Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

semver

Package Overview
Dependencies
Maintainers
4
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

semver - npm Package Compare versions

Comparing version
7.7.4
to
7.8.0
+48
functions/truncate.js
'use strict'
const parse = require('./parse')
const constants = require('../internal/constants')
const SemVer = require('../classes/semver')
const truncate = (version, truncation, options) => {
if (!constants.RELEASE_TYPES.includes(truncation)) {
return null
}
const clonedVersion = cloneInputVersion(version, options)
return clonedVersion && doTruncation(clonedVersion, truncation)
}
const cloneInputVersion = (version, options) => {
const versionStringToParse = (
version instanceof SemVer ? version.version : version
)
return parse(versionStringToParse, options)
}
const doTruncation = (version, truncation) => {
if (isPrerelease(truncation)) {
return version.version
}
version.prerelease = []
switch (truncation) {
case 'major':
version.minor = 0
version.patch = 0
break
case 'minor':
version.patch = 0
break
}
return version.format()
}
const isPrerelease = (type) => {
return type.startsWith('pre')
}
module.exports = truncate
+14
-10

@@ -49,2 +49,3 @@ #!/usr/bin/env node

}
switch (a) {

@@ -64,11 +65,6 @@ case '-rv': case '-rev': case '--rev': case '--reverse':

case '-i': case '--inc': case '--increment':
switch (argv[0]) {
case 'major': case 'minor': case 'patch': case 'prerelease':
case 'premajor': case 'preminor': case 'prepatch':
case 'release':
inc = argv.shift()
break
default:
inc = 'patch'
break
if (semver.RELEASE_TYPES.includes(argv[0]) || (argv[0] === 'release')) {
inc = { value: argv.shift(), maybeErrantValue: null, option: a }
} else {
inc = { value: 'patch', maybeErrantValue: argv[0], option: a }
}

@@ -107,2 +103,10 @@ break

if (
inc &&
versions.includes(inc.maybeErrantValue) &&
!semver.valid(inc.maybeErrantValue, options)
) {
console.warn(`Invalid value for ${inc.option}; defaulting to 'patch'. This may become a failure in future major versions.`)
}
versions = versions.map((v) => {

@@ -131,3 +135,3 @@ return coerce ? (semver.coerce(v, options) || { version: v }).version : v

.map(v => semver.clean(v, options))
.map(v => inc ? semver.inc(v, inc, options, identifier, identifierBase) : v)
.map(v => inc ? semver.inc(v, inc.value, options, identifier, identifierBase) : v)
.forEach(v => console.log(v))

@@ -134,0 +138,0 @@ }

@@ -31,2 +31,3 @@ 'use strict'

const coerce = require('./functions/coerce')
const truncate = require('./functions/truncate')
const Comparator = require('./classes/comparator')

@@ -70,2 +71,3 @@ const Range = require('./classes/range')

coerce,
truncate,
Comparator,

@@ -72,0 +74,0 @@ Range,

@@ -139,3 +139,3 @@ 'use strict'

// Something like "2.*" or "1.2.x".
// Note that "x.x" is a valid xRange identifer, meaning "any version"
// Note that "x.x" is a valid xRange identifier, meaning "any version"
// Only the first item is strictly required.

@@ -142,0 +142,0 @@ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`)

{
"name": "semver",
"version": "7.7.4",
"version": "7.8.0",
"description": "The semantic version parser used by npm.",

@@ -18,3 +18,3 @@ "main": "index.js",

"@npmcli/eslint-config": "^6.0.0",
"@npmcli/template-oss": "4.29.0",
"@npmcli/template-oss": "5.0.0",
"benchmark": "^2.1.4",

@@ -56,3 +56,3 @@ "tap": "^16.0.0"

"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.29.0",
"version": "5.0.0",
"engines": ">=10",

@@ -59,0 +59,0 @@ "distPaths": [

@@ -59,2 +59,3 @@ semver(1) -- The semantic versioner for npm

const semverRsort = require('semver/functions/rsort')
const semverTruncate = require('semver/functions/truncate')

@@ -403,8 +404,15 @@ // low-level comparators between versions

qualifier ::= ( '-' pre )? ( '+' build )?
pre ::= parts
build ::= parts
parts ::= part ( '.' part ) *
part ::= nr | [-0-9A-Za-z]+
pre ::= prepart ( '.' prepart ) *
prepart ::= nr | alphanumid
build ::= buildid ( '.' buildid ) *
alphanumid ::= ( ['0'-'9'] ) * [-A-Za-z] [-0-9A-Za-z] *
buildid ::= [-0-9A-Za-z]+
```
Note: Prerelease identifiers (`pre`) use `nr` for numeric parts, which
disallows leading zeros (e.g., `1.2.3-00` is invalid). Build metadata
identifiers (`build`) allow any alphanumeric string including leading
zeros (e.g., `1.2.3+00` is valid). This matches the
[SemVer 2.0.0 specification](https://semver.org/#spec-item-9).
## Functions

@@ -454,2 +462,8 @@

a `SemVer` object or `null`.
* `truncate(v, releaseType)`: Return the version with components _lower_
than `releaseType` dropped off, e.g.:
* `major` removes build & prerelease info and sets minor & patch to 0.
* `minor` removes build & prerelease info, and sets patch to 0
* `patch` removes build & prerelease info
* All prerelease types remove build info only

@@ -656,2 +670,3 @@ ### Comparison

* `require('semver/functions/sort')`
* `require('semver/functions/truncate')`
* `require('semver/functions/valid')`

@@ -658,0 +673,0 @@ * `require('semver/ranges/gtr')`

Sorry, the diff of this file is not supported yet