@redtea/semint
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Semint

Semint is a small lib to encode/decode SemVer to/from integer.

Install

$ npm install -S @redtea/semint

Usage

// lib also support umd
import {encode, decode, isValid} from 'semint'; 

// first argument is semver in string representation and second argument is max decimals numbers to encode one part of semver
encode('1.1.1', 1); // 1 1 1
encode('1.1.1', 2); // 1 01 01
encode('1.1.1', 3); // 1 001 001
encode('999.999.999', 3); // 999 999 999

// first argument is semver in number representation and second argument is the same as for `encode`
decode(999999999, 3); // '999.999.999'

// `encode` and `decode` function use `isValid` to validate input and throw error if it is not valid
isValid(999999999, 3); // true
isValid(999999999, 1); // false
isValid('999.999.999', 3); // true
isValid('999.999.999', 1); // false
isValid('999.999.999-1', 3); // false
isValid('999.999.', 3); // false

Readme

Keywords

none

Package Sidebar

Install

npm i @redtea/semint

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

5.9 kB

Total Files

6

Last publish

Collaborators

  • hokid