0.0.2 • Published 3 years ago

@yukinotech/babel-plugin-transform-jsbd-to-bigdecimal v0.0.2

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

babel-plugin-transform-jsbd-to-bigdecimal

A scheme similar to JSBI, for transforming JSBD to native bigdecimal, Referring to the implementation of jsbi (https://github.com/GoogleChromeLabs/babel-plugin-transform-jsbi-to-bigint)

how to use

use as a babel plugin @yukinotech/babel-plugin-transform-jsbd-to-bigdecimal

const result = require('@babel/core').transform(code, {
  plugins: ['@yukinotech/babel-plugin-transform-jsbd-to-bigdecimal'],
  comments: false,
})

how it work

it will replace indetitor JSBD to native bigdecimal syntax

Operationnative BigDecimalsJSBD
Additionc = a + bc = JSBD.add(a, b)
Subtractionc = a - bc = JSBD.subtract(a, b)
Multiplicationc = a * bc = JSBD.multiply(a, b)
Division with two argumentsc = a / bc = JSBD.divide(a, b)
Remainderc = a % bc = JSBD.remainder(a, b)
Exponentiationc = a ** bc = JSBD.pow(a, b)
Comparison to other BigIntsa === bJSBD.equal(a, b)
a !== bJSBD.notEqual(a, b)
a < bJSBD.lessThan(a, b)
a <= bJSBD.lessThanOrEqual(a, b)
a > bJSBD.greaterThan(a, b)
a >= bJSBD.greaterThanOrEqual(a, b)
c = BigDecimal.round(a,option)c = JSBD.round(a, option)
Division with three argumentsc = BigDecimal.divide(a,b,roundOption)c = JSBD.divide(a, b,roundOption)

differences from bigint to bigdecimal

since bigdecimal has a roundOption, we can't just transform JSBI.add(one,two) to one + two,if there are three arguments we just transform JSBD.add(one,two,option) to Decimal.add(one,two,option)