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

crumbsplit

v0.1.0

Published

Split integer units and decimal amounts exactly using largest remainders.

Readme

crumbsplit

Split integer units and decimal amounts exactly using largest remainders.

Node.js 22+. No runtime dependencies. CommonJS, ES modules and TypeScript declarations. MIT licensed. This is the JavaScript edition; no Python installation is needed.

Install

npm install crumbsplit

JavaScript

import { allocate, splitAmount } from 'crumbsplit';
console.assert(JSON.stringify(splitAmount('100.00', [1, 1, 1])) ===
  JSON.stringify(['33.34', '33.33', '33.33']));
console.assert(JSON.stringify(allocate(10, [1, 2, 3])) === '[2,3,5]');
console.assert(allocate(9007199254740993n, [1])[0] === 9007199254740993n);

CommonJS is also supported: const api = require('crumbsplit');. ES modules support both named exports and a default API object.

Command line

npx crumbsplit 100.00 --parts 3
npx crumbsplit 10 --integer --weights 1 2 3
npx crumbsplit 0.02 --parts 3 --offset 1

Use --help for usage and --version for the package version. You can install globally with npm install -g crumbsplit to run the command directly.

API and behavior

allocate(total, weights, {offset = 0}) distributes non-negative integer units by Hamilton's largest-remainder method, preserving the exact total. A safe integer number total returns number[]; a bigint total returns bigint[]. Weights are non-negative numbers, bigint values, or decimal/fraction strings. At least one weight must be positive. Zero weights receive zero.

splitAmount(amount, weights, {places = 2, offset = 0}) returns fixed-precision decimal strings, never floating-point amounts. Precision is 0 through 18 places. An amount with excess precision is rejected, not rounded. Ties follow input order starting at offset and wrapping around (negative offsets are supported).

Use decimal strings for money and bigint for large integer totals. Unsafe number integers, booleans, negative values and non-finite numbers are rejected. A number argument may already contain floating-point rounding before reaching this API. No currency conversion is performed.

CLI output always uses JSON strings, including --integer, so large values can be read without precision loss. Use exactly one of --parts N or --weights W...; put AMOUNT before options. Exit codes: 0 success, 2 invalid input.

Development

In the source checkout, run npm test. Tests use Node's built-in test runner; there are no test framework dependencies. npm pack builds the publishable tarball. Tests and local state are excluded from the tarball.