JSPM

@stdlib/regexp-semver

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1558
  • Score
    100M100P100Q118612F
  • License Apache-2.0

Return a regular expression to match a semantic version string.

Package Exports

  • @stdlib/regexp-semver
  • @stdlib/regexp-semver/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/regexp-semver) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Semantic Version

NPM version Build Status Coverage Status

Regular expression to match a semantic version string.

Installation

npm install @stdlib/regexp-semver

Usage

var reSemVer = require( '@stdlib/regexp-semver' );

reSemVer()

Return a regular expression to match a semantic version string.

var RE_SEMVER = reSemVer();
// returns <RegExp>

var parts = RE_SEMVER.exec( '1.0.0' );
/* returns
    [
        '1.0.0',
        '1',
        '0',
        '0',
        undefined,
        undefined,
        index: 0,
        input: '1.0.0',
        groups: undefined
    ]
*/

parts = RE_SEMVER.exec( '1.0.0-alpha.1' );
/* returns
    [
        '1.0.0-alpha.1',
        '1',
        '0',
        '0',
        'alpha',
        '1',
        index: 0,
        input: '1.0.0-alpha.1',
        groups: undefined
    ]
*/

reSemVer.REGEXP

Regular expression to match a semantic version string.

var parts = reSemVer.REGEXP.exec( '0.2.3' );
/* returns
    [
        '0.2.3',
        '0',
        '2',
        '3',
        undefined,
        undefined,
        index: 0,
        input: '0.2.3',
        groups: undefined
    ]
*/

Examples

var reSemVer = require( '@stdlib/regexp-semver' );

var RE_SEMVER = reSemVer();
var version = '1.0.0';
var bool = RE_SEMVER.test( version );
// returns true

version = '1.0.0-alpha.1';
bool = RE_SEMVER.test( version );
// returns true

version = '1.0.0-alpha.1+build.1';
bool = RE_SEMVER.test( version );
// returns true

version = '1.0.0-alpha.1+build.1.2.b8f12d7';
bool = RE_SEMVER.test( version );
// returns true

version = '1.2';
bool = RE_SEMVER.test( version );
// returns false

version = '-1.2.3';
bool = RE_SEMVER.test( version );
// returns false

version = 'a.b.c';
bool = RE_SEMVER.test( version );
// returns false

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright © 2016-2022. The Stdlib Authors.