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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pfi

v0.0.2

Published

predicate filter interpolator

Downloads

4

Readme

Predicate Filter Interpolator

A short hand for creating predicate functions

Goals

  • No dependencies
  • Bundle size as small as possible
  • As fast as possible
import p from "pfi";

const isTrue = p`${true}`; // will only match true
const isTrue = n => n === true; // is longer!

const isFalse = p`${false}`; // will only match false
const isNine = p`${9}`; // will only match 9

const isBetween6And9 = p`${n => n > 6 && n < 9}`; // will match 7 or 8
const isArrayWithLength4 = p`[] && {length:${4}}`;
const isArrayWithLength4 = a => Array.isArray(a) && a.length === 4;

const isArrayContaining7 = p`[${7}]`;
const isArrayContaining7AndStringFoo = p`[${7},${"foo"}]`; // [1,7,'foo']
const isNotArrayContaining7 = p`![${7}]`; // Will match anything such as {} apart from [1,2,3,4,7] or [7]
const isArrayNotContaining7 = p`[!${7}]`; // Will match [1,2,3,4] but not {}
const isEmptyArray = p`[]`;
const isEmptyObject = p`{}`;
const isEmptyArrayOrEmptyObject = p`[]||{}`;
const isFalsy = p`!`;
const isTruthy = p`!!`;
const isEmptyString = p`""`;
const isEmptyString = p`${""}`;
const hasName = p`{name}`; // {name: 'foo'}
const hasNameOrhasNum = p`{name}||{num}`;
const hasNameAndNum = p`{name,num}`;
const isRupert = p`${"Rupert"}`;
const isNumeric = p`${Number}`;
const isBoolean = p`${Boolean}`;
const isString = p`${String}`;
const isObject = p`${Object}`;
const isSymbol = p`${Symbol}`;
const isSymbol = s => typeof s === "symbol";
const isFunction = p`${Function}`;
const isUndefined = p`${undefined}`;
const isNotUndefined = p`!${undefined}`;
const isNull = p`${null}`;
const isNil = p`${null}||${undefined}`;

const isNotNil = p`!${p`${null}||${undefined}`}`;

const isNotNil = p`!(${null}||${undefined})`; //this cn be phase 2

const isComplexObject = p`{
  type:${/^.+foo$/},
  payload:{
    arr:![${6}],
    foo:!${true},
    num:${n => n > 4 || n < -100},
    bar:{
      baz:${/^foo/},
      foo
    },
    "foo-bar":${6}
  }
}`;