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

@mkrause/strux

v0.0.9

Published

Immutable data structures for JavaScript + flowtype.

Readme

strux

A set of immutable (persistent) data structures. Uses flow for static type checking.

Motivation

This library is similar to existing libraries like ImmutableJS. I created strux because none of the libraries I could find matched exactly what I was looking for. A few notable ways in which strux is different:

  • Strux makes heavy use of modern JavaScript features like Map (for true ordered maps, as well as support for arbitrary keys), and WeakMap (for efficient caching through object references).

  • Strux Mapping performs key comparison based on their value, rather than by reference. That means that the example below will work. Internally we calculate a hash for each key, and perform lookups based on the hash.

const users = new Mapping([
    [{ id: 'john' }, 42],
    [{ id: 'alice' }, 101],
]);
users.has({ id: 'alice' }); // true
users.get({ id: 'alice' }); // 101
  • Strux relies on flow for static type checking whenever possible. For example, rather than using runtime type checking of record types (like ImmutableJS Record), we rely on flow generics using Record<T> (where T is the record type).

  • Includes nonempty versions of types where it makes sense. That is, they exclude the "empty" value of that type. For example, a dictionary with zero entries is not a valid instance of Dictionary, and an empty string is not a valid instance of Text. The reason we default to nonempty types is that it helps to prevent bugs caused by mishandling of edge cases. Expanding a nonempty type to a allow empty values is still easy, by using a maybe type (?type in flow).

Strux has not yet been fully optimized. If you're working with large data sets, or have stringent performance requirements, then this library may not fit your needs.

Interfaces

  • Hashable: support a hash() method to calculate a unique hash for some value object.
interface Hashable {
    hash() : string;
}
  • Equatable: support equality checking between two objects.
interface Equatable {
    equals(other : Hashable) : boolean;
}
  • JsonSerializable: support JSON serialization through toJSON().
interface JsonSerializable {
    toJSON() : any;
}

Structures

Primitives

  • Unit

Represents the empty value. Serves a purpose similar to null in JS.

  • Text and TextNonempty

Represents a textual value (i.e. a piece of Unicode text). Can be constructed from any JS string. TextNonempty excludes the empty string "".

const message = new Text('hello');
message.equals(new Text('hello')); // true
message.toString(); // 'hello'
  • Natural and NaturalNonempty

Represents a natural number. Can be constructed from any finite JS integer greater or equal than zero. NaturalNonempty also excludes zero.

const count = new Natural(42);
count.equals(new Natural(42)); // true
count.valueOf(); // 42

Compounds

  • Record<T>

A record of type T. For example, to represent a person with a name field, and a numerical score:

type Person = { name : string, score : number };
const john : Record<Person> = new Record({ name: 'John', score: 42 });
john.get('name'); // 'John'

Records are always nonempty types. That is, a record of zero properties is not allowed.

  • Dictionary<A> and DictionaryNonempty<A>

A mapping from symbols (strings) to values of type A. Similar to a JS object, in that keys are always textual. But meant specifically for collections of items of the same type (A). In contrast, objects that represent a single (record) type should use the Record type.

const scores = new Dictionary({
    john: 42,
    alice: 101,
});
scores.get('john'); // 42
scores.toJSON(); // { john: 42, alice: 101 }
  • Mapping<K, A> and MappingNonempty<K, A>

A mapping from arbitrary keys (type A) to arbitrary values (type V). Keys are compared by value equality, rather than by reference. That means that two objects will refer to the same value, as long as they are equal.

const users = new Mapping([
    [{ id: 'john' }, new Record({ name: 'John', score: 42 })],
    [{ id: 'alice' }, new Record({ name: 'Alice', score: 101 })],
]);
users.get({ id: 'alice' }).get('score'); // 101