quantity.js

1.1.3 • Public • Published

Quantity.js

quantity.js provides parser/operations for k8s quantity

It is based on bignumber.js

Load

For Node.js, the library is available from npm registry

$ npm install quantity.js
var quantity = require('quantity.js')

ES6

import * as quantity from "quantity.js"

Use

parse = quantity.parseQuantity
x = parse("100Mi")

parse("0.5Mi").toString() // "512Ki"
parse("1024Ti").toString() // "1Pi"
parse("10241Mi").toString() // "10241Mi"

// add
x.add(parse("50Mi")) // "150Mi"
x.plus(parse("50Mi")) // "150Mi"

// minus
x.minus(parse("50Mi")) // "50Mi"
x.sub(parse("50Mi")) // "50Mi"

// div
x = parse("100")
x.div(parse("50")) // "2"
x.sub(parse("50Mi")) // "50Mi"

// mul
x = parse("2")
x.mul(parse("50")) // "100"
x.times(parse("50")) // "100"

// mod
x = parse("10")
x.mod(parse("3")) // "1"

Build & Test

dev

 yarn run build
 yarn run test

publish

yarn run pub

Readme

Keywords

Package Sidebar

Install

npm i quantity.js

Weekly Downloads

137

Version

1.1.3

License

Apache-2.0

Unpacked Size

37.6 kB

Total Files

11

Last publish

Collaborators

  • zoumo