Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
find-versions
Advanced tools
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.
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']"
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 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 semver versions in a string:
unicorn 1.0.0
→1.0.0
$ npm install --save find-versions
var findVersions = require('find-versions');
findVersions('unicorn 1.0.0 rainbow v2.3.4+build.1');
//=> ['1.0.0', '2.3.4+build.1']
findVersions('cp (GNU coreutils) 8.22', {loose: true});
//=> ['8.22.0']
Required
Type: string
Type: boolean
Default: false
Also match non-semver versions like 1.88
.
They're coerced into semver compliant versions.
$ npm install --global find-versions
$ find-versions --help
Usage
find-versions <string> [--first] [--loose]
echo <string> | find-versions
Example
find-versions 'unicorns v1.2.3'
1.2.3
curl --version | find-versions --first
7.30.0
Options
--first Return the first match
--loose Match non-semver versions like 1.88
MIT © Sindre Sorhus
FAQs
Find semver versions in a string: `unicorn v1.2.3` → `1.2.3`
The npm package find-versions receives a total of 4,540,968 weekly downloads. As such, find-versions popularity was classified as popular.
We found that find-versions demonstrated a healthy version release cadence and project activity because the last version was released less than 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.