New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bignum/template

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bignum/template

Write formulas with template literals.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-82.86%
Maintainers
1
Weekly downloads
 
Created
Source

@bignum/template

Write formulas with template literals.

🚀 Features

  • You can write formulas with template literals.
    (f`0.3 - 0.1` is easier to read than a statement like new Big(0.3).minus(0.1).)
  • Returns exact calculation results using arbitrary-precision arithmetic with BigInt.
    (Similar to big.js.)
  • The calculation engine is customizable.

💿 Installation

npm install @bignum/template

📖 Usage

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

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

// Perform exact calculations using the arbitrary-precision arithmetic with BigInt.
console.log(f`${0.2} + ${0.1}`); // 0.3
console.log(0.2 + 0.1); // 0.30000000000000004

🧮 API

setupEngine([context]): BTEngine

Returns the calculation engine.

  • context: An object for customizing calculations.
    By default, calculations are performed using BigNum.
setupEngine context

TBA

BTEngine

Perform calculations using template literals.

Example:

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

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

The calculation result usually returns a number, but if the number loses precision when converted to a string, it returns a string with the original precision is returned.

🛸 Prior Art

  • bigjs-literal
    This package is similar to bigjs-literal in that it uses template literals for calculations, but bigjs-literal has a 49kB file for the parser alone.
    The JavaScript file for the compiler that @bignum/template has is 8kB (without minify). (However, there is no ability to compile it in advance.)

Keywords

FAQs

Package last updated on 16 May 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc