.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-go / lib / utils / versions.js
diff --git a/.config/coc/extensions/node_modules/coc-go/lib/utils/versions.js b/.config/coc/extensions/node_modules/coc-go/lib/utils/versions.js
new file mode 100644 (file)
index 0000000..a0313f6
--- /dev/null
@@ -0,0 +1,33 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.parseVersion = exports.compareVersions = exports.isValidVersion = void 0;
+const versionExp = /^v?(\d+)\.(\d+).(\d+)$/;
+function isValidVersion(version) {
+    return Boolean(version.trim().match(versionExp));
+}
+exports.isValidVersion = isValidVersion;
+function compareVersions(version1, version2) {
+    const v1 = parseVersion(version1);
+    const v2 = parseVersion(version2);
+    for (let i = 0; i < 3; i++) {
+        if (v1[i] !== v2[i]) {
+            return Math.max(-1, Math.min(1, v1[i] - v2[i]));
+        }
+    }
+    return 0;
+}
+exports.compareVersions = compareVersions;
+function parseVersion(v) {
+    let ver = [0, 0, 0];
+    const match = v.trim().match(versionExp);
+    if (match) {
+        const [, major, minor, patch] = match;
+        ver = [parseInt(major), parseInt(minor), parseInt(patch)];
+    }
+    if (!isValidVersion(v)) {
+        throw new Error(`'${v}' is not a valid version`);
+    }
+    return ver;
+}
+exports.parseVersion = parseVersion;
+//# sourceMappingURL=versions.js.map
\ No newline at end of file