What is find-versions?
The find-versions npm package is designed to extract version numbers from strings. It is useful for parsing and identifying version numbers in various formats from text, allowing developers to easily extract and manipulate version information programmatically.
What are find-versions's main functionalities?
Extracting version numbers from strings
This feature allows you to extract version numbers from a given string. The function returns an array of version numbers found within the string. It's particularly useful for parsing logs, documents, or any text content that may contain version numbers.
"const findVersions = require('find-versions');\nconsole.log(findVersions('unicorn v1.2.3')); //=> ['1.2.3']"
Extracting version numbers with options
This feature extends the basic functionality by allowing you to specify options for the extraction process. For example, setting the 'loose' option to true enables the function to match version numbers that don't strictly follow semantic versioning.
"const findVersions = require('find-versions');\nconsole.log(findVersions('cat 1.2.3 and dog 4.5.6', {loose: true})); //=> ['1.2.3', '4.5.6']"
Other packages similar to find-versions
semver
The semver package is a module for semantic versioning. It provides utilities for parsing and comparing semantic versions. While it focuses on semantic versioning, find-versions is more general-purpose, extracting version numbers from strings regardless of their format.
validate-version
validate-version is a package that allows you to check if a string is a valid semantic version. Unlike find-versions, which extracts version numbers from arbitrary text, validate-version focuses on validating the format of version strings.
find-versions
Find semver versions in a string: unicorn v1.2.3
→ 1.2.3
Install
npm install find-versions
Usage
import findVersions from 'find-versions';
findVersions('unicorn v1.2.3 rainbow 2.3.4+build.1');
findVersions('cp (GNU coreutils) 8.22', {loose: true});
API
findVersions(stringWithVersions, options?)
stringWithVersions
Type: string
options
Type: object
loose
Type: boolean
Default: false
Also match non-semver versions like 1.88
. They're coerced into semver compliant versions.
Related