New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prototype-helper

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prototype-helper

Import the package to the first file you call.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50
increased by233.33%
Maintainers
1
Weekly downloads
 
Created
Source

code style: prettier code style: prettier code style: prettier npm

Adds a convenient prototype function package.

Getting started

Import the package to the first file you call.

import "prototype-helper";

// and use
console.log("10000".toComma()); // 10,000

Prototype Helper

Number

toComma()

It is a function that attaches a three-digit comma.

let test = 123;
test.toComma(); // "123"
test = 123456;
test.toComma(); // "123,456"
//

ampersand()

Ampsand that safely handles floating point errors.

console.log(35 % 0.8); // 0.5999999999999981
console.log((35).ampersand(0.8)); // 0.6

console.log(39225.3 % 0.01); // 2.0938424605265737e-12
console.log((39225.3).ampersand(0.01)); // 0

safeAdd()

Addition to safely handling floating point errors.

Calculate only up to 15 decimal places.

console.log(0.1 + 0.2); // 0.30000000000000004
console.log((0.1).safeAdd(0.2)); // 0.3

safeSubtract()

Subtraction that safely handles floating point errors.

Calculate only up to 15 decimal places.

console.log(0.1 - 0.3); // -0.19999999999999998
console.log((0.1).safeSubtract(0.3)); // 0.2

safeDivision()

Division that safely handles floating point errors.

Calculate only up to 15 decimal places.

console.log(0.2 / 0.6); // 0.33333333333333337
console.log((0.2).safeDivision(0.6)); // 0.3333333333333333

safeMultiply()

Division that safely handles floating point errors.

Calculate only up to 15 decimal places.

console.log(0.1 * 0.2); // 0.020000000000000004
console.log((0.1).safeMultiply(0.2)); // 0.02

fixNumber()

Fix the number of digits to be marked.

console.log("30222.50380000".fixPoint(5)); // 30222.50380
console.log((30222).fixPoint(3)); // 30222.000
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000

fixPoint()

Fix the decimal place to be marked.

console.log("30222.50380000".fixPoint(5)); // 30222.50380
console.log((30222).fixPoint(3)); // 30222.000
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000

String

toComma()

It is a function that attaches a three-digit comma.

let test = "123";
test.toComma(); // "123"
test = "123456";
test.toComma(); // "123,456"
//

fixNumber()

Fix the number of digits to be marked.

console.log("30222".fixPoint(5)); // 30222
console.log("30222".fixPoint(5)); // 30222

fixPoint()

Fix the decimal place to be marked.

console.log("30222.50380000".fixPoint(5)); // 30222.50380
console.log((30222).fixPoint(3)); // 30222.000
console.log((30222.12).fixPoint(5).toComma()); // 30,222.12000
console.log("30222.50380000".fixPoint(8).fixNumber(8)); // 00030222.50380000

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)); //112.535
console.log(Math.floor10(112.5345, 3)); //112.534
console.log(Math.ceil10(112.5345, 3)); //112.535

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)); //135.1
console.log(Math.randomRange(0, 200)); //169

clamp(input: number, min: number, max: number)

console.log(Math.clamp(10, 3, 5)); // 5
console.log(Math.clamp(1, 3, 5)); // 3
console.log(Math.clamp(4, 3, 5)); // 4

Keywords

FAQs

Package last updated on 07 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc