Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
/ math.format Public archive

Function to check numbers format, do some modifications, fix minimum and maximum values, etc.

License

Notifications You must be signed in to change notification settings

GuillaumeAmat/math.format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Function to check numbers format, do some modifications, fix minimum and maximum values, etc.

Resources

License

Stars

Watchers

Forks

Packages

No packages published