Tools for manipulating semver strings and objects
Go to file
AJ ONeal 361e1dd788 Merge pull request #2 from metaraine/master
Add mocha tests. Add support for caret (^).
2015-10-21 10:05:38 -07:00
test Fix reSemverRange to parse pre-release versions that contain hyphens. 2015-08-03 11:12:58 -06:00
.gitignore Add mocha unit tests. 2015-06-06 15:22:04 -06:00
README.md Update README.md 2014-02-24 16:35:47 -06:00
package.json Remove unnecessary deep-equal dependency. 2015-06-06 15:39:50 -06:00
semver-utils.js Fix reSemverRange to parse pre-release versions that contain hyphens. 2015-08-03 11:12:58 -06:00

README.md

semver-utils

Some utils that aren't provided by the mainstream semver module.

Usage

npm install --save semver-utils
'use strict';

var semverUtils = require('semver-utils')
  , version = require('./package.json').version
  , semver = semverUtils.parse(version)
  ;
  
console.log(semver);

API

  • semverUtils.parse(semverString)
  • semverUtils.stringify(semverObject)
  • semverUtils.parseRange(rangeString)
  • semverUtils.stringifyRange(rangeArray)

semverUtils.parse(semverString)

Turns a string such as 1.0.6-1+build-623 into the object

{
  semver:   '1.0.6-1+build-623'
, version:  '1.0.6'
, major:    '1'
, minor:    '0'
, patch:    '6'
, release:  '1'
, build:    'build-623'
}

returns null on error

semverUtils.stringify(semverObject)

Creates a string such as 1.0.6-1+build-623 from the object

{
  major:    '1'
, minor:    '0'
, patch:    '6'
, release:  '1'
, build:    'build-623'
}

semverUtils.parseRange(rangeString)

A solution to https://github.com/isaacs/node-semver/issues/10

Parses a range string into an array of semver objects

>= 1.1.7 < 2.0.0 || 1.1.3 becomes

[
    {
        "semver": ">= v1.1.7"
      , "operator": ">="
      , "major": 1
      , "minor": 1
      , "patch": 7
    }
  , {
        "semver": "< v2.0.0"
      , "operator": "<"
      , "major": 2
      , "minor": 0
      , "patch": 0
    }
  , {
        "operator": "||"
    }
  , {
        "semver": "v1.1.3"
      , "operator": "="
      , "major": 1
      , "minor": 1
      , "patch": 3
    }

]

semverUtils.stringifyRange(rangeArray)

Creates a range string such as >= 1.1.7 < 2.0.0 || 1.1.3 from an array of semver objects (and operators) such as

[
    {
        "semver": ">= v1.1.7"
      , "operator": ">="
      , "major": 1
      , "minor": 1
      , "patch": 7
    }
  , {
        "semver": "< v2.0.0"
      , "operator": "<"
      , "major": 2
      , "minor": 0
      , "patch": 0
    }
  , {
        "operator": "||"
    }
  , {
        "semver": "v1.1.3"
      , "operator": "="
      , "major": 1
      , "minor": 1
      , "patch": 3
    }

]

Obsolete Work