
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
babel-plugin-transform-decimal
Advanced tools
A plugin for babel to transform `x * y` into something like `JSBD.multiply(x, y)` to support decimals.
NOTICE: This will not work in many cases, so please use bignumber.js or decimal.js directly only if you know, that the code works only with BigDecimals. Since proposal decimal is still in stage-1, it might changed a lot and this transformer many take this breaking changes in the feature.
A plugin for babel to transform x * y
into something like JSBD.multiply(x, y)
to support decimals.
Input using native BigDecimal
s:
const a = BigDecimal(0.1);
const b = 0.2m;
a + b;
a - b;
a * b;
a / b;
a % b;
a ** b;
a === b;
a < b;
a <= b;
a > b;
a >= b;
a.toString();
Compiled output using JSBD
:
const a = JSBD.BigDecimal(0.1);
const b = JSBD.BigDecimal(0.2);
JSBD.add(a, b);
JSBD.subtract(a, b);
JSBD.multiply(a, b);
JSBD.divide(a, b);
JSBD.remainder(a, b);
JSBD.pow(a, b);
JSBD.equal(a, b);
JSBD.lessThan(a, b);
JSBD.lessThanOrEqual(a, b);
JSBD.greaterThan(a, b);
JSBD.greaterThanOrEqual(a, b);
a.toString();
¡ It is buggy !
BigDecimal.round(1m)
;Number(0.1m)
;<<
and >>
;&
/ |
/ ^
;Published under ISC License.
FAQs
A plugin for babel to transform `x * y` into something like `JSBD.multiply(x, y)` to support decimals.
We found that babel-plugin-transform-decimal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.