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

pickpick-targeting-compiler

v0.2.0

Published

compiles targeting expressions for pickpick engine

Downloads

38

Readme

pickpick-targeting-compiler

compiles targeting expressions to javascript code for pickpick engine

  • uses jsep to parse expressions and turn them into a javascript function that evaluates a conditiongiven a certain input.
  • uses the vm module to have isolated context
  • in addition to normal javascript operators, there are some special operators (see below for example):
    • in is exactly Array.includes
    • match regexp test
    • startsWith and endsWith is exactly String.startsWith and String.endsWith respectively
  • exposes a bunch of useful is* functions from util module
  • open for extension via user defined envinronment accessible using $

example

npm i pickpick-targeting-compiler

const assert = require('assert')
const compile = require('pickpick-targeting-compiler')

// intentionally using var here 

// all normal js operators apply
var { isMatch, features } = compile('_.geo === "US"')
assert(isMatch({ geo: 'US' }))

var { isMatch, features } = compile('_.number >= 0')
assert(isMatch({ number: 1 }))
assert(isMatch({ number: 2 }))
assert(isMatch({ number: 3 }))

// can create compound logical statements
var { isMatch, features } = compile('_.geo === "US" && _.number > 5')
assert(isMatch({ geo: 'US', number: 8 }))

// in operator - same as Array.includes(value)
var { isMatch, features } = compile('_.geo in ["US", "MX"]')
assert(isMatch({ geo: 'US' }))

// operators apply to context data as well
var { isMatch, features } = compile('_.geo in _.page')
assert(isMatch({ geo: 'US', page: ["US", "MX"] }))

// startsWith operator - same as String.startsWith(string)
var { isMatch, features } = compile('_.geo startsWith "x"')
assert(isMatch({ geo: 'xyz' }))

// endsWith operator - same as String.endsWith(string)
var { isMatch, features } = compile('_.geo endsWith "z"')
assert(isMatch({ geo: 'xyz' }))

// match operator for literal regular expressions, same as /regex/g.test('value')
var { isMatch, features } = compile('_.geo match "[0-9]"')
assert(isMatch({ geo: 0 }))

// deeplyEquals operator performs a deep equal comparison (uses [lodash.isEqual](https://lodash.com/docs/4.17.10#isEqual))
var { isMatch, features } = compile('_.geo deeplyEquals [1, 2, 3]')
assert(isMatch({ geo: [1, 2, 3] }))

// exposes a bunch of isSomething from util:
// isNullOrUndefined,
// isNull,
// isUndefined,
// isString,
// isNumber,
// isArray,
// isObject,
// isBoolean,
// isDate,
// isNull,
// isPrimitive
var { isMatch, features } = compile('isNumber(_.geo)')
assert(isMatch({ geo: 0 }))

// provide user defined functions and data
const userEnvironment = { x: [1, 2, 3], isOk: (arg) => arg.startsWith('x') }
var { isMatch, features } = compile('_.geo in $.x && $.isOk(_.page)', { userEnvironment })
assert(isMatch({ geo: 1, page: 'x.html' }))

api

Table of Contents

compile

index.js:56-156

Compile an expression into a resuable javascript function

Parameters

  • expression String any expression that can be parsed by jsep
  • options Object (optional, default {})
    • options.matcherProperty String return the match function using a different property name in the compound return value, e.g: (optional, default 'isMatch')
    • options.userEnvironment Object allows the user to inject additional functionality that will be exposed to the expression. e.g: (optional, default {})
    • options.userEnvNamespace String change the name used to access user environment in an expression (optional, default $)
    • options.inputNamespace String change the name used to access input in the expression (optional, default _)

Examples

// options.matcherProperty
 
   // normally this would be isMatch instead of 'foo'
   let { foo } = compile('_.geo === "1"', { matcherProperty: 'foo' })
// options.userEnvironment
   
   let userEnvironment = {
 	    geos: ['MX', 'US', 'IL'],
  	    format: value => value.toUpperCase()
   }
   
   let { isMatch } = compile('$.format(_.geo) in $.geos', { userEnvironment })

Returns Function a function that accepts input and returns a boolean value

license

MIT © ironSource LTD