1.1.0 • Published 7 years ago

vparse v1.1.0

Weekly downloads
38
License
MIT
Repository
github
Last release
7 years ago

vparse

The smallest version parser, for client + server, done natively in JavaScript + TypeScript.

It is the minimum for parsing and comparing versions, when use of semver is an overkill.

Build Status Coverage Status

Installing

$ npm install vparse

See also the TypeScript implementation of the library.

Usage

  • Node.js
var parseVersion = require('vparse');

parseVersion('1.2.3.4');
  • Browser
<script src="./vparse"></script>

<script>
    parseVersion('1.2.3.4');
</script>

Function parseVersion returns an object:

{
    major: 1,
    minor: 2,
    patch: 3,
    build: 4,
    parsed: [1, 2, 3, 4], // is always an array of 4 integers
    isEmpty: false, // = true when 'parsed' = [0, 0, 0, 0]    
    text: '1.2.3.4', // normalized version string
    compare: function(v) // comparison function

Function compare takes either a version string or a pre-parsed object, and returns:

  • 0 - when the versions are the same
  • 1 - when this version is greater / later
  • -1 - when this version is lesser / earlier

Features

All symbols that are not digits or dots are removed before parsing the string.

As a result, a version string like ^1.2alfa.3 0.* becomes 1.2.30.0.

The parser also supports the following syntax:

  • Skipping numbers, i.e. .1..4 = 0.1.0.4
  • An empty string is the same as 0.0.0.0

Passing in a non-string value will throw an error.

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago