
Product
Introducing Repository Labels and Security Policies
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
semver-truncate
Advanced tools
The semver-truncate npm package is designed to truncate semantic versions to a specified level of precision. It can be used to manipulate version strings, allowing developers to easily reduce a full semantic version to just the major, minor, or patch component. This can be particularly useful in scenarios where software compatibility or versioning policies require simplified version strings.
Truncate to major version
This feature allows you to truncate a semantic version to its major component. It's useful when you need to reference or work with the major version of a dependency or project.
"const semverTruncate = require('semver-truncate');
console.log(semverTruncate('1.2.3', 'major')); // '1'"
Truncate to minor version
This feature enables truncation of a semantic version to include just the major and minor components, omitting the patch level. It can be useful for defining compatibility ranges or when minor version precision is required.
"const semverTruncate = require('semver-truncate');
console.log(semverTruncate('1.2.3', 'minor')); // '1.2'"
Truncate to patch version
This feature allows for the full semantic version string to be used, including the patch level. It's essentially a no-op in this context but can be used for consistency in code that dynamically selects the truncation level.
"const semverTruncate = require('semver-truncate');
console.log(semverTruncate('1.2.3', 'patch')); // '1.2.3'"
The semver package is a more comprehensive tool for working with semantic versions. It includes functionality for parsing, comparing, and manipulating semantic versions beyond simple truncation. Compared to semver-truncate, semver offers a broader set of features for detailed version management.
compare-versions is another npm package that allows for comparison of semantic version numbers. While it focuses more on the comparison aspect rather than truncation, it shares the common ground of manipulating version strings for various purposes.
Truncate a semver version:
1.2.3
→1.2.0
$ npm install semver-truncate
import semverTruncate from 'semver-truncate';
semverTruncate('1.2.3-foo', 'patch');
//=> '1.2.3'
semverTruncate('1.2.3', 'minor');
//=> '1.2.0'
semverTruncate('1.2.3', 'major');
//=> '1.0.0'
Type: string
Semver version.
Type: 'patch' | 'minor' | 'major'
Version type to truncate to.
0.0.1
0.0.2
→ patch
FAQs
Truncate a semver version: `1.2.3` → `1.2.0`
The npm package semver-truncate receives a total of 1,981,334 weekly downloads. As such, semver-truncate popularity was classified as popular.
We found that semver-truncate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
Research
Security News
Socket researchers uncovered malicious npm and PyPI packages that steal crypto wallet credentials using Google Analytics and Telegram for exfiltration.
Product
Socket now supports .NET, bringing supply chain security and SBOM accuracy to NuGet and MSBuild-powered C# projects.