Comparing version 3.0.0 to 4.0.0
@@ -1,25 +0,23 @@ | ||
declare namespace toSemver { | ||
interface Options { | ||
/** | ||
Include prereleases, like `1.2.3-alpha.3`. | ||
export interface Options { | ||
/** | ||
Include prereleases, like `1.2.3-alpha.3`. | ||
@default true | ||
*/ | ||
readonly includePrereleases?: boolean; | ||
@default true | ||
*/ | ||
readonly includePrereleases?: boolean; | ||
/** | ||
Clean versions. For example `v1.3.0` → `1.3.0`. | ||
/** | ||
Clean versions. For example, `v1.3.0` → `1.3.0`. | ||
@default true | ||
*/ | ||
readonly clean?: boolean; | ||
} | ||
@default true | ||
*/ | ||
readonly clean?: boolean; | ||
} | ||
/** | ||
Get an array of valid, sorted, and cleaned [semver](https://semver.org/) versions from an array of strings. | ||
Get an array of valid, sorted, and cleaned [semver](https://semver.org) versions from an array of strings. | ||
@example | ||
``` | ||
import toSemver = require('to-semver'); | ||
import toSemver from 'to-semver'; | ||
@@ -39,7 +37,2 @@ toSemver([ | ||
*/ | ||
declare function toSemver( | ||
versions: readonly string[], | ||
options?: toSemver.Options | ||
): string[]; | ||
export = toSemver; | ||
export default function toSemver(versions: readonly string[], options?: Options): string[]; |
22
index.js
@@ -1,11 +0,9 @@ | ||
'use strict'; | ||
const semver = require('semver'); | ||
const cleanSemver = require('clean-semver'); | ||
import semver from 'semver'; | ||
import cleanSemver from 'clean-semver'; | ||
module.exports = (versions, options) => { | ||
options = { | ||
includePrereleases: true, | ||
clean: true, | ||
...options | ||
}; | ||
export default function toSemver(versions, options = {}) { | ||
const { | ||
includePrereleases = true, | ||
clean = true | ||
} = options; | ||
@@ -18,7 +16,7 @@ let sortedVersions = versions | ||
if (!options.includePrereleases) { | ||
if (!includePrereleases) { | ||
sortedVersions = sortedVersions.filter(version => semver.prerelease(version[1]) === null); | ||
} | ||
if (options.clean) { | ||
if (clean) { | ||
return sortedVersions.map(version => version[1]); | ||
@@ -28,2 +26,2 @@ } | ||
return sortedVersions.map(([version]) => version); | ||
}; | ||
} |
{ | ||
"name": "to-semver", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Get an array of valid, sorted, and cleaned semver versions from an array of strings", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12" | ||
}, | ||
@@ -46,9 +48,9 @@ "scripts": { | ||
"clean-semver": "^2.1.0", | ||
"semver": "^7.3.2" | ||
"semver": "^7.3.5" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.30.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.39.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# to-semver [![Build Status](https://travis-ci.com/sindresorhus/to-semver.svg?branch=master)](https://travis-ci.com/sindresorhus/to-semver) | ||
# to-semver | ||
@@ -13,7 +13,6 @@ > Get an array of valid, sorted, and cleaned [semver](https://semver.org) versions from an array of strings | ||
## Usage | ||
```js | ||
const toSemver = require('to-semver'); | ||
import toSemver from 'to-semver'; | ||
@@ -59,3 +58,3 @@ toSemver([ | ||
Clean versions. For example `v1.3.0` → `1.3.0`. | ||
Clean versions. For example, `v1.3.0` → `1.3.0`. | ||
@@ -62,0 +61,0 @@ ## Related |
Yes
4561
51
65
Updatedsemver@^7.3.5