addons-moz-compare
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "addons-moz-compare", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "JS implementation to compare add-on versions.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,4 +5,38 @@ # addons-moz-compare | ||
A JavaScript library to compare Mozilla add-on versions. | ||
A JavaScript library to compare Mozilla add-on versions that follow the [Manifest Version Format](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version/format). | ||
For more information: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version/format | ||
## API | ||
This library exposes a `mozCompare()` function that takes two (string) versions `A` and `B` and returns: | ||
- `-1` if `A < B` | ||
- `0` if `A == B` | ||
- `1` if `A > B` | ||
This implementation matches the Firefox implementation except that there are only 3 different possible return values (Firefox returns strictly negative and strictly positive values instead of `-1` and `1`). | ||
## Usage | ||
``` | ||
npm i addons-moz-compare | ||
``` | ||
or | ||
``` | ||
yarn add addons-moz-compare | ||
``` | ||
### Node | ||
``` | ||
const { mozCompare } = require('addons-moz-compare'); | ||
``` | ||
### Browser | ||
Use `window.mozCompare` after having included the source of this library. | ||
## License | ||
This plugin is released under the Mozilla Public License Version 2.0. See the bundled [LICENSE](./LICENSE.txt) file for details. |
@@ -1,2 +0,2 @@ | ||
(function addonsMozComparator() { | ||
(function addonsMozCompare() { | ||
const compareParts = (partA, partB) => { | ||
@@ -10,2 +10,4 @@ if (partA === partB) { | ||
// This isn't strictly a bytewise comparison but it has conditions that | ||
// `compareParts()` does not have. | ||
const compareByteWiseParts = (partA, partB) => { | ||
@@ -50,3 +52,3 @@ if (!partA) { | ||
const parsePart = (part) => { | ||
// Normalize zero if needed. | ||
// Normalize leading zero if needed. | ||
if (!part || /^0+$/.test(part.toString())) { | ||
@@ -118,5 +120,5 @@ return 0; | ||
* @param versionB the second version | ||
* @returns < 0 if A < B | ||
* = 0 if A == B | ||
* > 0 if A > B | ||
* @returns -1 if A < B | ||
* 0 if A == B | ||
* 1 if A > B | ||
*/ | ||
@@ -123,0 +125,0 @@ const mozCompare = (versionA, versionB) => { |
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
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
22434
120
42