@comate/zulu 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/comate-engine/bin/comate.js +10 -0
- package/comate-engine/fallbackServer.js +1 -0
- package/comate-engine/node_modules/@comate/plugin-engine/dist/index.d.ts +188 -0
- package/comate-engine/node_modules/@comate/plugin-engine/dist/index.js +36 -0
- package/comate-engine/node_modules/@comate/plugin-engine/package.json +49 -0
- package/comate-engine/node_modules/@comate/plugin-host/bin.js +44 -0
- package/comate-engine/node_modules/@comate/plugin-host/dist/index.js +1 -0
- package/comate-engine/node_modules/@comate/plugin-host/dist/main.d.ts +14 -0
- package/comate-engine/node_modules/@comate/plugin-host/dist/main.js +9 -0
- package/comate-engine/node_modules/@comate/plugin-host/dist/user-Btg63hPI.js +36 -0
- package/comate-engine/node_modules/@comate/plugin-host/package.json +47 -0
- package/comate-engine/node_modules/@comate/plugin-shared-internals/dist/index.d.ts +2849 -0
- package/comate-engine/node_modules/@comate/plugin-shared-internals/dist/index.js +36 -0
- package/comate-engine/node_modules/@comate/plugin-shared-internals/package.json +72 -0
- package/comate-engine/node_modules/@comate/preview-proxy/bin/preview.js +13 -0
- package/comate-engine/node_modules/@comate/preview-proxy/dist/index.js +350 -0
- package/comate-engine/node_modules/@comate/preview-proxy/package.json +83 -0
- package/comate-engine/node_modules/@comate/preview-proxy/static/comate-preview-injector.css +1 -0
- package/comate-engine/node_modules/@comate/preview-proxy/static/comate-preview-injector.js +2 -0
- package/comate-engine/node_modules/@comate/preview-proxy/static/comate-preview-injector.js.LICENSE.txt +58 -0
- package/comate-engine/node_modules/compare-versions/LICENSE +21 -0
- package/comate-engine/node_modules/compare-versions/README.md +133 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compare.d.ts +19 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compare.js +44 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compare.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compareVersions.d.ts +8 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compareVersions.js +29 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/compareVersions.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/index.d.ts +5 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/index.js +5 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/index.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/satisfies.d.ts +14 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/satisfies.js +66 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/satisfies.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/utils.d.ts +7 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/utils.js +37 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/utils.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/validate.d.ts +28 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/validate.js +31 -0
- package/comate-engine/node_modules/compare-versions/lib/esm/validate.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/lib/umd/index.js +216 -0
- package/comate-engine/node_modules/compare-versions/lib/umd/index.js.map +1 -0
- package/comate-engine/node_modules/compare-versions/package.json +45 -0
- package/comate-engine/node_modules/compare-versions/src/compare.ts +54 -0
- package/comate-engine/node_modules/compare-versions/src/compareVersions.ts +31 -0
- package/comate-engine/node_modules/compare-versions/src/index.ts +5 -0
- package/comate-engine/node_modules/compare-versions/src/satisfies.ts +69 -0
- package/comate-engine/node_modules/compare-versions/src/utils.ts +50 -0
- package/comate-engine/node_modules/compare-versions/src/validate.ts +36 -0
- package/comate-engine/node_modules/pkce-challenge/LICENSE +21 -0
- package/comate-engine/node_modules/pkce-challenge/README.md +55 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.browser.d.ts +19 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.browser.js +72 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.node.cjs +80 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.node.d.cts +19 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.node.d.ts +19 -0
- package/comate-engine/node_modules/pkce-challenge/dist/index.node.js +75 -0
- package/comate-engine/node_modules/pkce-challenge/package.json +58 -0
- package/comate-engine/node_modules/web-streams-polyfill/LICENSE +22 -0
- package/comate-engine/node_modules/web-streams-polyfill/README.md +119 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/polyfill.es5.js +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/polyfill.js +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/ponyfill.es5.js +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/ponyfill.es5.mjs +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/ponyfill.js +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/dist/ponyfill.mjs +8 -0
- package/comate-engine/node_modules/web-streams-polyfill/package.json +98 -0
- package/comate-engine/node_modules/web-streams-polyfill/types/polyfill.d.ts +28 -0
- package/comate-engine/node_modules/web-streams-polyfill/types/ponyfill.d.ts +809 -0
- package/comate-engine/node_modules/web-streams-polyfill/types/tsdoc-metadata.json +11 -0
- package/comate-engine/package.json +91 -0
- package/comate-engine/plugins/aiscan/assets/icon.svg +12 -0
- package/comate-engine/plugins/aiscan/dist/index.js +53861 -0
- package/comate-engine/plugins/aiscan/package.json +67 -0
- package/comate-engine/plugins/appdev/assets/icon.png +0 -0
- package/comate-engine/plugins/appdev/dist/help.md +12 -0
- package/comate-engine/plugins/appdev/dist/index.d.ts +2 -0
- package/comate-engine/plugins/appdev/dist/index.js +194 -0
- package/comate-engine/plugins/appdev/dist/providers/err.d.ts +8 -0
- package/comate-engine/plugins/appdev/dist/providers/err.js +37 -0
- package/comate-engine/plugins/appdev/dist/providers/fallback.d.ts +5 -0
- package/comate-engine/plugins/appdev/dist/providers/fallback.js +28 -0
- package/comate-engine/plugins/appdev/dist/providers/help.d.ts +8 -0
- package/comate-engine/plugins/appdev/dist/providers/help.js +19 -0
- package/comate-engine/plugins/appdev/dist/providers/medusa.d.ts +8 -0
- package/comate-engine/plugins/appdev/dist/providers/medusa.js +39 -0
- package/comate-engine/plugins/appdev/dist/providers/qa.d.ts +8 -0
- package/comate-engine/plugins/appdev/dist/providers/qa.js +33 -0
- package/comate-engine/plugins/appdev/package.json +67 -0
- package/comate-engine/plugins/bfc/assets/bfc-icon.png +0 -0
- package/comate-engine/plugins/bfc/dist/config/config.d.ts +4 -0
- package/comate-engine/plugins/bfc/dist/config/config.js +4 -0
- package/comate-engine/plugins/bfc/dist/help.md +11 -0
- package/comate-engine/plugins/bfc/dist/index.d.ts +2 -0
- package/comate-engine/plugins/bfc/dist/index.js +452 -0
- package/comate-engine/plugins/bfc/dist/providers/bfcInstructMode.d.ts +8 -0
- package/comate-engine/plugins/bfc/dist/providers/bfcInstructMode.js +77 -0
- package/comate-engine/plugins/bfc/dist/providers/genAbnormalCode.d.ts +8 -0
- package/comate-engine/plugins/bfc/dist/providers/genAbnormalCode.js +71 -0
- package/comate-engine/plugins/bfc/dist/providers/genBfcCode.d.ts +8 -0
- package/comate-engine/plugins/bfc/dist/providers/genBfcCode.js +74 -0
- package/comate-engine/plugins/bfc/dist/providers/getBatchCases.d.ts +10 -0
- package/comate-engine/plugins/bfc/dist/providers/getBatchCases.js +71 -0
- package/comate-engine/plugins/bfc/dist/providers/help.d.ts +8 -0
- package/comate-engine/plugins/bfc/dist/providers/help.js +19 -0
- package/comate-engine/plugins/bfc/dist/service/generateService.d.ts +14 -0
- package/comate-engine/plugins/bfc/dist/service/generateService.js +27 -0
- package/comate-engine/plugins/bfc/package.json +85 -0
- package/comate-engine/plugins/bpm/assets/bpm.png +0 -0
- package/comate-engine/plugins/bpm/dist/index.js +313 -0
- package/comate-engine/plugins/bpm/package.json +65 -0
- package/comate-engine/plugins/casebuilder/assets/icon.svg +1 -0
- package/comate-engine/plugins/casebuilder/dist/help.md +33 -0
- package/comate-engine/plugins/casebuilder/dist/index.js +837 -0
- package/comate-engine/plugins/casebuilder/package.json +80 -0
- package/comate-engine/plugins/centrino/assets/icon.png +0 -0
- package/comate-engine/plugins/centrino/dist/help.md +30 -0
- package/comate-engine/plugins/centrino/dist/index.js +1046 -0
- package/comate-engine/plugins/centrino/package.json +68 -0
- package/comate-engine/plugins/cnap/assets/cnap.png +0 -0
- package/comate-engine/plugins/cnap/dist/help.md +11 -0
- package/comate-engine/plugins/cnap/dist/index.js +171 -0
- package/comate-engine/plugins/cnap/package.json +65 -0
- package/comate-engine/plugins/demo-feature/assets/icon.svg +1 -0
- package/comate-engine/plugins/demo-feature/dist/help.md +1 -0
- package/comate-engine/plugins/demo-feature/dist/index.d.ts +2 -0
- package/comate-engine/plugins/demo-feature/dist/index.js +36008 -0
- package/comate-engine/plugins/demo-feature/dist/providers/codeQuery.d.ts +12 -0
- package/comate-engine/plugins/demo-feature/dist/providers/codeQuery.js +23 -0
- package/comate-engine/plugins/demo-feature/dist/providers/codeSearch.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/codeSearch.js +26 -0
- package/comate-engine/plugins/demo-feature/dist/providers/config.d.ts +13 -0
- package/comate-engine/plugins/demo-feature/dist/providers/config.js +25 -0
- package/comate-engine/plugins/demo-feature/dist/providers/context.d.ts +10 -0
- package/comate-engine/plugins/demo-feature/dist/providers/context.js +49 -0
- package/comate-engine/plugins/demo-feature/dist/providers/debugAgent.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/debugAgent.js +65 -0
- package/comate-engine/plugins/demo-feature/dist/providers/explainCode.d.ts +9 -0
- package/comate-engine/plugins/demo-feature/dist/providers/explainCode.js +24 -0
- package/comate-engine/plugins/demo-feature/dist/providers/fallback.d.ts +5 -0
- package/comate-engine/plugins/demo-feature/dist/providers/fallback.js +23 -0
- package/comate-engine/plugins/demo-feature/dist/providers/file.d.ts +13 -0
- package/comate-engine/plugins/demo-feature/dist/providers/file.js +36 -0
- package/comate-engine/plugins/demo-feature/dist/providers/help.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/help.js +19 -0
- package/comate-engine/plugins/demo-feature/dist/providers/information.d.ts +13 -0
- package/comate-engine/plugins/demo-feature/dist/providers/information.js +23 -0
- package/comate-engine/plugins/demo-feature/dist/providers/knowledge.d.ts +15 -0
- package/comate-engine/plugins/demo-feature/dist/providers/knowledge.js +71 -0
- package/comate-engine/plugins/demo-feature/dist/providers/log.d.ts +12 -0
- package/comate-engine/plugins/demo-feature/dist/providers/log.js +21 -0
- package/comate-engine/plugins/demo-feature/dist/providers/onlyCode.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/onlyCode.js +23 -0
- package/comate-engine/plugins/demo-feature/dist/providers/pluginConfig.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/pluginConfig.js +47 -0
- package/comate-engine/plugins/demo-feature/dist/providers/prompt.d.ts +7 -0
- package/comate-engine/plugins/demo-feature/dist/providers/prompt.js +7 -0
- package/comate-engine/plugins/demo-feature/dist/providers/ragProvider.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/ragProvider.js +17 -0
- package/comate-engine/plugins/demo-feature/dist/providers/render.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/render.js +75 -0
- package/comate-engine/plugins/demo-feature/dist/providers/renderJsx.d.ts +10 -0
- package/comate-engine/plugins/demo-feature/dist/providers/renderJsx.js +173 -0
- package/comate-engine/plugins/demo-feature/dist/providers/section.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/section.js +136 -0
- package/comate-engine/plugins/demo-feature/dist/providers/selectedKnowledge.d.ts +12 -0
- package/comate-engine/plugins/demo-feature/dist/providers/selectedKnowledge.js +17 -0
- package/comate-engine/plugins/demo-feature/dist/providers/streaming.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/streaming.js +29 -0
- package/comate-engine/plugins/demo-feature/dist/providers/userDetail.d.ts +8 -0
- package/comate-engine/plugins/demo-feature/dist/providers/userDetail.js +28 -0
- package/comate-engine/plugins/demo-feature/package.json +214 -0
- package/comate-engine/plugins/demo-timer/assets/icon.svg +2 -0
- package/comate-engine/plugins/demo-timer/dist/index.js +463 -0
- package/comate-engine/plugins/demo-timer/package.json +73 -0
- package/comate-engine/plugins/dev-tools/assets/icon.png +0 -0
- package/comate-engine/plugins/dev-tools/dist/help.md +18 -0
- package/comate-engine/plugins/dev-tools/dist/index.js +166160 -0
- package/comate-engine/plugins/dev-tools/package.json +95 -0
- package/comate-engine/plugins/devaux/assets/icon.svg +1 -0
- package/comate-engine/plugins/devaux/dist/help.md +41 -0
- package/comate-engine/plugins/devaux/dist/index.js +73829 -0
- package/comate-engine/plugins/devaux/dist/static/tree-sitter-cpp.wasm +0 -0
- package/comate-engine/plugins/devaux/dist/static/tree-sitter-go.wasm +0 -0
- package/comate-engine/plugins/devaux/dist/static/tree-sitter.wasm +0 -0
- package/comate-engine/plugins/devaux/dist/tree-sitter.wasm +0 -0
- package/comate-engine/plugins/devaux/package.json +83 -0
- package/comate-engine/plugins/f2c/assets/icon.svg +11 -0
- package/comate-engine/plugins/f2c/dist/help.md +13 -0
- package/comate-engine/plugins/f2c/dist/index.js +64551 -0
- package/comate-engine/plugins/f2c/package.json +56 -0
- package/comate-engine/plugins/fcnap/assets/icon.png +0 -0
- package/comate-engine/plugins/fcnap/dist/help.md +9 -0
- package/comate-engine/plugins/fcnap/dist/index.js +105 -0
- package/comate-engine/plugins/fcnap/package.json +50 -0
- package/comate-engine/plugins/front-end-skills/assets/icon.svg +1 -0
- package/comate-engine/plugins/front-end-skills/dist/help.md +17 -0
- package/comate-engine/plugins/front-end-skills/dist/index.js +8172 -0
- package/comate-engine/plugins/front-end-skills/package.json +79 -0
- package/comate-engine/plugins/gdp/assets/icon.png +0 -0
- package/comate-engine/plugins/gdp/dist/help.md +11 -0
- package/comate-engine/plugins/gdp/dist/index.js +53065 -0
- package/comate-engine/plugins/gdp/package.json +79 -0
- package/comate-engine/plugins/git/assets/git.svg +1 -0
- package/comate-engine/plugins/git/assets/icon.svg +1 -0
- package/comate-engine/plugins/git/dist/help.md +7 -0
- package/comate-engine/plugins/git/dist/index.js +32675 -0
- package/comate-engine/plugins/git/package.json +91 -0
- package/comate-engine/plugins/harmonyos/assets/harmonyos.png +0 -0
- package/comate-engine/plugins/harmonyos/dist/index.js +78 -0
- package/comate-engine/plugins/harmonyos/package.json +37 -0
- package/comate-engine/plugins/iapi/assets/icon.png +0 -0
- package/comate-engine/plugins/iapi/dist/help.md +13 -0
- package/comate-engine/plugins/iapi/dist/index.js +458 -0
- package/comate-engine/plugins/iapi/dist/static/lang/tree-sitter-go.wasm +0 -0
- package/comate-engine/plugins/iapi/dist/static/lang/tree-sitter-java.wasm +0 -0
- package/comate-engine/plugins/iapi/dist/static/tree-sitter-go.wasm +0 -0
- package/comate-engine/plugins/iapi/dist/static/tree-sitter-java.wasm +0 -0
- package/comate-engine/plugins/iapi/dist/tree-sitter.wasm +0 -0
- package/comate-engine/plugins/iapi/package.json +102 -0
- package/comate-engine/plugins/icafe/assets/icafe.svg +1 -0
- package/comate-engine/plugins/icafe/dist/help.md +5 -0
- package/comate-engine/plugins/icafe/dist/index.js +885 -0
- package/comate-engine/plugins/icafe/package.json +74 -0
- package/comate-engine/plugins/ievalue/assets/iEValue.svg +10 -0
- package/comate-engine/plugins/ievalue/dist/index.js +2920 -0
- package/comate-engine/plugins/ievalue/package.json +88 -0
- package/comate-engine/plugins/ipipe/assets/iPipePlugin.png +0 -0
- package/comate-engine/plugins/ipipe/dist/help.md +15 -0
- package/comate-engine/plugins/ipipe/dist/index.js +7264 -0
- package/comate-engine/plugins/ipipe/package.json +62 -0
- package/comate-engine/plugins/jarvis/assets/icon.svg +1 -0
- package/comate-engine/plugins/jarvis/dist/help.md +17 -0
- package/comate-engine/plugins/jarvis/dist/index.js +140416 -0
- package/comate-engine/plugins/jarvis/package.json +93 -0
- package/comate-engine/plugins/mapsearch/assets/mapsearchicon.png +0 -0
- package/comate-engine/plugins/mapsearch/dist/help.md +4 -0
- package/comate-engine/plugins/mapsearch/dist/index.js +145 -0
- package/comate-engine/plugins/mapsearch/package.json +53 -0
- package/comate-engine/plugins/paddle/assets/icon.png +0 -0
- package/comate-engine/plugins/paddle/assets/paconvert-3.0.1-py3-none-any.whl +0 -0
- package/comate-engine/plugins/paddle/dist/help.md +31 -0
- package/comate-engine/plugins/paddle/dist/index.js +1011 -0
- package/comate-engine/plugins/paddle/package.json +129 -0
- package/comate-engine/plugins/robot/assets/Robot.png +0 -0
- package/comate-engine/plugins/robot/dist/index.js +288 -0
- package/comate-engine/plugins/robot/package.json +67 -0
- package/comate-engine/plugins/security/assets/comate.png +0 -0
- package/comate-engine/plugins/security/dist/index.js +18393 -0
- package/comate-engine/plugins/security/package.json +82 -0
- package/comate-engine/plugins/smartapp/assets/icon.png +0 -0
- package/comate-engine/plugins/smartapp/dist/help.md +4 -0
- package/comate-engine/plugins/smartapp/dist/index.js +113 -0
- package/comate-engine/plugins/smartapp/package.json +54 -0
- package/comate-engine/plugins/springer/assets/icon.png +0 -0
- package/comate-engine/plugins/springer/dist/help.md +4 -0
- package/comate-engine/plugins/springer/dist/index.js +94525 -0
- package/comate-engine/plugins/springer/package.json +71 -0
- package/comate-engine/plugins/testmate/assets/icon.svg +1 -0
- package/comate-engine/plugins/testmate/dist/help.md +62 -0
- package/comate-engine/plugins/testmate/dist/index.js +21483 -0
- package/comate-engine/plugins/testmate/package.json +85 -0
- package/comate-engine/plugins/tor/assets/TorPlugin.png +0 -0
- package/comate-engine/plugins/tor/dist/help.md +22 -0
- package/comate-engine/plugins/tor/dist/index.js +807 -0
- package/comate-engine/plugins/tor/package.json +99 -0
- package/comate-engine/plugins/weiyun/assets/icon.png +0 -0
- package/comate-engine/plugins/weiyun/dist/help.md +11 -0
- package/comate-engine/plugins/weiyun/dist/index.js +100491 -0
- package/comate-engine/plugins/weiyun/package.json +55 -0
- package/comate-engine/plugins/wenku/assets/icon.svg +1 -0
- package/comate-engine/plugins/wenku/dist/index.js +249 -0
- package/comate-engine/plugins/wenku/package.json +55 -0
- package/comate-engine/plugins/workcard/assets/favicon.png +0 -0
- package/comate-engine/plugins/workcard/dist/help.md +30 -0
- package/comate-engine/plugins/workcard/dist/index.js +490 -0
- package/comate-engine/plugins/workcard/package.json +95 -0
- package/comate-engine/plugins/xiaomi-aiot/assets/icon.png +0 -0
- package/comate-engine/plugins/xiaomi-aiot/dist/help.md +6 -0
- package/comate-engine/plugins/xiaomi-aiot/dist/index.js +37466 -0
- package/comate-engine/plugins/xiaomi-aiot/package.json +63 -0
- package/comate-engine/server.d.ts +3 -0
- package/comate-engine/server.js +474 -0
- package/dist/bundle/index.js +29 -58174
- package/package.json +2 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.compareVersions = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
8
|
+
const validateAndParse = (version) => {
|
|
9
|
+
if (typeof version !== 'string') {
|
|
10
|
+
throw new TypeError('Invalid argument expected string');
|
|
11
|
+
}
|
|
12
|
+
const match = version.match(semver);
|
|
13
|
+
if (!match) {
|
|
14
|
+
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
|
|
15
|
+
}
|
|
16
|
+
match.shift();
|
|
17
|
+
return match;
|
|
18
|
+
};
|
|
19
|
+
const isWildcard = (s) => s === '*' || s === 'x' || s === 'X';
|
|
20
|
+
const tryParse = (v) => {
|
|
21
|
+
const n = parseInt(v, 10);
|
|
22
|
+
return isNaN(n) ? v : n;
|
|
23
|
+
};
|
|
24
|
+
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
25
|
+
const compareStrings = (a, b) => {
|
|
26
|
+
if (isWildcard(a) || isWildcard(b))
|
|
27
|
+
return 0;
|
|
28
|
+
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
29
|
+
if (ap > bp)
|
|
30
|
+
return 1;
|
|
31
|
+
if (ap < bp)
|
|
32
|
+
return -1;
|
|
33
|
+
return 0;
|
|
34
|
+
};
|
|
35
|
+
const compareSegments = (a, b) => {
|
|
36
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
37
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
38
|
+
if (r !== 0)
|
|
39
|
+
return r;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
46
|
+
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
47
|
+
* @param v1 - First version to compare
|
|
48
|
+
* @param v2 - Second version to compare
|
|
49
|
+
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
|
|
50
|
+
*/
|
|
51
|
+
const compareVersions = (v1, v2) => {
|
|
52
|
+
// validate input and split into segments
|
|
53
|
+
const n1 = validateAndParse(v1);
|
|
54
|
+
const n2 = validateAndParse(v2);
|
|
55
|
+
// pop off the patch
|
|
56
|
+
const p1 = n1.pop();
|
|
57
|
+
const p2 = n2.pop();
|
|
58
|
+
// validate numbers
|
|
59
|
+
const r = compareSegments(n1, n2);
|
|
60
|
+
if (r !== 0)
|
|
61
|
+
return r;
|
|
62
|
+
// validate pre-release
|
|
63
|
+
if (p1 && p2) {
|
|
64
|
+
return compareSegments(p1.split('.'), p2.split('.'));
|
|
65
|
+
}
|
|
66
|
+
else if (p1 || p2) {
|
|
67
|
+
return p1 ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Compare [semver](https://semver.org/) version strings using the specified operator.
|
|
74
|
+
*
|
|
75
|
+
* @param v1 First version to compare
|
|
76
|
+
* @param v2 Second version to compare
|
|
77
|
+
* @param operator Allowed arithmetic operator to use
|
|
78
|
+
* @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```
|
|
82
|
+
* compare('10.1.8', '10.0.4', '>'); // return true
|
|
83
|
+
* compare('10.0.1', '10.0.1', '='); // return true
|
|
84
|
+
* compare('10.1.1', '10.2.2', '<'); // return true
|
|
85
|
+
* compare('10.1.1', '10.2.2', '<='); // return true
|
|
86
|
+
* compare('10.1.1', '10.2.2', '>='); // return false
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
const compare = (v1, v2, operator) => {
|
|
90
|
+
// validate input operator
|
|
91
|
+
assertValidOperator(operator);
|
|
92
|
+
// since result of compareVersions can only be -1 or 0 or 1
|
|
93
|
+
// a simple map can be used to replace switch
|
|
94
|
+
const res = compareVersions(v1, v2);
|
|
95
|
+
return operatorResMap[operator].includes(res);
|
|
96
|
+
};
|
|
97
|
+
const operatorResMap = {
|
|
98
|
+
'>': [1],
|
|
99
|
+
'>=': [0, 1],
|
|
100
|
+
'=': [0],
|
|
101
|
+
'<=': [-1, 0],
|
|
102
|
+
'<': [-1],
|
|
103
|
+
'!=': [-1, 1],
|
|
104
|
+
};
|
|
105
|
+
const allowedOperators = Object.keys(operatorResMap);
|
|
106
|
+
const assertValidOperator = (op) => {
|
|
107
|
+
if (typeof op !== 'string') {
|
|
108
|
+
throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
|
|
109
|
+
}
|
|
110
|
+
if (allowedOperators.indexOf(op) === -1) {
|
|
111
|
+
throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
|
|
117
|
+
*
|
|
118
|
+
* @param version Version number to match
|
|
119
|
+
* @param range Range pattern for version
|
|
120
|
+
* @returns `true` if the version number is within the range, `false` otherwise.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```
|
|
124
|
+
* satisfies('1.1.0', '^1.0.0'); // return true
|
|
125
|
+
* satisfies('1.1.0', '~1.0.0'); // return false
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
const satisfies = (version, range) => {
|
|
129
|
+
// clean input
|
|
130
|
+
range = range.replace(/([><=]+)\s+/g, '$1');
|
|
131
|
+
// handle multiple comparators
|
|
132
|
+
if (range.includes('||')) {
|
|
133
|
+
return range.split('||').some((r) => satisfies(version, r));
|
|
134
|
+
}
|
|
135
|
+
else if (range.includes(' - ')) {
|
|
136
|
+
const [a, b] = range.split(' - ', 2);
|
|
137
|
+
return satisfies(version, `>=${a} <=${b}`);
|
|
138
|
+
}
|
|
139
|
+
else if (range.includes(' ')) {
|
|
140
|
+
return range
|
|
141
|
+
.trim()
|
|
142
|
+
.replace(/\s{2,}/g, ' ')
|
|
143
|
+
.split(' ')
|
|
144
|
+
.every((r) => satisfies(version, r));
|
|
145
|
+
}
|
|
146
|
+
// if no range operator then "="
|
|
147
|
+
const m = range.match(/^([<>=~^]+)/);
|
|
148
|
+
const op = m ? m[1] : '=';
|
|
149
|
+
// if gt/lt/eq then operator compare
|
|
150
|
+
if (op !== '^' && op !== '~')
|
|
151
|
+
return compare(version, range, op);
|
|
152
|
+
// else range of either "~" or "^" is assumed
|
|
153
|
+
const [v1, v2, v3, , vp] = validateAndParse(version);
|
|
154
|
+
const [r1, r2, r3, , rp] = validateAndParse(range);
|
|
155
|
+
const v = [v1, v2, v3];
|
|
156
|
+
const r = [r1, r2 !== null && r2 !== void 0 ? r2 : 'x', r3 !== null && r3 !== void 0 ? r3 : 'x'];
|
|
157
|
+
// validate pre-release
|
|
158
|
+
if (rp) {
|
|
159
|
+
if (!vp)
|
|
160
|
+
return false;
|
|
161
|
+
if (compareSegments(v, r) !== 0)
|
|
162
|
+
return false;
|
|
163
|
+
if (compareSegments(vp.split('.'), rp.split('.')) === -1)
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
// first non-zero number
|
|
167
|
+
const nonZero = r.findIndex((v) => v !== '0') + 1;
|
|
168
|
+
// pointer to where segments can be >=
|
|
169
|
+
const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;
|
|
170
|
+
// before pointer must be equal
|
|
171
|
+
if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0)
|
|
172
|
+
return false;
|
|
173
|
+
// after pointer must be >=
|
|
174
|
+
if (compareSegments(v.slice(i), r.slice(i)) === -1)
|
|
175
|
+
return false;
|
|
176
|
+
return true;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Validate [semver](https://semver.org/) version strings.
|
|
181
|
+
*
|
|
182
|
+
* @param version Version number to validate
|
|
183
|
+
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```
|
|
187
|
+
* validate('1.0.0-rc.1'); // return true
|
|
188
|
+
* validate('1.0-rc.1'); // return false
|
|
189
|
+
* validate('foo'); // return false
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
const validate = (version) => typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
|
|
193
|
+
/**
|
|
194
|
+
* Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.
|
|
195
|
+
*
|
|
196
|
+
* @param version Version number to validate
|
|
197
|
+
* @returns `true` if the version number is a valid semver version number `false` otherwise
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```
|
|
201
|
+
* validate('1.0.0-rc.1'); // return true
|
|
202
|
+
* validate('1.0-rc.1'); // return false
|
|
203
|
+
* validate('foo'); // return false
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
const validateStrict = (version) => typeof version === 'string' &&
|
|
207
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/.test(version);
|
|
208
|
+
|
|
209
|
+
exports.compare = compare;
|
|
210
|
+
exports.compareVersions = compareVersions;
|
|
211
|
+
exports.satisfies = satisfies;
|
|
212
|
+
exports.validate = validate;
|
|
213
|
+
exports.validateStrict = validateStrict;
|
|
214
|
+
|
|
215
|
+
}));
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../esm/utils.js","../esm/compareVersions.js","../esm/compare.js","../esm/satisfies.js","../esm/validate.js"],"sourcesContent":["export const semver = /^[v^~<>=]*?(\\d+)(?:\\.([x*]|\\d+)(?:\\.([x*]|\\d+)(?:\\.([x*]|\\d+))?(?:-([\\da-z\\-]+(?:\\.[\\da-z\\-]+)*))?(?:\\+[\\da-z\\-]+(?:\\.[\\da-z\\-]+)*)?)?)?$/i;\nexport const validateAndParse = (version) => {\n if (typeof version !== 'string') {\n throw new TypeError('Invalid argument expected string');\n }\n const match = version.match(semver);\n if (!match) {\n throw new Error(`Invalid argument not valid semver ('${version}' received)`);\n }\n match.shift();\n return match;\n};\nconst isWildcard = (s) => s === '*' || s === 'x' || s === 'X';\nconst tryParse = (v) => {\n const n = parseInt(v, 10);\n return isNaN(n) ? v : n;\n};\nconst forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];\nconst compareStrings = (a, b) => {\n if (isWildcard(a) || isWildcard(b))\n return 0;\n const [ap, bp] = forceType(tryParse(a), tryParse(b));\n if (ap > bp)\n return 1;\n if (ap < bp)\n return -1;\n return 0;\n};\nexport const compareSegments = (a, b) => {\n for (let i = 0; i < Math.max(a.length, b.length); i++) {\n const r = compareStrings(a[i] || '0', b[i] || '0');\n if (r !== 0)\n return r;\n }\n return 0;\n};\n//# sourceMappingURL=utils.js.map","import { compareSegments, validateAndParse } from './utils.js';\n/**\n * Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.\n * This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.\n * @param v1 - First version to compare\n * @param v2 - Second version to compare\n * @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).\n */\nexport const compareVersions = (v1, v2) => {\n // validate input and split into segments\n const n1 = validateAndParse(v1);\n const n2 = validateAndParse(v2);\n // pop off the patch\n const p1 = n1.pop();\n const p2 = n2.pop();\n // validate numbers\n const r = compareSegments(n1, n2);\n if (r !== 0)\n return r;\n // validate pre-release\n if (p1 && p2) {\n return compareSegments(p1.split('.'), p2.split('.'));\n }\n else if (p1 || p2) {\n return p1 ? -1 : 1;\n }\n return 0;\n};\n//# sourceMappingURL=compareVersions.js.map","import { compareVersions } from './compareVersions.js';\n/**\n * Compare [semver](https://semver.org/) version strings using the specified operator.\n *\n * @param v1 First version to compare\n * @param v2 Second version to compare\n * @param operator Allowed arithmetic operator to use\n * @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.\n *\n * @example\n * ```\n * compare('10.1.8', '10.0.4', '>'); // return true\n * compare('10.0.1', '10.0.1', '='); // return true\n * compare('10.1.1', '10.2.2', '<'); // return true\n * compare('10.1.1', '10.2.2', '<='); // return true\n * compare('10.1.1', '10.2.2', '>='); // return false\n * ```\n */\nexport const compare = (v1, v2, operator) => {\n // validate input operator\n assertValidOperator(operator);\n // since result of compareVersions can only be -1 or 0 or 1\n // a simple map can be used to replace switch\n const res = compareVersions(v1, v2);\n return operatorResMap[operator].includes(res);\n};\nconst operatorResMap = {\n '>': [1],\n '>=': [0, 1],\n '=': [0],\n '<=': [-1, 0],\n '<': [-1],\n '!=': [-1, 1],\n};\nconst allowedOperators = Object.keys(operatorResMap);\nconst assertValidOperator = (op) => {\n if (typeof op !== 'string') {\n throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);\n }\n if (allowedOperators.indexOf(op) === -1) {\n throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);\n }\n};\n//# sourceMappingURL=compare.js.map","import { compare } from './compare.js';\nimport { compareSegments, validateAndParse } from './utils.js';\n/**\n * Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.\n *\n * @param version Version number to match\n * @param range Range pattern for version\n * @returns `true` if the version number is within the range, `false` otherwise.\n *\n * @example\n * ```\n * satisfies('1.1.0', '^1.0.0'); // return true\n * satisfies('1.1.0', '~1.0.0'); // return false\n * ```\n */\nexport const satisfies = (version, range) => {\n // clean input\n range = range.replace(/([><=]+)\\s+/g, '$1');\n // handle multiple comparators\n if (range.includes('||')) {\n return range.split('||').some((r) => satisfies(version, r));\n }\n else if (range.includes(' - ')) {\n const [a, b] = range.split(' - ', 2);\n return satisfies(version, `>=${a} <=${b}`);\n }\n else if (range.includes(' ')) {\n return range\n .trim()\n .replace(/\\s{2,}/g, ' ')\n .split(' ')\n .every((r) => satisfies(version, r));\n }\n // if no range operator then \"=\"\n const m = range.match(/^([<>=~^]+)/);\n const op = m ? m[1] : '=';\n // if gt/lt/eq then operator compare\n if (op !== '^' && op !== '~')\n return compare(version, range, op);\n // else range of either \"~\" or \"^\" is assumed\n const [v1, v2, v3, , vp] = validateAndParse(version);\n const [r1, r2, r3, , rp] = validateAndParse(range);\n const v = [v1, v2, v3];\n const r = [r1, r2 !== null && r2 !== void 0 ? r2 : 'x', r3 !== null && r3 !== void 0 ? r3 : 'x'];\n // validate pre-release\n if (rp) {\n if (!vp)\n return false;\n if (compareSegments(v, r) !== 0)\n return false;\n if (compareSegments(vp.split('.'), rp.split('.')) === -1)\n return false;\n }\n // first non-zero number\n const nonZero = r.findIndex((v) => v !== '0') + 1;\n // pointer to where segments can be >=\n const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;\n // before pointer must be equal\n if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0)\n return false;\n // after pointer must be >=\n if (compareSegments(v.slice(i), r.slice(i)) === -1)\n return false;\n return true;\n};\n//# sourceMappingURL=satisfies.js.map","import { semver } from './utils.js';\n/**\n * Validate [semver](https://semver.org/) version strings.\n *\n * @param version Version number to validate\n * @returns `true` if the version number is a valid semver version number, `false` otherwise.\n *\n * @example\n * ```\n * validate('1.0.0-rc.1'); // return true\n * validate('1.0-rc.1'); // return false\n * validate('foo'); // return false\n * ```\n */\nexport const validate = (version) => typeof version === 'string' && /^[v\\d]/.test(version) && semver.test(version);\n/**\n * Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.\n *\n * @param version Version number to validate\n * @returns `true` if the version number is a valid semver version number `false` otherwise\n *\n * @example\n * ```\n * validate('1.0.0-rc.1'); // return true\n * validate('1.0-rc.1'); // return false\n * validate('foo'); // return false\n * ```\n */\nexport const validateStrict = (version) => typeof version === 'string' &&\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z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6.1.1",
|
|
4
|
+
"description": "Compare semver version strings to find greater, equal or lesser.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/omichelsen/compare-versions.git"
|
|
8
|
+
},
|
|
9
|
+
"author": "Ole Michelsen",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/omichelsen/compare-versions/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/omichelsen/compare-versions#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"semver",
|
|
17
|
+
"version",
|
|
18
|
+
"compare",
|
|
19
|
+
"browser",
|
|
20
|
+
"node"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run build:esm && npm run build:umd",
|
|
24
|
+
"build:esm": "tsc --module esnext --target es2017 --outDir lib/esm",
|
|
25
|
+
"build:umd": "rollup lib/esm/index.js --format umd --name compareVersions --sourcemap -o lib/umd/index.js",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"test": "c8 --reporter=lcov mocha"
|
|
28
|
+
},
|
|
29
|
+
"main": "./lib/umd/index.js",
|
|
30
|
+
"module": "./lib/esm/index.js",
|
|
31
|
+
"types": "./lib/esm/index.d.ts",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"files": [
|
|
34
|
+
"lib",
|
|
35
|
+
"src"
|
|
36
|
+
],
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/mocha": "^10.0.7",
|
|
39
|
+
"c8": "^10.1.2",
|
|
40
|
+
"mocha": "^10.6.0",
|
|
41
|
+
"rollup": "^4.18.1",
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^5.5.3"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { compareVersions } from './compareVersions.js';
|
|
2
|
+
import { CompareOperator } from './utils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compare [semver](https://semver.org/) version strings using the specified operator.
|
|
6
|
+
*
|
|
7
|
+
* @param v1 First version to compare
|
|
8
|
+
* @param v2 Second version to compare
|
|
9
|
+
* @param operator Allowed arithmetic operator to use
|
|
10
|
+
* @returns `true` if the comparison between the firstVersion and the secondVersion satisfies the operator, `false` otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* compare('10.1.8', '10.0.4', '>'); // return true
|
|
15
|
+
* compare('10.0.1', '10.0.1', '='); // return true
|
|
16
|
+
* compare('10.1.1', '10.2.2', '<'); // return true
|
|
17
|
+
* compare('10.1.1', '10.2.2', '<='); // return true
|
|
18
|
+
* compare('10.1.1', '10.2.2', '>='); // return false
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const compare = (v1: string, v2: string, operator: CompareOperator) => {
|
|
22
|
+
// validate input operator
|
|
23
|
+
assertValidOperator(operator);
|
|
24
|
+
|
|
25
|
+
// since result of compareVersions can only be -1 or 0 or 1
|
|
26
|
+
// a simple map can be used to replace switch
|
|
27
|
+
const res = compareVersions(v1, v2);
|
|
28
|
+
|
|
29
|
+
return operatorResMap[operator].includes(res);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const operatorResMap = {
|
|
33
|
+
'>': [1],
|
|
34
|
+
'>=': [0, 1],
|
|
35
|
+
'=': [0],
|
|
36
|
+
'<=': [-1, 0],
|
|
37
|
+
'<': [-1],
|
|
38
|
+
'!=': [-1, 1],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const allowedOperators = Object.keys(operatorResMap);
|
|
42
|
+
|
|
43
|
+
const assertValidOperator = (op: string) => {
|
|
44
|
+
if (typeof op !== 'string') {
|
|
45
|
+
throw new TypeError(
|
|
46
|
+
`Invalid operator type, expected string but got ${typeof op}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (allowedOperators.indexOf(op) === -1) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Invalid operator, expected one of ${allowedOperators.join('|')}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compareSegments, validateAndParse } from './utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
5
|
+
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
6
|
+
* @param v1 - First version to compare
|
|
7
|
+
* @param v2 - Second version to compare
|
|
8
|
+
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
|
|
9
|
+
*/
|
|
10
|
+
export const compareVersions = (v1: string, v2: string) => {
|
|
11
|
+
// validate input and split into segments
|
|
12
|
+
const n1 = validateAndParse(v1);
|
|
13
|
+
const n2 = validateAndParse(v2);
|
|
14
|
+
|
|
15
|
+
// pop off the patch
|
|
16
|
+
const p1 = n1.pop();
|
|
17
|
+
const p2 = n2.pop();
|
|
18
|
+
|
|
19
|
+
// validate numbers
|
|
20
|
+
const r = compareSegments(n1, n2);
|
|
21
|
+
if (r !== 0) return r;
|
|
22
|
+
|
|
23
|
+
// validate pre-release
|
|
24
|
+
if (p1 && p2) {
|
|
25
|
+
return compareSegments(p1.split('.'), p2.split('.'));
|
|
26
|
+
} else if (p1 || p2) {
|
|
27
|
+
return p1 ? -1 : 1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return 0;
|
|
31
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { compare } from './compare.js';
|
|
2
|
+
import { CompareOperator, compareSegments, validateAndParse } from './utils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Match [npm semver](https://docs.npmjs.com/cli/v6/using-npm/semver) version range.
|
|
6
|
+
*
|
|
7
|
+
* @param version Version number to match
|
|
8
|
+
* @param range Range pattern for version
|
|
9
|
+
* @returns `true` if the version number is within the range, `false` otherwise.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* satisfies('1.1.0', '^1.0.0'); // return true
|
|
14
|
+
* satisfies('1.1.0', '~1.0.0'); // return false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const satisfies = (version: string, range: string): boolean => {
|
|
18
|
+
// clean input
|
|
19
|
+
range = range.replace(/([><=]+)\s+/g, '$1');
|
|
20
|
+
|
|
21
|
+
// handle multiple comparators
|
|
22
|
+
if (range.includes('||')) {
|
|
23
|
+
return range.split('||').some((r) => satisfies(version, r));
|
|
24
|
+
} else if (range.includes(' - ')) {
|
|
25
|
+
const [a, b] = range.split(' - ', 2);
|
|
26
|
+
return satisfies(version, `>=${a} <=${b}`);
|
|
27
|
+
} else if (range.includes(' ')) {
|
|
28
|
+
return range
|
|
29
|
+
.trim()
|
|
30
|
+
.replace(/\s{2,}/g, ' ')
|
|
31
|
+
.split(' ')
|
|
32
|
+
.every((r) => satisfies(version, r));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// if no range operator then "="
|
|
36
|
+
const m = range.match(/^([<>=~^]+)/);
|
|
37
|
+
const op = m ? m[1] : '=';
|
|
38
|
+
|
|
39
|
+
// if gt/lt/eq then operator compare
|
|
40
|
+
if (op !== '^' && op !== '~')
|
|
41
|
+
return compare(version, range, op as CompareOperator);
|
|
42
|
+
|
|
43
|
+
// else range of either "~" or "^" is assumed
|
|
44
|
+
const [v1, v2, v3, , vp] = validateAndParse(version);
|
|
45
|
+
const [r1, r2, r3, , rp] = validateAndParse(range);
|
|
46
|
+
const v = [v1, v2, v3];
|
|
47
|
+
const r = [r1, r2 ?? 'x', r3 ?? 'x'];
|
|
48
|
+
|
|
49
|
+
// validate pre-release
|
|
50
|
+
if (rp) {
|
|
51
|
+
if (!vp) return false;
|
|
52
|
+
if (compareSegments(v, r) !== 0) return false;
|
|
53
|
+
if (compareSegments(vp.split('.'), rp.split('.')) === -1) return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// first non-zero number
|
|
57
|
+
const nonZero = r.findIndex((v) => v !== '0') + 1;
|
|
58
|
+
|
|
59
|
+
// pointer to where segments can be >=
|
|
60
|
+
const i = op === '~' ? 2 : nonZero > 1 ? nonZero : 1;
|
|
61
|
+
|
|
62
|
+
// before pointer must be equal
|
|
63
|
+
if (compareSegments(v.slice(0, i), r.slice(0, i)) !== 0) return false;
|
|
64
|
+
|
|
65
|
+
// after pointer must be >=
|
|
66
|
+
if (compareSegments(v.slice(i), r.slice(i)) === -1) return false;
|
|
67
|
+
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowed arithmetic operators
|
|
3
|
+
*/
|
|
4
|
+
export type CompareOperator = '>' | '>=' | '=' | '<' | '<=' | '!=';
|
|
5
|
+
|
|
6
|
+
export const semver =
|
|
7
|
+
/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
8
|
+
|
|
9
|
+
export const validateAndParse = (version: string) => {
|
|
10
|
+
if (typeof version !== 'string') {
|
|
11
|
+
throw new TypeError('Invalid argument expected string');
|
|
12
|
+
}
|
|
13
|
+
const match = version.match(semver);
|
|
14
|
+
if (!match) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Invalid argument not valid semver ('${version}' received)`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
match.shift();
|
|
20
|
+
return match;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isWildcard = (s: string) => s === '*' || s === 'x' || s === 'X';
|
|
24
|
+
|
|
25
|
+
const tryParse = (v: string) => {
|
|
26
|
+
const n = parseInt(v, 10);
|
|
27
|
+
return isNaN(n) ? v : n;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const forceType = (a: string | number, b: string | number) =>
|
|
31
|
+
typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
32
|
+
|
|
33
|
+
const compareStrings = (a: string, b: string) => {
|
|
34
|
+
if (isWildcard(a) || isWildcard(b)) return 0;
|
|
35
|
+
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
36
|
+
if (ap > bp) return 1;
|
|
37
|
+
if (ap < bp) return -1;
|
|
38
|
+
return 0;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const compareSegments = (
|
|
42
|
+
a: string | string[] | RegExpMatchArray,
|
|
43
|
+
b: string | string[] | RegExpMatchArray
|
|
44
|
+
) => {
|
|
45
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
46
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
47
|
+
if (r !== 0) return r;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { semver } from './utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validate [semver](https://semver.org/) version strings.
|
|
5
|
+
*
|
|
6
|
+
* @param version Version number to validate
|
|
7
|
+
* @returns `true` if the version number is a valid semver version number, `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```
|
|
11
|
+
* validate('1.0.0-rc.1'); // return true
|
|
12
|
+
* validate('1.0-rc.1'); // return false
|
|
13
|
+
* validate('foo'); // return false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const validate = (version: string) =>
|
|
17
|
+
typeof version === 'string' && /^[v\d]/.test(version) && semver.test(version);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Validate [semver](https://semver.org/) version strings strictly. Will not accept wildcards and version ranges.
|
|
21
|
+
*
|
|
22
|
+
* @param version Version number to validate
|
|
23
|
+
* @returns `true` if the version number is a valid semver version number `false` otherwise
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* validate('1.0.0-rc.1'); // return true
|
|
28
|
+
* validate('1.0-rc.1'); // return false
|
|
29
|
+
* validate('foo'); // return false
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const validateStrict = (version: string) =>
|
|
33
|
+
typeof version === 'string' &&
|
|
34
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/.test(
|
|
35
|
+
version
|
|
36
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# pkce-challenge
|
|
2
|
+
|
|
3
|
+
Generate or verify a Proof Key for Code Exchange (PKCE) challenge pair.
|
|
4
|
+
|
|
5
|
+
Read more about [PKCE](https://www.oauth.com/oauth2-servers/pkce/authorization-request/).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install pkce-challenge
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Default length for the verifier is 43
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import pkceChallenge from "pkce-challenge";
|
|
19
|
+
|
|
20
|
+
await pkceChallenge();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
gives something like:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
{
|
|
27
|
+
code_verifier: 'u1ta-MQ0e7TcpHjgz33M2DcBnOQu~aMGxuiZt0QMD1C',
|
|
28
|
+
code_challenge: 'CUZX5qE8Wvye6kS_SasIsa8MMxacJftmWdsIA_iKp3I'
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Specify a verifier length
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const challenge = await pkceChallenge(128);
|
|
36
|
+
|
|
37
|
+
challenge.code_verifier.length === 128; // true
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Challenge verification
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { verifyChallenge } from "pkce-challenge";
|
|
44
|
+
|
|
45
|
+
(await verifyChallenge(challenge.code_verifier, challenge.code_challenge)) ===
|
|
46
|
+
true; // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Challenge generation from existing code verifier
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { generateChallenge } from "pkce-challenge";
|
|
53
|
+
|
|
54
|
+
(await generateChallenge(challenge.code_verifier)) === challenge.code_challenge; // true
|
|
55
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Generate a PKCE code challenge from a code verifier
|
|
2
|
+
* @param code_verifier
|
|
3
|
+
* @returns The base64 url encoded code challenge
|
|
4
|
+
*/
|
|
5
|
+
export declare function generateChallenge(code_verifier: string): Promise<string>;
|
|
6
|
+
/** Generate a PKCE challenge pair
|
|
7
|
+
* @param length Length of the verifer (between 43-128). Defaults to 43.
|
|
8
|
+
* @returns PKCE challenge pair
|
|
9
|
+
*/
|
|
10
|
+
export default function pkceChallenge(length?: number): Promise<{
|
|
11
|
+
code_verifier: string;
|
|
12
|
+
code_challenge: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** Verify that a code_verifier produces the expected code challenge
|
|
15
|
+
* @param code_verifier
|
|
16
|
+
* @param expectedChallenge The code challenge to verify
|
|
17
|
+
* @returns True if challenges are equal. False otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
|