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

twople

v0.1.0

Published

A helper for creating key/value pairs, also known as entries

Readme

Twople

Twople is a micro-library for declaring key-value pairs, which in javascript are called "entries" and are implemented as tuples (a tuple is an array of some fixed number of items, in this case two, hence the name). An entry, such as is used to constuct an es6 Map can be written as [key, value].

Build Status npm version

Why

Generally there are two specific reasons why you would want to use twoples:

Initializing maps in Typescript

If you use typescript and tried to write the following, you may have been surprised when it was an error:

const entryList = [['key', 'value']];

new Map(entryList);

This fails because typescript only infers forwards in code. It thinks that entry list is of type Array<Array<"key" | "value">>, instead of correctly understanding that it should use Array<["key", "value"]>.

You can fix this code using twople!

import entry from 'twople';
const entryList = [entry('key1', 'value1'), entry('key2', 'value2')];

new Map(entryList);

Now it works great!

Reflective behavior

Some operations make more sense when they are aware of key-value pairs. For example the map function normally is passed a callback of the form (value, i) => .... In this circumstance i is fulfilling the role of a key, because when the map implementation is Array.prototype.map, it is indeed the key of the item in the array. If you are trying to write a more general map function however, or make use of such a general function which has already been written, then twople can allow you to understand (or specify) that your input is a sequence of key-value pairs, after which map can give you the appropriate key, and return a result in which only the values are changed.

API

function entry(key, value) The result of this function is an entry: [key, value]. This function is the default export of the library, even when used in node.

function entryIterable(iterable) This function is a passthrough. It should be passed an iterable of entries and it will emit those same entries. It will throw an error if any or the items in the iterable is not an Array of size two. isEntryIterable(entryIterable(iterable)) returns true.

function isEntryIterable(iterable) Returns true if every item in the iterable can safely be expected to be an entry. This function is actually a re-export from structure-ish, and is capable of detecting more types of entry iterables (Maps, for example) than just those created by the entryIterable function.