math.format

1.0.4 • Public • Published

Build Status

Math.format

Method to check values and format numbers.

Usage

Math.format(34.5279, {'round': -2}); // Returns 34.53
Math.format(34.5279, {'round': 0}); // Returns 35
Math.format(34.5279, {'round': 1}); // Returns 30
 
Math.format(34.5279, {'floor': -2}); // Returns 34.52
Math.format(34.5279, {'floor': 0}); // Returns 34
Math.format(34.5279, {'floor': 1}); // Returns 30
 
Math.format(34.5279, {'ceil': -2}); // Returns 34.53
Math.format(34.5279, {'ceil': 0}); // Returns 35
Math.format(34.5279, {'ceil': 1}); // Returns 40
 
Math.format(34.5279, {'min': 40}); // Returns 40
Math.format(34.5279, {'max': 30}); // Returns 30
 
Math.format('a string', {'ifNaN': 'custom value'}); // Returns 'custom value'
Math.format('', {'ifEmpty': 'custom value'}); // Returns 'custom value'
Math.format(undefined, {'ifEmpty': 'custom value'}); // Returns 'custom value'
Math.format(Infinity, {'ifInfinity': 'custom value'}); // Returns 'custom value'
 
Math.format(2, {'preProcess': '(x + 2) * 3'}); // Returns 12
Math.format(2, {'postProcess': '(x + 2) * 3'}); // Returns 12
Math.format(2, {'preProcess': '(x + 2) * 3', 'max': 10}); // Returns 10
Math.format(2, {'postProcess': '(x + 2) * 3', 'max': 10}); // Returns 12
 
Math.format(2, {'prefix': 'hello '}); // Returns 'hello 2'
Math.format(2, {'suffix': ' times'}); // Returns '2 times'
Math.format(2, {'prefix': 'hello ', 'suffix': ' times'}); // Returns 'hello 2 times'

Unit tests

Unit tests are made with Mocha. Just launch npm test to run it.

Contribute

Be careful that I use Git-flow to organize the repository branches, so make your pull requests to the develop branch.

$ npm install
$ npm test
$ npm run watch

Webpack will compile your code in the build directory.

Source

Readme

Keywords

none

Package Sidebar

Install

npm i math.format

Weekly Downloads

0

Version

1.0.4

License

MIT

Last publish

Collaborators

  • guillaumeamat