{"id":13457626,"url":"https://github.com/omichelsen/compare-versions","last_synced_at":"2025-05-14T11:11:52.797Z","repository":{"id":28922474,"uuid":"32447621","full_name":"omichelsen/compare-versions","owner":"omichelsen","description":"Compare semver version strings to find which is greater, equal or lesser.","archived":false,"fork":false,"pushed_at":"2023-12-10T05:18:57.000Z","size":370,"stargazers_count":569,"open_issues_count":4,"forks_count":50,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-03T09:45:15.511Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omichelsen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-18T08:47:12.000Z","updated_at":"2024-05-31T08:01:47.707Z","dependencies_parsed_at":"2023-12-10T06:32:37.749Z","dependency_job_id":null,"html_url":"https://github.com/omichelsen/compare-versions","commit_stats":{"total_commits":110,"total_committers":16,"mean_commits":6.875,"dds":"0.19999999999999996","last_synced_commit":"6376c8fc976252cb0942837fe6bad5769c1f4dda"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omichelsen%2Fcompare-versions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omichelsen%2Fcompare-versions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omichelsen%2Fcompare-versions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omichelsen%2Fcompare-versions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omichelsen","download_url":"https://codeload.github.com/omichelsen/compare-versions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248384690,"owners_count":21094757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T09:00:31.995Z","updated_at":"2025-04-11T11:36:29.771Z","avatar_url":"https://github.com/omichelsen.png","language":"TypeScript","readme":"# compare-versions\n\n[![Build Status](https://github.com/omichelsen/compare-versions/actions/workflows/ci.yml/badge.svg)](https://github.com/omichelsen/compare-versions/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/omichelsen/compare-versions/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/omichelsen/compare-versions?branch=main)\n[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/compare-versions.svg)](https://bundlephobia.com/package/compare-versions)\n\nCompare [semver](https://semver.org/) version strings to find greater, equal or lesser. Runs in the browser as well as Node.js/React Native etc. Has no dependencies and is [tiny](https://bundlephobia.com/package/compare-versions).\n\nSupports the full semver specification including versions with different number of digits like `1.0.0`, `1.0`, `1` and pre-releases like `1.0.0-alpha`. Additionally supports the following variations:\n\n- Wildcards for minor and patch version like `1.0.x` or `1.0.*`.\n- [Chromium version numbers](https://www.chromium.org/developers/version-numbers) with 4 parts, e.g. version `25.0.1364.126`.\n- Any leading `v` is ignored, e.g. `v1.0` is interpreted as `1.0`.\n- Leading zero is ignored, e.g. `1.01.1` is interpreted as `1.1.1`.\n- [npm version ranges](https://docs.npmjs.com/cli/v6/using-npm/semver#ranges), e.g. `1.2.7 || \u003e=1.2.9 \u003c2.0.0`\n\n## Install\n\n```bash\n$ npm install compare-versions\n```\n\n__Note__: Starting from v5 the main export is now _named_ like so: `import { compareVersions } from 'compare-versions'`.\n\n__Note__: Starting from v4 this library includes a ESM version which will automatically be selected by your bundler (webpack, parcel etc). The CJS/UMD version is `lib/umd/index.js` and the new ESM version is `lib/esm/index.js`.\n\n## Usage\n\nWill return `1` if first version is greater, `0` if versions are equal, and `-1` if the second version is greater:\n\n```js\nimport { compareVersions } from 'compare-versions';\n\ncompareVersions('11.1.1', '10.0.0'); //  1\ncompareVersions('10.0.0', '10.0.0'); //  0\ncompareVersions('10.0.0', '11.1.1'); // -1\n```\n\nCan also be used for sorting:\n\n```js\nconst versions = [\n  '1.5.19',\n  '1.2.3',\n  '1.5.5'\n]\nconst sorted = versions.sort(compareVersions);\n/*\n[\n  '1.2.3',\n  '1.5.5',\n  '1.5.19'\n]\n*/\n```\n\n### \"Human Readable\" Compare\n\nThe alternative `compare` function accepts an operator which will be more familiar to humans:\n\n```js\nimport { compare } from 'compare-versions';\n\ncompare('10.1.8', '10.0.4', '\u003e');  // true\ncompare('10.0.1', '10.0.1', '=');  // true\ncompare('10.1.1', '10.2.2', '\u003c');  // true\ncompare('10.1.1', '10.2.2', '\u003c='); // true\ncompare('10.1.1', '10.2.2', '\u003e='); // false\n```\n\n### Version ranges\n\nThe `satisfies` function accepts a range to compare, compatible with [npm package versioning](https://docs.npmjs.com/cli/v6/using-npm/semver):\n\n```js\nimport { satisfies } from 'compare-versions';\n\nsatisfies('10.0.1', '~10.0.0');  // true\nsatisfies('10.1.0', '~10.0.0');  // false\nsatisfies('10.1.2', '^10.0.0');  // true\nsatisfies('11.0.0', '^10.0.0');  // false\nsatisfies('10.1.8', '\u003e10.0.4');  // true\nsatisfies('10.0.1', '=10.0.1');  // true\nsatisfies('10.1.1', '\u003c10.2.2');  // true\nsatisfies('10.1.1', '\u003c=10.2.2'); // true\nsatisfies('10.1.1', '\u003e=10.2.2'); // false\nsatisfies('1.4.6', '1.2.7 || \u003e=1.2.9 \u003c2.0.0'); // true\nsatisfies('1.2.8', '1.2.7 || \u003e=1.2.9 \u003c2.0.0'); // false\nsatisfies('1.5.1', '1.2.3 - 2.3.4'); // true\nsatisfies('2.3.5', '1.2.3 - 2.3.4'); // false\n```\n\n### Validate version numbers\n\nApplies the same rules used comparing version numbers and returns a boolean:\n\n```js\nimport { validate } from 'compare-versions';\n\nvalidate('1.0.0-rc.1'); // true\nvalidate('1.0-rc.1');   // false\nvalidate('foo');        // false\n```\n\n### Validate version numbers (strict)\n\nValidate version numbers strictly according to semver.org; 3 integers, no wildcards, no leading zero or \"v\" etc:\n\n```js\nimport { validateStrict } from 'compare-versions';\n\nvalidate('1.0.0');      // true\nvalidate('1.0.0-rc.1'); // true\nvalidate('1.0');        // false\nvalidate('1.x');        // false\nvalidate('v1.02');      // false\n```\n\n### Browser\n\nIn modern browsers the functions above can be imported as modules:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { compareVersions, compare, satisfies, validate, validateStrict } from './node_modules/compare-versions/lib/esm/index.js'\n  console.log(compareVersions('11.0.0', '10.0.0'))\n  console.log(compare('11.0.0', '10.0.0', '\u003e'))\n  console.log(satisfies('1.2.0', '^1.0.0'))\n  console.log(validate('11.0.0'))\n  console.log(validateStrict('11.0.0'))\n\u003c/script\u003e\n```\n\n#### Legacy (UMD)\n\nIf included directly in the browser, the functions above are available on the global window under the `compareVersions` object:\n\n```html\n\u003cscript src=\"https://unpkg.com/compare-versions/lib/umd/index.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const { compareVersions, compare, satisfies, validate, validateStrict } = window.compareVersions\n  console.log(compareVersions('11.0.0', '10.0.0'))\n  console.log(compare('11.0.0', '10.0.0', '\u003e'))\n  console.log(satisfies('1.2.0', '^1.0.0'))\n  console.log(validate('11.0.0'))\n  console.log(validateStrict('11.0.0'))\n\u003c/script\u003e\n```\n","funding_links":[],"categories":["TypeScript","Repository"],"sub_categories":["NPM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomichelsen%2Fcompare-versions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomichelsen%2Fcompare-versions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomichelsen%2Fcompare-versions/lists"}