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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pinemach/describe

v1.2.0

Published

Brief string descriptions of arbitrary values.

Readme

@pinemach/describe

This is a small, simple, permissively-licensed and zero-dependency library for getting a brief string description of arbitrary JavaScript values.

The default built-in description logic guarantees that strings will not be longer than 60 characters and will not contain newlines or control characters. This makes the package particularly suitable for generating human-readable descriptions of untrusted data, that is safe to output to a log.

Installation

You can add @pinemach/describe to your JavaScript project via NPM:

npm install --save @pinemach/describe

Usage

The simplest usage of this package is to import the default describe function and invoke it with the value that should be described.

Basic usage:

const {describe} = require("@pinemach/describe");

console.log(describe(null)); // Prints "null"
console.log(describe(1234.5)); // Prints "the number 1234.5"
console.log(describe({})); // Prints "an empty object"
console.log(describe([0, 1, 2, 3])); // Prints "an array with 4 elements"

The package also supports overriding description behavior via the addDescriptor function. Descriptor functions take precedence over default built-in logic, and descriptors added first take precedence over descriptors added last. When a descriptor function returns a non-empty string for an input value, that string will be produced by the describe function instead of its default output. When a descriptor function returns any falsey value, evaluation continues for remaining descriptor functions and then to the default description logic.

Intermediate usage, featuring custom value descriptors:

const {describe, addDescriptor} = require("@pinemach/describe");

// A custom class that we will want a custom description for
class MyClass {
    constructor(n) {
        this.n = n;
    }
}

// Prints "an object instance of \"MyClass\""
console.log(describe(new MyClass(50)));

// Add special logic for describing MyClass instances
addDescriptor((value) => {
    if(value instanceof MyClass) {
        return "MyClass #" + value.n;
    }
    else {
        return undefined;
    }
});

// Prints "MyClass #50"
console.log(describe(new MyClass(50)));

The package also provides a Describe class for instanced behavior. This means that custom descriptor functions may be added to a specific instance and applied only to uses of that instance's describe method, without changing the behavior of the global default describe function or any other Describe instances.

Advanced usage, featuring custom value descriptors and instanced Describe logic:

const {Describe, describe} = require("@pinemach/describe");

// A custom class that we will want a custom description for
class MyClass {
    constructor(n) {
        this.n = n;
    }
}

// Create a new Describe instance instead of using the global default
const myDescriber = new Describe();

// Add special logic for describing MyClass instances
myDescriber.addDescriptor((value) => {
    if(value instanceof MyClass) {
        return "MyClass #" + value.n;
    }
    else {
        return undefined;
    }
});

// Prints "MyClass #50"
console.log(myDescriber.describe(new MyClass(50)));

// Still prints "an object instance of \"MyClass\""
console.log(describe(new MyClass(50)));