Socket
Socket
Sign inDemoInstall

babel-plugin-transform-bigdecimal

Package Overview
Dependencies
56
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-bigdecimal

A plugin for babel to transform `x * y` into something like `JSBD.multiply(x, y)` to support bigdecimals.


Version published
Maintainers
1
Created

Readme

Source

babel-plugin-transform-bigdecimal

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 bigdecimals.

Example

Input using native BigDecimals:

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();

Playground

  1. Open https://babeljs.io/en/repl
  2. Turn off all presets.
  3. "Add plugin" @babel/babel-plugin-syntax-decimal
  4. "Add plugin" babel-plugin-transform-bigdecimal

¡ It is buggy !

TODO(s)

  • support BigDecimal.round(1m);
  • support Number(0.1m);
  • support shift operators << and >>;
  • support bitwise operators like & / | / ^;

License

Published under ISC License.

Keywords

FAQs

Last updated on 23 Dec 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc