You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Christoph Daniel Miksche d4e98a050c
docs: add blog post
4 months ago
.github fix: set degrees of freedom to 0 5 months ago
coverage fix: fistDigit function 5 months ago
dist feat: minify output 5 months ago
src fix: fistDigit function 5 months ago
.drone.yml init 5 months ago
.eslintignore init 5 months ago
.eslintrc.js init 5 months ago
.gitignore init 5 months ago
LICENSE feat: first implementation 5 months ago docs: add blog post 4 months ago
commitlint.config.js init 5 months ago
jest.config.js init 5 months ago
package.json feat: publish new version 5 months ago
tsconfig.json fix: ignore zero 5 months ago


Build Status npm version npm Coverage Branches Coverage Lines Coverage Functions Coverage Statements

Check if a number array confirms to the Benford's Law

Heavily inspired by


npm i benfordslaw


Look at the tests for good examples.


import { BenfordsLaw } from 'benfordslaw';

const numbers = [1,2,3,4,5,6,7,8,9];
const benfords = new BenfordsLaw(numbers);

const chiSquared = benfords.getChiSquared();
// chiSquared = 0.40105320411553363
const probability = benfords.getProbability()?.toFixed(1);
// probability = 1.0

The ChiSquared result is a float and describes how well Benford's Law was matched. Lower is better.

The Probability describes how relevant ChiSquared is. It should be >= 0.9

getDist() returns the distribution of the numbers.

Why TypeScript

With Types TypeScript adds a extra layer of security. I also use mainly TypeScript projects with this project so TypeScript just makes sense. And TS also compiles to JavaScript Code so JS projects also can use it.

General Information

License: MIT

Author: Christoph Daniel Miksche

See also