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

cond-xtra

v1.0.0

Published

cond construct for JavaScript

Readme

cond-xtra

Cond construct with some minor conveniences added.

API

cond(...clauseList, default)

Iterate through a series of clauses until one of them has a true predicate. Predicates and return values can both be closures in order to evaluate them lazily. If it's necessary to return a function as a value, cond.value can be used to wrap it, or it can be returned from another anonymous function. If none of the clauses has a true predicate, returns the last clause as the default.

Example

const resType = 'application/json;charset=utf-8';
const message = cond(
    // clauses can have pre-evaluated predicates and values
    [resType.includes('json'), 'it\'s json'],
    // one or both may be closures for lazy evaluation; especially helpful for
    // error checking
    [() => resType.includes('text'), () => 'it\'s text'],
    // Entire clause may be in a closure; both parts will be evaluated at the
    // same time, but only when this clause is reached
    () => [resType.includes('xml'), 'it\'s xml'],
    // Default may be a literal or a closure
    `I dunno what it is, but the header says ${resType}`
); // -> 'it\'s json'

cond.value(any)

Wraps a return value so it isn't accidentally evaluated when its predicate is true. This should be used for any x for which x instanceof Function is true. This can wrap any value, but is only useful for callable return values.

Example

const order = 'asc'
const sortingFunc = cond(
    [order === 'desc', cond.value((a, b) => a - b)],
    [order === 'asc', cond.value((a, b) => b - a)],
    cond.value((a, b) => 0)
); // -> [Function]

cond.nd(...clauseList)

Same as cond.multi, but automatically provides null as the default value.

Example

const message = cond(
    [false, 'this will never be seen'],
    ['', 'not this one, either'],
    [0, 'nope']
    // No default clause needed
); // -> null

cond.multi(...clauseList, default)

Returns an Array containing the return values for all clauses with true predicates. Same lazy evaluation rule holds from regular cond. If no clauses have a true predicate, returns the last clause with no array.

Example

const bestVegetables = cond.multi(
    [false, 'green beans'],
    [true, 'broccoli'],
    [false, 'cauliflower'],
    [true, 'snow peas'],
    ['carrots']
); // -> ['broccoli', 'snow peas']

cond.multind(...clauseList)

Same as cond.multi, but automatically provides null as the default value.

Example

const bestVegetables = cond.multi(
    [false, 'green beans'],
    [false, 'broccoli'],
    [false, 'cauliflower'],
    [false, 'snow peas'],
    // no default needed
); // -> null