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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@whi/repr

v0.2.0

Published

A simple string representation library for complex objects

Downloads

19

Readme

repr()

This module is intended to make short, limited string representations of complex object.

For a more detailed inspection tool, try @whi/json which has a json.debug() method for deep representational inspection.

Overview

The main use-case for this library is expected to be for logging.

Features

  • Distinguish primitive types from their similar object version
  • Truncate large list types
  • Support for
    • Map types:
      • Boolean, Number, String, Date, RegExp, Function, Object
    • List types:
      • Array, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array
    • Primitive types:
      • string, number, bigint, boolean, null, undefined, symbol
  • Custom object formatting by implementing a toRepr() method.

Install

npm i @whi/repr

Usage

The default import is a single function.

const repr = require('@whi/repr');

Pass any value to repr to get the representational value.

const value = [0,1,2,3,4,5,6,7,8,9];

repr( input )
// Array (10) [ 0, 1, 2, 3 … 6, 7, 8, 9 ]

repr( input, true );
// Array(10)
const value = {a:0,b:0,c:0,d:0,e:0,f:0,g:0,h:0,i:0,j:0};

repr( input )
// Object { a: 0, b: 0, c: 0, d: 0 … 6 more properties }

repr( input, true );
// Object(10)

Second-level values are automatically displayed using the minimal format.

const value = [ [], {}, new Boolean(1), new Number(1), new String("hi"), new Date(1646429736851), RegExp(/.*/gi), () => {} ];

repr( input )
// Array (8) [ Array(0), Object(0), Bool(1), Number(1), String("hi"), 2022-03-04T21:35:36.851Z, RegExp(/.*/gi), function(0 args) ]

repr( input, true );
// Array(8)

Custom formatting

class Rectangle {
    constructor ( x, y ) {
        this.x = x;
        this.y = y;
    }

    toRepr ( minimal ) {
        return minimal
            ? `${this.constructor.name}(${this.x},${this.y})`
            : `${this.constructor.name} { x: ${this.x}, y: ${this.y} }`;
    }
}

const value = new Rectangle( 3, 4 );

repr( value )
// Rectangle { x: 3, y: 4 }

repr( value, true )
// Rectangle(3,4)

Contributing

See CONTRIBUTING.md