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

dndmatrix

v2.0.0

Published

Roll up a D&D stat roll matrix

Readme

dndmatrix

My friend and co-worker had a peculiar way of generating stat rolls for D&D. He and his friends always rolled 4d6 (drop lowest) 36 times to construct a 6x6 matrix of rolls. Then they could pick one column or one roll to use as their stats array.

This seemed like a fun challenge to stretch my functional programming skills.

Usage

This module should be able to be installed via npm. If installed globally, you run the command dndmatrix to output a D&D stat matrix in a Github Flavored Markdown table.

dndmatrix can also be installed directly to a project and used as a module:

const dnd = require('dndmatrix')

Running the Test Suite

If you've installed the developer dependencies, you should be able to run npm test. Both standard and tape are used for the test suite.

Provided Functions

fillArray(n)(fn)

Returns an array with n elements that are the results of function fn. This function is curried to allow partial application of arguments.

rollDie(max, randomFn = Math.random)

Returns a random integer between 1 and max. By default, the library uses Math.random, but you can inject any preferred random number function.

rollD6()

Returns a random integer between 1 and 6 (1d6).

generateRolls(rollFn = rollD6)

Returns an array with four random numbers between 1 and 6 (4d6).

By default, the function uses rollD6 to generate rolls. While this is mainly to allow for unit testing, you could also choose to inject the die roll of your choice here.

sortRolls(arr)

Returns a sorted array based on arr in ascending order.

dropLow(arr)

Returns an array based on arr without the first element. If sorted in ascending order, this will be the lowest value.

sum(arr)

Returns the sum of all integers in array arr.

generateStat(rollFn = generateRolls)

By default, returns a randomly generated integer between 3 and 18 using the algorithm 4d6, drop the lowest value, and add the remaining 3 die rolls. However the function that provides 4d6 rolls can be injected with the function of your choice. While this is mainly to allow unit testing, you could also override stat generation in some interesting ways here.

This function will likely be further paramterized in the future to allow other custom rolls (3d6 or 5d6 dropping the lowest two rolls, for example).

outputTable(matrix)

Given a six-element array of six-element arrays matrix, returns a Github Flavored Markdown table that displays all the integers.

generateStatArray(statFn = generateStat)

Returns a six-element array of stat rolls. The function to generate a stat roll can be injected, allowing for both unit testing and custom behavior. (Munchkins rejoice!)

generateStatMatrix(arrayFn = generateStatArray)

Returns a six-element array of six stat rolls. To facilitate unit testing, the stat array function can be injected, but I can think of no practical reason why anyone would customize this function for purposes not involving unit tests. You'll just get six copies of the results of whatever function you pass in here.