0.1.3 • Published 4 years ago

sscs-6000 v0.1.3

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

Super Speedy Cider Squeezer 6000 🍺

"Super Speedy Cider Squeezer 6000" (shortcut SSCS-6000) is a lightweight and fast number formatter for js.

npm version

Feel free to suggest and PR new features.

Install:

npm i sscs-6000

Usage:

  import sscs from 'sscs-6000'
  
  console.log(sscs(0.007123, { error: '-' }).toFirstNumberFixed().valueOf());
  // '0.007'

Available features:

Be careful! Some functions convert number to string, use them last before valueOf(). These functions will be marked with '❗'.

FunctionDescriptionExample
toFixed([digit])This function formats a number using fixed-point notation. Implemetanion of Number.prototype.toFixed()sscs(1.6785323).toFixed(2).valueOf() would be 1.67
custom([callback])This function provides you custom callback (value) => value. So, you can do anything you want with value.sscs(1).custom(val => val + 1).valueOf() would be 2
round()This function returns the value of a number rounded to the nearest integer. Implemetanion of Math.round()sscs(1.6785323).round().valueOf() would be 2
toFirstNumberFixed()This function formats a number to the first significant decimal place.sscs(1.000323).toFirstNumberFixed().valueOf() would be 1.0003
toAnyFloat()This function returns a number with zero fractional part.sscs(34).toAnyFloat().valueOf() would be '34.0'
separate()This function divides the number by spaces by digits.sscs(130000000).separate().valueOf() would be '130 000 000'
replaceDots()This function replace dot in float with сommasscs(13.23).replaceDots().valueOf() would be '13,23'
valueOf()This last function which you should call to get your value.sscs(13.23).valueOf() would be 13.23

Config

Config object is a second parameter in main function.

KeyDefaultDescription
error'-'This returns if no value or value is NaN
checkError!value || isNaN(value) || value === Number.MIN_VALUEFunction to check is value correct.

Examples

  import sscs from 'sscs-6000'
  
  console.log(sscs(0.007123, { error: '-' }).toFirstNumberFixed().valueOf());
  // '0.007'
  
  console.log(sscs(undefined, { error: '-' }).valueOf());
  // '-'
  
  console.log(sscs(123900.00432, { error: '-' }).toFixed(4).toFirstNumberFixed().replaceDots().separate().valueOf());
  // '123 900,004'
0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago