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

fulfills

v4.0.1

Published

Checks whether or not an object fulfills a specified condition

Downloads

3,793

Readme

npm version npm downloads Module type: CJS Types in JS js-semistandard-style Follow @voxpelli@mastodon.social

Checks whether or not an object fulfills a specified condition

Installation

npm install fulfills --save

Usage

const fulfills = require('fulfills');

const obj = {
  property: { subproperty: 'value' }
};

// Performant option – useful if the same condition is used over and over again
const condition = fulfills.compileCondition('property.subproperty = value OR property.subproperty = 123');

if (fulfills(obj, condition)) {
  // ...
}

// Short option – useful if a condition will only be used once
if (fulfills(obj, 'property.subproperty = value OR property.subproperty = 123')) {
  // ...
}

Condition syntax

A condition has the syntax of:

property == value or just property

The == can be any supported comparison operator. If only a property is given then the condition will be true of the property contains a truthy value in the javascript sense.

Multiple conditions can be combined or modified through the use of logical operators and when doing so parantheses can be used to group them together into different groups.

Needlessly complex example

!(bookmark.bar-car.foo["abc adf sdaf sda f"][][][]=123) AND foo OR bar=abc OR foo="\\" OR foo[]=123 OR foo.abc[].bar.foo[] != true

Property syntax

The property can be targeted at subproperties by appending them with a . before each level, like: property.subproperty.subpropertyOfSubproperty.

To look for a value in an array rather than compare the value to the array itself, then append [] to the property like: property[]

The array syntax and subproperties can be combined however one likes. For example: property.subproperty[][].propertyOfObjectInATwoLevelDeepArray

Complex property names can be specified like ["very complex property name"]. Values in such property names can be escaped, like: ["property name including a \"funny\" char"]

Supported values

  • Simple strings – a single word containing just a-z needs no quotes. Example: foobar
  • Quoted stringes – multiple words or complex words needs to be quoted. Example: "a very long text". Supports escaping, like: "This is an escaped \" character"
  • Integers – a number containg just 0-9 chars
  • Booleans – when set to exactly true or false

Comparison operators

All work just like the javascript comparison operators does.

  • ===
  • == (alias: =)
  • !==
  • != (alias: <>)
  • <
  • >
  • <=
  • >=

Logical operators

  • OR (alias: ||)
  • AND (alias: &&)
  • NOT (alias: !)

For enterprise

Available as part of the Tidelift Subscription.

The maintainers of fulfills and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. Learn more.