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

@etianen/dict

v0.4.0

Published

Helpers for treating objects as maps.

Readme

@etianen/dict

Helpers for treating dicts as maps.

Installing

npm install '@etianen/dict'

TypeScript: To take advantage of typings, be sure to set moduleResolution to "node" in your tsconfig.json.

Overview

Treating dicts as maps in Javascript is needlessly difficult.

@etianen/dict provides a minimal set of helpers of interacting with dicts.

import * as dict from "@etianen/dict";

dict.has({foo: "bar"}, "foo");  // => true
dict.mapValues({foo: "bar"}, v => v.toUpperCase());  // => {foo: "BAR"}

API

In all the functions below:

  • Only own, enumerable properties are considered.
  • The source arguments are never mutated.
  • If the return value is a Dict or Array, it is frozen.

Dict

An object containing values of type V.

type Dict<V> = {[key: string]: V};

count()

Returns the number of entries in dict.

Note: This is an O(n) operation. Use isEmpty() if you just want to check if the dict is empty.

function count(dict: Dict<Object>): number;

empty()

Returns a new empty dict.

function empty<V>(): Dict<V>;

entries()

Returns an Array of [key, value] entries in dict.

function entries<V>(dict: Dict<V>): Array<[string, V]>;

every()

Returns true if all entries in dict satisfy predicate.

function every<V>(dict: Dict<V>, predicate: (value?: V, key?: string, dict?: Dict<V>) => boolean, context?: Object): boolean;

filter()

Returns a new dict containing entries from dict that satisfy predicate.

function filter<V>(dict: Dict<V>, predicate: predicate: (value?: V, key?: string, dict?: Dict<V>) => boolean, context?: Object): Dict<V>

forEach()

Runs sideEffect for each entry in dict.

function forEach<V>(dict: Dict<V>, sideEffect: (value?: V, key?: string, dict?: Dict<V>) => void, context?: Object): void;

fromEntries()

Creates a new dict from an array of [key, value] entries.

function fromEntries<V>(entries: Array<[string, V]>): Dict<V>;

fromKeys()

Creates a new dict from an array of keys, obtaining the values by passing each key through mapper.

function fromKeys<V>(keys: Array<string>, mapper: (key?: string, index?: number, array?: Array<string>) => V, context?: Object): Dict<V>

get()

Returns the value at key in dict, or defaultValue if the key is not set.

function get<V>(dict: Dict<V>, key: string, defaultValue?: V): V;

has()

Returns true if key is in dict.

function has(dict: Dict<Object>, key: string): boolean;

isEmpty()

Returns true if dict contains no entries.

function isEmpty(dict: Dict<Object>): boolean;

keys()

Returns an Array of all keys in dict.

function keys(dict: Dict<Object>): Array<string>;

map()

Returns a new Array with all entries passed through mapper.

function map<V, R>(dict: Dict<V>, mapper: (value?: V, key: string, dict?: Dict<V>) => R, context?: Object): Array<R>

mapEntries()

Returns a new dict with all entries passed through mapper.

function mapEntries<V, R>(dict: Dict<V>, mapper: (value?: V, key: string, dict?: Dict<V>) => [string, R], context?: Object): Dict<R>

mapKeys()

Returns a new dict with all keys passed through mapper.

function mapKeys<V>(dict: Dict<V>, mapper: (key?: string, value? V, dict?: Dict<V>) => string, context?: Object): Dict<V>;

mapValues()

Returns a new dict with all values passed through mapper.

map<V, R>(dict: Dict<V>, mapper: (value?: V, key?: string, dict?: Dict<V>) => R, context?: Object): Dict<R>;

reduce()

Reduces dict to a single value using reducer.

function reduce<V>(dict: Dict<V>, reducer: (reduction?: V, value?: V, key?: string, dict?: Dict<V>) => V): V;
function reduce<V, R>(dict: Dict<V>, reducer: (reduction?: R, value?: V, key?: string, dict?: Dict<V>) => R, initialReduction: R, context?: V;

remove()

Returns a new dict with key removed.

function remove<V>(dict: Dict<V>, key: string): Dict<V>;

set()

Returns a new dict with key set to value.

function set<V>(dict: Dict<V>, key: string, value: V): Dict<V>;

some()

Returns true if one or more entries in dict satisfy predicate.

function some<V>(dict: Dict<V>, predicate: (value?: V, key?: string, dict?: Dict<V>) => boolean, context?: Object): boolean;

update()

Returns a copy of dict updated with all entries in other.

function update<V>(dict: Dict<V>, other: Dict<V>): Dict<V>;

values()

Returns an Array of all values in dict.

function values<V>(dict: Dict<V>): Array<V>;

Build status

This project is built on every push using the Travis-CI service.

Build Status

Support and announcements

Downloads and bug tracking can be found at the main project website.

More information

This project was developed by Dave Hall. You can get the code from the project site.

Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually find him on the Internet: