Adds a convenient prototype function package.
Getting started
Import the package to the first file you call.
import "prototype-helper";
console.log("10000".toComma());
Prototype Helper
Number
toComma()
It is a function that attaches a three-digit comma.
let test = 123;
test.toComma();
test = 123456;
test.toComma();
mod()
Ampsand that safely handles floating point errors.
console.log(35 % 0.8);
console.log((35).mod(0.8));
console.log(39225.3 % 0.01);
console.log((39225.3).mod(0.01));
add()
Addition to safely handling floating point errors.
Calculate only up to 15 decimal places.
console.log(0.1 + 0.2);
console.log((0.1).add(0.2));
sub()
Subtraction that safely handles floating point errors.
Calculate only up to 15 decimal places.
console.log(0.1 - 0.3);
console.log((0.1).sub(0.3));
div()
Division that safely handles floating point errors.
Calculate only up to 15 decimal places.
console.log(0.2 / 0.6);
console.log((0.2).div(0.6));
mul()
Division that safely handles floating point errors.
Calculate only up to 15 decimal places.
console.log(0.1 * 0.2);
console.log((0.1).mul(0.2));
fixNumber()
Fix the number of digits to be marked.
console.log("3022.50380000".fixNumber(5));
console.log((3022).fixNumber(7));
console.log((3222.12).fixNumber(5).toComma());
fixPoint()
Fix the decimal place to be marked.
console.log("30222.50380000".fixPoint(5));
console.log((30222).fixPoint(3));
console.log((30222.12).fixPoint(5).toComma());
String
toComma()
It is a function that attaches a three-digit comma.
let test = "123";
test.toComma();
test = "123456";
test.toComma();
fixNumber()
Fix the number of digits to be marked.
console.log("3022.50380000".fixNumber(5));
console.log((3022).fixNumber(7));
console.log((3222.12).fixNumber(5).toComma());
fixPoint()
Fix the decimal place to be marked.
console.log("30222.50380000".fixPoint(5));
console.log((30222).fixPoint(3));
console.log((30222.12).fixPoint(5).toComma());
Object
Array
Extention Helper
Math
round10(x: number, point?: number)
floor10(x: number, point?: number)
ceil10(x: number, point?: number)
A function that allows you to use decimal points for discarding/rounding/round.
I used the code of the MDN below.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil#decimal_adjustment
console.log(Math.round10(112.5345, 3));
console.log(Math.floor10(112.5345, 3));
console.log(Math.ceil10(112.5345, 3));
randomRange(a: number, b: number, point?: number)
Create random numbers within that range.
(Includes maximum and minimum values.)
console.log(Math.randomRange(112.5, 200, 1));
console.log(Math.randomRange(0, 200));
clamp(input: number, min: number, max: number)
console.log(Math.clamp(10, 3, 5));
console.log(Math.clamp(1, 3, 5));
console.log(Math.clamp(4, 3, 5));