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

@revisium/formula

v0.7.0

Published

Formula expression parser and evaluator for Revisium

Readme

@revisium/formula

Quality Gate Status Coverage GitHub License GitHub Release

Formula expression parser and evaluator for Revisium.

SpecificationAPI Reference

Installation

npm install @revisium/formula

Usage

import { parseExpression, evaluate } from '@revisium/formula';

// Simple arithmetic
parseExpression('price * 1.1');
// { minVersion: "1.0", features: [], dependencies: ["price"] }
evaluate('price * 1.1', { price: 100 });
// 110

// Nested object paths
parseExpression('stats.damage * multiplier');
// { minVersion: "1.1", features: ["nested_path"], dependencies: ["stats.damage", "multiplier"] }
evaluate('stats.damage * multiplier', { stats: { damage: 50 }, multiplier: 2 });
// 100

// Array index access
parseExpression('items[0].price + items[1].price');
// { minVersion: "1.1", features: ["array_index", "nested_path"], dependencies: ["items[0].price", "items[1].price"] }
evaluate('items[0].price + items[1].price', { items: [{ price: 10 }, { price: 20 }] });
// 30

// Comparisons
evaluate('price > 100', { price: 150 });
// true

// Fields named like functions
evaluate('max(max, 0)', { max: 10 });
// 10 (max() function is called with field "max" as argument)

evaluate('max(max - field.min, 0)', { max: 100, field: { min: 20 } });
// 80

// Type inference
import { inferFormulaType } from '@revisium/formula';

inferFormulaType('price * quantity', { price: 'number', quantity: 'number' });
// 'number'

inferFormulaType('price > 100');
// 'boolean'

// Array item formulas with path resolution
import { evaluateWithContext } from '@revisium/formula';

// Absolute path: /field always resolves from root data
evaluateWithContext('price * (1 + /taxRate)', {
  rootData: { taxRate: 0.1, items: [{ price: 100 }] },
  itemData: { price: 100 },
  currentPath: 'items[0]'
});
// 110

// Relative path: ../field resolves from parent (root)
evaluateWithContext('price * (1 - ../discount)', {
  rootData: { discount: 0.2, items: [] },
  itemData: { price: 100 },
  currentPath: 'items[0]'
});
// 80

API

Parser API

| Function | Description | |----------|-------------| | parseFormula | Low-level parser returning AST, dependencies, features | | validateSyntax | Validate expression syntax | | evaluate | Evaluate expression with context | | evaluateWithContext | Evaluate with automatic / and ../ path resolution | | inferFormulaType | Infer return type of expression |

Expression API

| Function | Description | |----------|-------------| | parseExpression | Parse expression, extract dependencies and version | | validateFormulaSyntax | Validate formula expression syntax |

Graph API

| Function | Description | |----------|-------------| | buildDependencyGraph | Build dependency graph from Record<string, string[]> | | detectCircularDependencies | Detect circular dependencies in graph | | getTopologicalOrder | Get evaluation order for nodes |

Path Syntax

| Syntax | Description | Example | |--------|-------------|---------| | field | Top-level field | baseDamage | | obj.field | Nested object | stats.damage | | arr[N] | Array index | items[0].price | | arr[-1] | Last element | items[-1] | | /field | Absolute path (from root) | /taxRate, /config.tax | | ../field | Relative path (parent scope) | ../discount, ../settings.multiplier |

Version Detection

| Feature | Min Version | |---------|-------------| | Simple refs (field) | 1.0 | | Function-named fields | 1.0 | | Nested paths (a.b) | 1.1 | | Array index ([0], [-1]) | 1.1 | | Absolute paths (/field) | 1.1 | | Relative paths (../field) | 1.1 |

License

MIT