Socket
Book a DemoInstallSign in
Socket

@bignum/template-light

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bignum/template-light

Write formulas with template literals.

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
16
45.45%
Maintainers
1
Weekly downloads
 
Created
Source

@bignum/template-light

Write formulas with template literals. (light version)

This is the light version of @bignum/template. It has significantly more limited functionality than @bignum/template, but is much smaller.

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

🚀 Features

  • You can write formulas with template literals.
    (f`${0.3} - ${0.1}` is easier to read than a statement like new MyNum(0.3).minus(0.1).)
  • Prevent rounding errors by calculating with rational numbers using BigInt.
  • There are no dependencies and can be minified to 2.3 KB (Minified and gzipped: 1.1 KB) .
  • You can pre-compiled using @bignum/babel-plugin ( Library size can be reduced to 1.1 KB (Minified and gzipped: 0.6 KB) ).

Note that although no rounding is performed during calculations, the calculation results are returned to Number, so values that cannot be held by Number may be rounded.

If you want more operations and more rounding avoidance, consider using @bignum/template.

💿 Installation

npm install @bignum/template-light

📖 Usage

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

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

// Prevent rounding errors by calculating with rational numbers using BigInt.
console.log(f`${0.2} + ${0.1}`); // 0.3
console.log(0.2 + 0.1); // 0.30000000000000004

🧮 API

f

Perform calculations using template literals.

Example:

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

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

📝 Supported Syntax

Operators

The following operators are supported:

/* Arithmetic Operators */
// add
f`${0.1} + ${0.2}`; // 0.3
// subtract
f`${0.3} - ${0.1}`; // 0.2
// multiply
f`${0.07} * ${100}`; // 7
// divide
f`${0.6} / ${0.2}`; // 3
// modulo
f`${0.6} % ${0.2}`; // 0

/* Parentheses */
f`(${0.1} + ${0.2}) * ${10}`; // 3
f`${0.1} + ${0.2} * ${10}`; // 2.1

Operand

Substitutions in the template literal are considered operands.

f`${0.2} + ${0.1}`; // 0.3

Keywords

bignum

FAQs

Package last updated on 02 Feb 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.