Dollar String
Helper utilities for dealing with dollar strings.
Getting started
npm install dollar-string
var dollarString = require('dollar-string');
Usage
dollarString.valid(value)
console.log(dollarString.valid("$1.00"));
console.log(dollarString.valid("$2.53"));
console.log(dollarString.valid("$10.2"));
console.log(dollarString.valid("$5"));
console.log(dollarString.valid("1.00"));
console.log(dollarString.valid("$1.004"));
console.log(dollarString.valid("$1.00c"));
console.log(dollarString.valid("$1.a0"));
dollarString.toCents(value)
console.log(dollarString.toCents("$1.00"));
console.log(dollarString.toCents('$2.22'));
console.log(dollarString.toCents('$1.50'));
dollarString.toDollars(value)
console.log(dollarString.toDollars("$1.00"));
console.log(dollarString.toDollars('$2.22'));
console.log(dollarString.toDollars('$1.50'));
dollarString.fromCents(value)
console.log(dollarString.fromCents(100));
console.log(dollarString.fromCents(222));
console.log(dollarString.fromCents(150));
dollarString.fromDollars(value)
console.log(dollarString.fromDollars(1));
console.log(dollarString.fromDollars(2.22));
console.log(dollarString.fromDollars(1.5));
dollarString.compare(val1, val2)
returns
- -1 if val1 is smaller than val2
- 0 if both values are equal
- 1 if val1 is greater than val2
console.log(dollarString.compare("$1.00", "$2.00"));
console.log(dollarString.compare("$10.00", "$10"));
console.log(dollarString.compare("$2.00" , "$1.00"));
dollarString.multipleOf(val1, val2)
returns
- true if val1 is a multiple of val2
- false otherwise
console.log(dollarString.multipleOf("$2.00", "$1.25"));
console.log(dollarString.multipleOf("$10.00", "$1"));