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

basic-record

v1.0.1

Published

A 25 LOC utility to define and create records via objects literals.

Readme

basic-record

Social Media Photo by Adrian Korte on Unsplash

Build Status Coverage Status

A 25 LOC utility to define and create records via objects literals.

Each Record class will have an implements(Record) method that returns true if the passed Record was used during class definition.

const {create, define} = require('basic-record');

// define a Record class through one or more arguments
const Point2D = define({x: 0, y: 0});

// define mixins by passing records and/or literals
const Point3D = define(Point2D, {z: 0});

// create an instance via new Record or create(Record)
const p2d = create(Point2D);
console.assert(
  p2d.x === 0                           &&
  p2d.y === 0                           &&
  Point2D.implements(Point2D) === true  &&
  Point2D.implements(Point3D) === false // Point2D is not Point3D
);

// optionally pass an `init` object to assign its values
const p3d = create(Point3D, {y: 123, z: 9});
const {constructor} = p3d;
console.assert(
  p3d.x === 0                               &&
  p3d.y === 123                             &&
  p3d.z === 9                               &&
  constructor.implements(Point3D) === true  &&
  constructor.implements(Point2D) === true  // Point3D is also Point2D
);

Use cases & Benchmark

The peculiarity of records is their ability to define every default value directly through their prototype. The benefits are seen particularly in creation of many default objects, but also assignment of partial properties, as opposite of guarding each received property, or argument, with a default value.

The benchmark file reflects these goals, underlying where it's easier, and faster, to use records instead of regular classes instances.

Results:

class.create: 0.299ms
record.create: 0.023ms

class.createArgs: 0.016ms
record.createArgs: 0.073ms

class.createExtend: 0.443ms
record.createExtend: 0.02ms

class.createExtendArgs: 0.014ms
record.createExtendArgs: 0.061ms

class.createPartialDefaults: 0.056ms
record.createPartialDefaults: 0.044ms

class.copy: 0.256ms
record.copy: 0.058ms

class.copyExtend: 0.528ms
record.copyExtend: 0.063ms

class.getCoords: 0.455ms
record.getCoords: 0.009ms

class.getCoordsArgs: 0.018ms
record.getCoordsArgs: 0.007ms