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

picklogic

v1.0.2

Published

A JS engine to pick among JSON objects based on simple logic conditions

Readme

❯ Quick Start

Install with npm:

$ npm install picklogic

Install with yarn:

$ yarn add picklogic

❯ Demo

Clone the PickLogic Demo repo, install dependencies, and run:

$ git clone [email protected]:GlobalStrategies/picklogic-demo.git
$ yarn
$ yarn demo

❯ Concept

Suppose you have two objects that you need to choose between:

const NORMAL = { "color": "green", "message": "Your temperature is normal." }
const FEVER = { "color": "red", "message": "You have a fever." }

You could write conditions to choose:

if ((system === FAHRENHEIT && temperature > 100) || (system === CELSIUS && temperature > 37.8)) { return FEVER; }

Or you could include the conditions with the data, thinking of them as the criteria to select the JSON object:

{
  "pickCriteria": <CRITERIA>,
  "payload": { "color": "red", "message": "You have a fever." }
}

The criteria can be encoded as equally acceptable sets of conditions that must be fulfilled:

{
  "pickCriteria": [
    {
      IF system === FAHRENHEIT && temperature > 100
    },
    {
      IF system === CELSIUS && temperature > 37.8
    }
  ],
  "payload": { "color": "red", "message": "You have a fever." }
}

If any of the pickCriteria are satisfied, the payload is delivered. The array elements can be thought of as conditions separated by ORs. We call each of these condition sets sufficientToPick. We then translate the AND conditions to array elements within each sufficientToPick property:

{
  "pickCriteria": [
    {
      "sufficientToPick": [system === FAHRENHEIT, temperature > 100]
    },
    {
      "sufficientToPick": [system === CELSIUS, temperature > 37.8]
    }
  ],
  "payload": { "color": "red", "message": "You have a fever." }
}

Finally we rewrite conditions in this form:

"sufficientToPick": [
  {
    "dataKey": "system",
    "operator": "=",
    "referenceValue": "FAHRENHEIT"
  },
  {
    "dataKey": "temperature",
    "operator": ">",
    "referenceValue": 100
  }
]

❯ API

Pickable

A pickable is a JSON object that includes an id, the pickCriteria under which it should be selected, and the payload it should deliver if selected. The Pickable class constructor function is a convenience for making this JSON format human-readable.

Params

  • pickable {Object}: A pickable JSON object of the form { "id": {string}, "pickCriteria": {Array}, "payload": {Object} }
  • defaultKey {string}: (optional). If all conditions perform logic on the same key, this property can be passed in and the "dataKey" property can be left out of all conditions.
  • lowerRanked {boolean}: (optional). Important only for condition readouts; determines whether an "always pick" condition is rendered as ALWAYS or IF not otherwise diverted. If an "always pick" condition (pickCriteria: []) is the only pickable in a set (lowerRanked = false), the conditionality is simply output as ALWAYS. Otherwise, it must be a final "catch-all" (lowerRanked = true), so the conditionality is output as IF not otherwise diverted.

Example

const pickable = new Pickable(FEVER_PICKABLE, null, true)

readoutsForPickableWithLocalized()

Outputs an object containing simplified string versions of the conditions, optionally localizing fixed words like IF and AND. This can be used to help non-engineers validate the conditional logic.

Params

  • localized {function}: (optional). A function that takes keywords and outputs localized equivalents (keywords used are ALWAYS, AND, OR, IF, NOT, NO, and 'not previously diverted'.

Example

pickable.readoutsForPickableWithLocalized()

Sample output

[{ 
  conjunction: 'IF',
  conditionString: 'system = F & temperature > 100'
}, {
  conjunction: 'OR',
  conditionString: 'system = C & temperature > 37.8'
}]

This can be easily converted to a simple text format, as seen in the demo.

Picker

The Picker class digests passed JSON conditions (pickables) and can evaluate them against passed data hashes.

Params

  • pickables {Array}: The JSON pickables to select among, each of the form { "id": {string}, "pickCriteria": {Array}, "payload": {Object} }. You can optionally include a "logicRank": {number} property to evaluate the conditions on each object in a specific order.
  • defaultKey {string}: (optional) If all conditions perform logic on the same key, this property can be passed in and the "dataKey" property can be left out of all conditions.

Example

const picker = new Picker(jsonFile.pickables, 'temperature')

pickForData()

Given the passed data, get a matching JSON object, if any.

Params

  • data {Object}: The data object should be a hash in the form { [dataKey]: { "value": {string | number | boolean | Array}, "datatype": {string} }.

Example

const pick = picker.pickForData({ system: { value: 'FAHRENHEIT', datatype: 'string' }, temperature: { value: 101, datatype: 'number' } })