version-range
Advanced tools
Comparing version 4.0.0 to 4.1.0-next.1700430339.baa6aab420a08840f0363e9834f0c64598d7dba5
@@ -5,3 +5,3 @@ export type Version = string | number | ||
const orRegex = /\s*\|\|\s*/ | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+)(-.+)?\s*$/ | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+?)[.x]*(-.+)?\s*$/ | ||
@@ -27,9 +27,9 @@ /** | ||
// cycle through the or conditions | ||
// cycle through the conditions | ||
let combinedResult: boolean = false | ||
if (!Array.isArray(range)) range = String(range).split(orRegex) | ||
for (const orRange of range) { | ||
for (const condition of range) { | ||
// process range | ||
const [_, comparator, target, prerelease] = | ||
String(orRange).match(rangeRegex) || [] | ||
String(condition).match(rangeRegex) || [] | ||
@@ -41,3 +41,5 @@ // prepare and verify target | ||
if (!target || targetMajor == null || prerelease) | ||
throw new Error(`range was invalid: ${JSON.stringify(orRange)}`) | ||
throw new Error( | ||
`range condition was invalid: ${JSON.stringify(condition)}` | ||
) | ||
const targetMajorNumber = Number(targetMajor || 0) | ||
@@ -170,3 +172,3 @@ const targetMinorNumber = Number(targetMinor || 0) | ||
throw new Error( | ||
`range comparator was invalid: ${JSON.stringify(orRange)}` | ||
`range comparator was invalid: ${JSON.stringify(condition)}` | ||
) | ||
@@ -173,0 +175,0 @@ } |
const orRegex = /\s*\|\|\s*/; | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+)(-.+)?\s*$/; | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+?)[.x]*(-.+)?\s*$/; | ||
/** | ||
@@ -17,13 +17,13 @@ * Check if the version is within the range | ||
const subjectPatchNumber = Number(subjectPatch || 0); | ||
// cycle through the or conditions | ||
// cycle through the conditions | ||
let combinedResult = false; | ||
if (!Array.isArray(range)) | ||
range = String(range).split(orRegex); | ||
for (const orRange of range) { | ||
for (const condition of range) { | ||
// process range | ||
const [_, comparator, target, prerelease] = String(orRange).match(rangeRegex) || []; | ||
const [_, comparator, target, prerelease] = String(condition).match(rangeRegex) || []; | ||
// prepare and verify target | ||
const [targetMajor = null, targetMinor = null, targetPatch = null] = (target || '').split('.'); | ||
if (!target || targetMajor == null || prerelease) | ||
throw new Error(`range was invalid: ${JSON.stringify(orRange)}`); | ||
throw new Error(`range condition was invalid: ${JSON.stringify(condition)}`); | ||
const targetMajorNumber = Number(targetMajor || 0); | ||
@@ -170,3 +170,3 @@ const targetMinorNumber = Number(targetMinor || 0); | ||
default: | ||
throw new Error(`range comparator was invalid: ${JSON.stringify(orRange)}`); | ||
throw new Error(`range comparator was invalid: ${JSON.stringify(condition)}`); | ||
} | ||
@@ -173,0 +173,0 @@ if (pass) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const orRegex = /\s*\|\|\s*/; | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+)(-.+)?\s*$/; | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+?)[.x]*(-.+)?\s*$/; | ||
/** | ||
@@ -19,13 +19,13 @@ * Check if the version is within the range | ||
const subjectPatchNumber = Number(subjectPatch || 0); | ||
// cycle through the or conditions | ||
// cycle through the conditions | ||
let combinedResult = false; | ||
if (!Array.isArray(range)) | ||
range = String(range).split(orRegex); | ||
for (const orRange of range) { | ||
for (const condition of range) { | ||
// process range | ||
const [_, comparator, target, prerelease] = String(orRange).match(rangeRegex) || []; | ||
const [_, comparator, target, prerelease] = String(condition).match(rangeRegex) || []; | ||
// prepare and verify target | ||
const [targetMajor = null, targetMinor = null, targetPatch = null] = (target || '').split('.'); | ||
if (!target || targetMajor == null || prerelease) | ||
throw new Error(`range was invalid: ${JSON.stringify(orRange)}`); | ||
throw new Error(`range condition was invalid: ${JSON.stringify(condition)}`); | ||
const targetMajorNumber = Number(targetMajor || 0); | ||
@@ -172,3 +172,3 @@ const targetMinorNumber = Number(targetMinor || 0); | ||
default: | ||
throw new Error(`range comparator was invalid: ${JSON.stringify(orRange)}`); | ||
throw new Error(`range comparator was invalid: ${JSON.stringify(condition)}`); | ||
} | ||
@@ -175,0 +175,0 @@ if (pass) |
{ | ||
"name": "version-range", | ||
"version": "4.0.0", | ||
"version": "4.1.0-next.1700430339.baa6aab420a08840f0363e9834f0c64598d7dba5", | ||
"description": "Check version ranges like `>=N` and `X || Y || Z` with support for Node.js, Web Browsers, Deno, and TypeScript.", | ||
@@ -8,2 +8,3 @@ "homepage": "https://github.com/bevry/version-range", | ||
"keywords": [ | ||
"browser", | ||
"compare", | ||
@@ -18,2 +19,3 @@ "conditional", | ||
"gte", | ||
"module", | ||
"node", | ||
@@ -101,2 +103,16 @@ "node.js", | ||
{ | ||
"description": "TypeScript compiled against ES2022 for web browsers with Import for modules", | ||
"directory": "edition-browsers", | ||
"entry": "index.js", | ||
"tags": [ | ||
"compiled", | ||
"javascript", | ||
"import" | ||
], | ||
"engines": { | ||
"node": false, | ||
"browsers": "defaults" | ||
} | ||
}, | ||
{ | ||
"description": "TypeScript compiled against ES2022 for Node.js 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with Require for modules", | ||
@@ -142,3 +158,3 @@ "directory": "edition-es2022", | ||
"deno": true, | ||
"browsers": false | ||
"browsers": true | ||
} | ||
@@ -154,5 +170,10 @@ } | ||
"require": "./edition-es2022/index.js" | ||
}, | ||
"browser": { | ||
"import": "./edition-browsers/index.js" | ||
} | ||
}, | ||
"deno": "edition-deno/index.ts", | ||
"browser": "edition-browsers/index.js", | ||
"module": "edition-browsers/index.js", | ||
"devDependencies": { | ||
@@ -176,8 +197,10 @@ "@bevry/json": "^1.9.0", | ||
"typescript": "5.2.2", | ||
"valid-directory": "^4.4.0" | ||
"valid-directory": "^4.4.0", | ||
"valid-module": "^2.3.0" | ||
}, | ||
"scripts": { | ||
"our:clean": "rm -rf ./docs ./edition* ./es2015 ./es5 ./out ./.next", | ||
"our:compile": "npm run our:compile:deno && npm run our:compile:edition-es2022 && npm run our:compile:edition-es2022-esm && npm run our:compile:types", | ||
"our:compile": "npm run our:compile:deno && npm run our:compile:edition-browsers && npm run our:compile:edition-es2022 && npm run our:compile:edition-es2022-esm && npm run our:compile:types", | ||
"our:compile:deno": "make-deno-edition --attempt", | ||
"our:compile:edition-browsers": "tsc --module ESNext --target ES2022 --outDir ./edition-browsers --project tsconfig.json && ( test ! -d edition-browsers/source || ( mv edition-browsers/source edition-temp && rm -rf edition-browsers && mv edition-temp edition-browsers ) )", | ||
"our:compile:edition-es2022": "tsc --module commonjs --target ES2022 --outDir ./edition-es2022 --project tsconfig.json && ( test ! -d edition-es2022/source || ( mv edition-es2022/source edition-temp && rm -rf edition-es2022 && mv edition-temp edition-es2022 ) ) && printf '%s' '{\"type\": \"commonjs\"}' > edition-es2022/package.json", | ||
@@ -201,5 +224,6 @@ "our:compile:edition-es2022-esm": "tsc --module ESNext --target ES2022 --outDir ./edition-es2022-esm --project tsconfig.json && ( test ! -d edition-es2022-esm/source || ( mv edition-es2022-esm/source edition-temp && rm -rf edition-es2022-esm && mv edition-temp edition-es2022-esm ) ) && printf '%s' '{\"type\": \"module\"}' > edition-es2022-esm/package.json", | ||
"our:test": "npm run our:verify && npm test", | ||
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:prettier", | ||
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:module && npm run our:verify:prettier", | ||
"our:verify:directory": "valid-directory", | ||
"our:verify:eslint": "eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source", | ||
"our:verify:module": "valid-module", | ||
"our:verify:prettier": "prettier --write .", | ||
@@ -219,4 +243,5 @@ "test": "node ./edition-es2022/test.js" | ||
"boundation": { | ||
"browser": true, | ||
"nodeVersionTestedMinimum": 8 | ||
} | ||
} | ||
} |
@@ -40,3 +40,3 @@ <!-- TITLE/ --> | ||
Super fast and super compatible version range comparison for the most common use cases. As semver has two different behaviours based on whether the version is coerced or not, this library differs to match our actual expectations, unlike semver. For example: | ||
Range comparison of versions for the most common use cases. Fast with broad ecosystem support. | ||
@@ -66,3 +66,5 @@ ```typescript | ||
console.log(satisfies('1', '^1')) // true | ||
console.log(satisfies('1', '~1')) // false | ||
console.log(satisfies('1', '~1')) // false, not all 1.x versions (1.1, 1.2, etc) match 1.0.x | ||
console.log(satisfies('1', '^1.1')) // false, not all 1.x versions (1.0) match >=1.1<2 | ||
console.log(satisfies('1', '~1.1')) // false, not all 1.x versions (1.0) match 1.1.x | ||
console.log(satisfies('1.0.0', '^1')) // true | ||
@@ -72,4 +74,6 @@ console.log(satisfies('1.0.0', '~1')) // true | ||
Doesn't support ranges that include `.x`, `&&`, `-releaseTag`, and `>X <Y`. | ||
The above results are expected, but not what the [`semver` package](https://www.npmjs.com/package/semver) returns. The semver package has two different behaviours based on whether the version is coerced or not, alternating between expected and unexpected results. This package differs to match our actual expectations, as you can see above. | ||
Doesn't support ranges that include `&&`, `-releaseTag`, and `>X <Y`, and does not do the special handling for `0.x` versions. | ||
<!-- INSTALL/ --> | ||
@@ -89,5 +93,29 @@ | ||
``` typescript | ||
import pkg from 'https://unpkg.com/version-range@^4.0.0/edition-deno/index.ts' | ||
import pkg from 'https://unpkg.com/version-range@^4.1.0/edition-deno/index.ts' | ||
``` | ||
<a href="https://www.skypack.dev" title="Skypack is a JavaScript Delivery Network for modern web apps"><h3>Skypack</h3></a> | ||
``` html | ||
<script type="module"> | ||
import pkg from '//cdn.skypack.dev/version-range@^4.1.0' | ||
</script> | ||
``` | ||
<a href="https://unpkg.com" title="unpkg is a fast, global content delivery network for everything on npm"><h3>unpkg</h3></a> | ||
``` html | ||
<script type="module"> | ||
import pkg from '//unpkg.com/version-range@^4.1.0' | ||
</script> | ||
``` | ||
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a> | ||
``` html | ||
<script type="module"> | ||
import pkg from '//dev.jspm.io/version-range@4.1.0' | ||
</script> | ||
``` | ||
<h3><a href="https://editions.bevry.me" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3> | ||
@@ -98,2 +126,3 @@ | ||
<ul><li><code>version-range/source/index.ts</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> source code with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li> | ||
<li><code>version-range/edition-browsers/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against ES2022 for web browsers with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li> | ||
<li><code>version-range</code> aliases <code>version-range/edition-es2022/index.js</code></li> | ||
@@ -100,0 +129,0 @@ <li><code>version-range/edition-es2022/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against ES2022 for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 8 || 10 || 12 || 14 || 16 || 18 || 20 || 21 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li> |
@@ -5,3 +5,3 @@ export type Version = string | number | ||
const orRegex = /\s*\|\|\s*/ | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+)(-.+)?\s*$/ | ||
const rangeRegex = /^\s*([<>=~^]*)\s*([\d.]+?)[.x]*(-.+)?\s*$/ | ||
@@ -27,9 +27,9 @@ /** | ||
// cycle through the or conditions | ||
// cycle through the conditions | ||
let combinedResult: boolean = false | ||
if (!Array.isArray(range)) range = String(range).split(orRegex) | ||
for (const orRange of range) { | ||
for (const condition of range) { | ||
// process range | ||
const [_, comparator, target, prerelease] = | ||
String(orRange).match(rangeRegex) || [] | ||
String(condition).match(rangeRegex) || [] | ||
@@ -41,3 +41,5 @@ // prepare and verify target | ||
if (!target || targetMajor == null || prerelease) | ||
throw new Error(`range was invalid: ${JSON.stringify(orRange)}`) | ||
throw new Error( | ||
`range condition was invalid: ${JSON.stringify(condition)}` | ||
) | ||
const targetMajorNumber = Number(targetMajor || 0) | ||
@@ -170,3 +172,3 @@ const targetMinorNumber = Number(targetMinor || 0) | ||
throw new Error( | ||
`range comparator was invalid: ${JSON.stringify(orRange)}` | ||
`range comparator was invalid: ${JSON.stringify(condition)}` | ||
) | ||
@@ -173,0 +175,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66956
15
889
196
19
1