@putout/plugin-math
🐊Putout plugin helps with Math
Last updated 2 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-math 
SYNC missed versions from official npm registry.

@putout/plugin-math NPM version

🐊Putout plugin helps with Math.

Install

npm i @putout/plugin-math -D

Rules

{
    "rules": {
        "math/apply-exponentiation": "on",
        "math/apply-multiplication": "on",
        "math/apply-numeric-separators": "on",
        "math/convert-sqrt-to-hypot": "on",
        "math/declare": "on"
    }
}

convert-sqrt-to-hypot

The Math.hypot() function returns the square root of the sum of squares of its arguments.

(c) MDN

Convert Math.sqrt() to Math.hypot(). Check out in 🐊Putout Editor.

❌ Example of incorrect code

Math.sqrt(a ** 2, b ** 2);

βœ… Example of correct code

Math.hypot(a, b);

apply-exponentiation

  • The Math.pow() static method, given two arguments, base and exponent, returns baseexponent.
  • The exponentiation operator (**) returns the result of raising the first operand to the power of the second operand. It is equivalent to Math.pow, except it also accepts BigInts as operands.

(c) MDN

❌ Example of incorrect code

Math.pow(2, 4);

βœ… Example of correct code

2 ** 4;

Comparison

Linter Rule Fix
🐊 Putout convert-math-pow βœ…
⏣ ESLint prefer-exponentiation-operator βœ…

apply-multiplication

Multiplying two numbers stored internally as integers (which is only possible with AsmJS with imul is the only potential circumstance where Math.imul() may prove performant in current browsers.

(c) MDN

Check out in 🐊Putout Editor.

❌ Example of incorrect code

const a = Math.imul(b, c);

βœ… Example of correct code

const a = b * c;

apply-numeric-separators

To improve readability for numeric literals, underscores (_) can be used as separators.

(c) MDN

❌ Example of incorrect code

const t = 10000000;

βœ… Example of correct code

const t = 10_000_000;

declare

The Math.round() static method returns the value of a number rounded to the nearest integer.

(c) MDN

❌ Example of incorrect code

round(bLength / aLength) > 3;

βœ… Example of correct code

const {round} = Math;
round(bLength / aLength) > 3;

License

MIT

Current Tags

  • 2.1.0                                ...           latest (2 years ago)

6 Versions

  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (9)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE