
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
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`
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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.