2.1.0 • Published 9 months ago

@bignum/babel-plugin v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@bignum/babel-plugin

Babel plugin to replace tagged template literals with BigNum JS expressions.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads

🚀 Features

💿 Installation

npm install -D @bignum/babel-plugin
npm install @bignum/template
# or
npm install @bignum/template-light

📖 Usage

Configuration

Include @bignum/babel-plugin in your Babel configuration.

{
  "plugins": ["@bignum/babel-plugin"]
}

Writing Code

Use @bignum/template.f to write the calculation formula.

import { f } from "@bignum/template";

const num = 0.1;
const result = f`${num} + 0.1 * 2`;
console.log(result); // 0.3
console.log(f`${0.2} + ${0.1}`); // 0.3

Output:

import { multiply, add, toResult } from "@bignum/template/core";
const num = 0.1;
const result = toResult(add(num, multiply("0.1", 2)));
console.log(result); // 0.3
console.log(toResult(add(0.2, 0.1))); // 0.3

Or use @bignum/template-light.f to write the calculation formula.

import { f } from "@bignum/template-light";

console.log(f`${0.2} + ${0.1}`); // 0.3

Output:

import { add, execCompiled } from "@bignum/template-light/core";

console.log(execCompiled([0.2, 0.1], (args) => add(args[0], args[1]))); // 0.3

🛸 Prior Art

  • bigjs-literal\ This package is similar to bigjs-literal in that it uses template literals for calculations, but is more lightweight.