Socket
Socket
Sign inDemoInstall

semver-truncate

Package Overview
Dependencies
3
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    semver-truncate

Truncate a semver version: `1.2.3` → `1.2.0`


Version published
Weekly downloads
1.8M
increased by1.51%
Maintainers
1
Install size
124 kB
Created
Weekly downloads
 

Package description

What is semver-truncate?

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.

What are semver-truncate's main functionalities?

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'"

Other packages similar to semver-truncate

Readme

Source

semver-truncate

Truncate a semver version: 1.2.31.2.0

Install

$ npm install semver-truncate

Usage

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'

API

truncateSemver(version, type)

version

Type: string

Semver version.

type

Type: 'patch' | 'minor' | 'major'

Version type to truncate to.

  • latest-semver - Get the latest stable semver version from an array of versions
  • to-semver - Get an array of valid, sorted, and cleaned semver versions from an array of strings
  • semver-regex - Regular expression for matching semver versions
  • semver-diff - Get the diff type of two semver versions: 0.0.1 0.0.2patch

Keywords

FAQs

Last updated on 28 Apr 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc