npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pinkchen/calc

v1.0.9

Published

The ultimate solution for precise front-end calculations, featuring accurate computation, lightweight design, convenience, maintainable calculation formulas, integrated decimal.js mathematical functions, and support for custom functions.

Downloads

269

Readme

@pinkchen/calc

The ultimate solution for precise front-end calculations, featuring accurate computation, lightweight design, convenience, maintainable calculation formulas, integrated decimal.js mathematical functions, and support for custom functions.

Advantages

  1. 💪 Supports precise calculations
  2. 🎈 Lightweight with small bundle size
  3. 💼 Convenient, supports es, cjs, umd
  4. 🔢 Integrates decimal.js internal mathematical functions
  5. ⚒️ Supports custom functions to meet all customization needs
  6. 👨🏻‍🔬 Support scientific notation
  7. 🌰 Successfully pass 500 test cases

Documentation

English|中文文档

Installation

npm i @pinkchen/calc -S
// or
yarn add @pinkchen/calc
// or
pnpm add @pinkchen/calc
// or
bun add @pinkchen/calc

Import

  • cjs
const { calc } = require('@pinkchen/calc');
  • es
import { calc } from '@pinkchen/calc';
  • umd
<script src="node_modules/@pinkchen/calc/dist/umd/index.js"></script>
<script>
  window.pinkchen.calc('0.1+0.2'); //0.3
  // Refer to specific usage examples for other usages
</script>

Usage

Basic Calculation

calc('0.1+0.2'); //0.3
calc('22.22*22.22'); //493.7284
calc('(22.22*22.22)'); //493.7284
calc('1 + 2 * (3 - 4 * (5 + 6))'); //-81

Calculation with Data Source

calc('1+22.22/(22.22+a)', { a: 22.22 }); //1.5
calc('a*b', { a: 11, b: 22 }); //242
calc('1+a*b', { a: 11, b: 22 }); //243
calc('aa*bb.bb', { aa: 22, b: 22, bb: { bb: 33 } }); //726
calc('oo.a+oo.b*(oo.c-oo.d.d*(oo.e.e+oo.ff))', {
  oo: { a: 1, b: 2, c: 3, d: { d: 4 }, e: { e: 5 }, ff: 6 }
}); //-81

Calculation with Functions

It integrates static mathematical functions from decimal.js. Refer to decimal.js for available functions.

Built-in functions must be used with the prefix "DC."; for example: DC.max(1, 2)

calc('DC.max(a+b,0.3)', { a: 0.1, b: 0.2 }); //0.3
calc('1+DC.max(a+b,0.3)', { a: 0.1, b: 0.2 }); //1.3
calc('1+DC.abs(-1-a-1)', { a: -1 }); //2

Support custom Function

You can achieve customization by injecting custom functions into the data source.

calc('a+max(getSum(a,b)+1, a+c, a+111/(d*e))', {
  a: 11,
  b: 12,
  c: 133,
  d: 14,
  e: 15,
  getSum: (a, b) => a + b
}); //155
calc('a+getSum(max(a*b, a+b), b)', { a: 1, b: 2, getSum: (a, b) => a + b }); //6
calc('a.a*(b + c + getOne())', { a: { a: 2 }, b: 3, c: 3, getOne: (b) => 1 }); //14

❗❗❗ Note: Whether built-in or custom functions, all parameters will be converted using Decimal, so please handle parameters as numbers inside custom function bodies.

Formatting

calc('2222.22*2222.22', {}, { separator: true }); //4,938,261.7284
calc('2222.22*2222.22', {}, { digit: 6 }); //4938261.728400
calc('2222.22*2222.22', {}, { preUnit: '$ ' }); //$ 4938261.7284
calc('2222.22*2222.22', {}, { postUnit: ' USD' }); //4938261.7284 USD
calc('2222.22*2222.22', {}, { percentage: true }); //493826172.84%
calc('2222.22*2222.22', {}, { permillage: true }); //4938261728.4‰
calc(
  '99.9949999/100',
  {},
  {
    separator: true,
    digit: 2,
    preUnit: 'Your skill level exceeds ',
    postUnit: ' of peers',
    percentage: true
  }
); //Your skill level exceeds 99.99% of peers

Support scientific notation

calc('DC.abs(-1e2,5e1,-2e1)'); //100
calc('9.99e15 * 9.99e15'); //9.98001e31
calc('1e0 / (1e0 + DC.exp((1.5e1 - 1.2e1) / (2.585e-2 * 3e2)))', {}, { digit: 6 }); //0.404477