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

@rawbytes/hissab

v1.3.0

Published

Strict, unit-aware natural-language calculation engine for TypeScript apps and AI agent tools

Readme

@rawbytes/hissab

Hissab's TypeScript calculation engine. It lexes natural-language-ish math expressions, parses them, and returns formatted results with token metadata. The user-facing syntax reference lives in ../lib/documentation.

Install

npm install @rawbytes/hissab

Quick Start

import { calculate } from "@rawbytes/hissab";

const result = await calculate("15 kilometers to miles");

console.log(result.result); // "9.3206 miles"
console.log(result.resultToken); // parsed result token

Supported expression families include arithmetic, percentages, unit conversion, compound units, sets/combinatorics, number theory, logarithms, statistics, probability, finance, health and fitness, trigonometry, geometry, dates/times, number systems, bitwise operations, colors, IP addresses, symbolic algebra, complex numbers, coordinate systems, matrices, visualization (draw/plot), random numbers / UUIDs / nanoids (random, uuid, nanoid), and text hashing (md5, sha256, crc32, …).

Advanced Usage

Use doLex and doParse separately when you need to inspect tokens or manage variables between multiple expressions.

import {
  doLex,
  doParse,
  type Variables,
} from "@rawbytes/hissab";

const variables: Variables = {};

const assignment = await doParse(doLex("distance = 15 km", variables, 1));
variables[assignment.meta.variableName] = assignment.resultToken;

const converted = await doParse(doLex("distance to miles", variables, 2));
console.log(converted.result);

API

calculate(line, options?)

Runs lexing and parsing in one call.

type CalculateOptions = {
  variables?: Variables;
  lineNumber?: number;
};

Returns:

type ParseResult = {
  result: string;
  resultToken: TokenType;
  meta: {
    variableName: string;
  };
};

doLex(line, variables?, lineNumber?)

Converts an expression string into TokenType[].

doParse(tokens)

Parses and evaluates tokens returned by doLex.

Symbolic helpers

Symbolic and complex expressions evaluate through the same calculate, doLex, and doParse APIs. The root export also exposes exprToLatex and the symbolic token classes for consumers that need structured rendering.

import { calculate, exprToLatex } from "@rawbytes/hissab";

const derivative = await calculate("derivative(2x^2, x)");
console.log(derivative.result); // "4x"

const product = await calculate("(2 + 3i) * (1 - i)");
console.log(product.result); // "5 + i"

if ("expr" in derivative.resultToken) {
  console.log(exprToLatex(derivative.resultToken.expr));
}

Errors

Invalid expressions throw UserError.

import { calculate, UserError } from "@rawbytes/hissab";

try {
  await calculate("10 meter to kilogram");
} catch (error) {
  if (error instanceof UserError) {
    console.error(error.message);
  }
}

Exports

The public root export includes:

  • calculate
  • doLex
  • doParse
  • UserError
  • DateTimeOperands
  • ComplexToken
  • ExprToken
  • SymbolToken
  • PointToken
  • MatrixToken
  • PlotToken
  • exprToLatex
  • evalExpr
  • freeSymbols
  • TokenBaseType
  • tokenFactory
  • Functions
  • Operators
  • Units
  • Types: CalculateOptions, ParseResult, parseResultIf, TokenType, Variables, Expr, PlotSeries