find-versions
Advanced tools
Comparing version 2.0.0 to 3.0.0
20
index.js
'use strict'; | ||
var semverRegex = require('semver-regex'); | ||
var arrayUniq = require('array-uniq'); | ||
const semverRegex = require('semver-regex'); | ||
const arrayUniq = require('array-uniq'); | ||
module.exports = function (str, opts) { | ||
if (typeof str !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
module.exports = (input, options = {}) => { | ||
if (typeof input !== 'string') { | ||
throw new TypeError(`Expected a string, got ${typeof input}`); | ||
} | ||
opts = opts || {}; | ||
const reLoose = new RegExp(`(?:${semverRegex().source})|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)`, 'g'); | ||
const matches = input.match(options.loose === true ? reLoose : semverRegex()) || []; | ||
var reLoose = new RegExp('(?:' + semverRegex().source + ')|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)', 'g'); | ||
var matches = str.match(opts.loose === true ? reLoose : semverRegex()) || []; | ||
return arrayUniq(matches.map(function (x) { | ||
return x.trim().replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0'); | ||
})); | ||
return arrayUniq(matches.map(match => match.trim().replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0'))); | ||
}; |
{ | ||
"name": "find-versions", | ||
"version": "2.0.0", | ||
"description": "Find semver versions in a string: `unicorn 1.0.0` → `1.0.0`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/find-versions", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"semver", | ||
"version", | ||
"versions", | ||
"regex", | ||
"regexp", | ||
"re", | ||
"match", | ||
"matching", | ||
"semantic", | ||
"find", | ||
"extract", | ||
"get" | ||
], | ||
"dependencies": { | ||
"array-uniq": "^1.0.0", | ||
"semver-regex": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "find-versions", | ||
"version": "3.0.0", | ||
"description": "Find semver versions in a string: `unicorn v1.2.3` → `1.2.3`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/find-versions", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"semver", | ||
"version", | ||
"versions", | ||
"regex", | ||
"regexp", | ||
"match", | ||
"matching", | ||
"semantic", | ||
"find", | ||
"extract", | ||
"get" | ||
], | ||
"dependencies": { | ||
"array-uniq": "^2.0.0", | ||
"semver-regex": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.0.0-rc.1", | ||
"xo": "^0.23.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# find-versions [![Build Status](https://travis-ci.org/sindresorhus/find-versions.svg?branch=master)](https://travis-ci.org/sindresorhus/find-versions) | ||
# find-versions [![Build Status](https://travis-ci.com/sindresorhus/find-versions.svg?branch=master)](https://travis-ci.com/sindresorhus/find-versions) | ||
> Find semver versions in a string: `unicorn 1.0.0` → `1.0.0` | ||
> Find semver versions in a string: `unicorn v1.2.3` → `1.2.3` | ||
@@ -9,3 +9,3 @@ | ||
``` | ||
$ npm install --save find-versions | ||
$ npm install find-versions | ||
``` | ||
@@ -19,4 +19,4 @@ | ||
findVersions('unicorn 1.0.0 rainbow v2.3.4+build.1'); | ||
//=> ['1.0.0', '2.3.4+build.1'] | ||
findVersions('unicorn v1.2.3 rainbow 2.3.4+build.1'); | ||
//=> ['1.2.3', '2.3.4+build.1'] | ||
@@ -38,9 +38,10 @@ findVersions('cp (GNU coreutils) 8.22', {loose: true}); | ||
Type: `Object` | ||
##### loose | ||
Type: `boolean` | ||
Type: `boolean` | ||
Default: `false` | ||
Also match non-semver versions like `1.88`. | ||
They're coerced into semver compliant versions. | ||
Also match non-semver versions like `1.88`. They're coerced into semver compliant versions. | ||
@@ -55,2 +56,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
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
54
3264
11
+ Addedarray-uniq@2.1.0(transitive)
+ Addedsemver-regex@2.0.0(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedsemver-regex@1.0.0(transitive)
Updatedarray-uniq@^2.0.0
Updatedsemver-regex@^2.0.0