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

@bortunac/matx

v1.0.3

Published

Precision-safe math utilities and nested object access for JavaScript.

Readme

Matx

Matx is a precision-safe math utility toolkit with deep object path support, ideal for financial and data aggregation tasks. It enhances JavaScript's native Math with precision-aware operations and introduces two object prototype extensions: .pointer() for safe nested access and .scan() for enumerable iteration.

🚀 Installation

npm install matx

📦 Usage

In ES6 module:

import 'matx';

const result = Math.sum(1.1, 2.22); // 3.32

In Browser:

Include the bundled script and use window.Matx:

<script src="matx.js" type="module"></script>
or
await import("/path/matx.js");
Math.acm(...)

🔧 Features

🔹 Math Methods

  • Math.sum(...values) – Accumulates with precision.
  • Math.diff(a, b) – Subtracts with precision.
  • Math.acm(acmObj, srcObj, keys) – Accumulate fields from srcObj into acmObj.
  • Math.acms(...) – Subtract version of acm.
  • Math.acmd(...) – Divide version of acm.
  • Math.float0(x) – Safe float parse.
  • Math.bytes(x) – Converts bytes into human-readable units.
  • Math.precision(x, p, type) – Applies fixed-point rounding.
  • Math.get_precision(x) – Finds decimal precision of a number.

🔸 Object Extensions

.pointer(path[, value])

Access or set deeply nested properties safely.

const obj = {};
obj.pointer("a.b.c", 42);
console.log(obj); // { a: { b: { c: 42 } } }

.scan(callback)

Iterates key-value pairs like Array.prototype.map.

const o = { a: 10, b: 20 };
const keys = o.scan((k, v, i) => `${k}:${v}`);
console.log(keys); // ["a:10", "b:20"]

Array.prototype.having()

This utility adds advanced filtering to arrays:

const COL = [
  { a: 1, b: 2 },
  { a: 2, b: 1 },
  { a: 3, b: 1 },
  { a: 4, b: 5 },
  { a: 5, b: 5 },
  { a: 1, c: { d: 1, e: ["alfa"] } },
  { c: { d: 1, e: ["alfa", "beta"] } }
];

// Filter with object criteria
console.log(COL.having({ b: 5, a: 4 }, { a: [2, 3] }));

// Filter with JS condition expression
console.log(COL.having("${b} > 1 && ${a} > 4"));

// Filter with regex logic
console.log(COL.having("/^5/.test('${b}')"));

// Deep search using $@ pointer notation
console.log(COL.having("[email protected][1] !== undefined || [email protected] > 2"));

Examples

Object .scan() with .pointer Chaining

const dataset = {
  101: { user: { id: 101, name: "Alice", scores: { math: 82 } } },
  102: { user: { id: 102, name: "Bob", scores: { math: 91 } } },
  103: { user: { id: 103, name: "Charlie", scores: { math: 75 } } }
};

const result = dataset.scan(function (key, value) {
  const name = value.pointer("user.name");
  const mathScore = value.pointer("user.scores.math");
  return `User ${name} scored ${mathScore} in math.`;
});

console.log(result);
// [
//   "User Alice scored 82 in math.",
//   "User Bob scored 91 in math.",
//   "User Charlie scored 75 in math."
// ]

Math.acm Aggregation Example

const acm = { total: 0 };
const items = [
  { total: 10 },
  { total: 25 },
  { total: 5 }
];

Math.acm(acm, items, "total");
console.log(acm); // { total: 40 }

Math.acm with Nested Keys Example

const acm = {};
const records = [
  {
    year_month: "2024-01",
    sales: { online: 100, retail: 200 },
    refunds: { online: 3, retail: 4 }
  },
  {
    year_month: "2024-02",
    sales: { online: 150, retail: 100 },
    refunds: { online: 2, retail: 5 }
  }
];

Math.acm(acm, records, [
  "sales.online",
  "sales.retail",
  "refunds.online",
  "refunds.retail"
]);

console.log(acm);
// {
//   sales: { online: 250, retail: 300 },
//   refunds: { online: 5, retail: 9 }
// }

🔍🧠 Why Matx?

  • Zero-dependency
  • Precision-safe
  • Works with deeply nested objects
  • Friendly to financial, scientific, or statistical data models

📄 License

MIT