Code Monkey home page Code Monkey logo

node-fulfills's Introduction

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.

node-fulfills's People

Contributors

fossabot avatar renovate-bot avatar renovate[bot] avatar voxpelli avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

fossabot jjhftykj

node-fulfills's Issues

Add a LIKE / INCLUDES or similar keyword

Have an INCLUDES be like email INCLUDES '@example.com'?

Maybe instead of a LIKE (email LIKE '%example%') have something which uses a regexp (😱)? email MATCH /\w+/ The latter is probably a very bad idea, but a somewhat exciting one. Who doesn't want to play with 🔥?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency @voxpelli/eslint-config to v21
  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
.github/workflows/compliance.yml
  • mtfoley/pr-compliance-action 11b664f0fcf2c4ce954f05ccfcaab6e52b529f86
.github/workflows/dependency-review.yml
.github/workflows/lint.yml
.github/workflows/nodejs.yml
.github/workflows/release-please.yml
.github/workflows/types.yml
npm
package.json
  • @types/chai ^4.3.16
  • @types/mocha ^10.0.7
  • @types/node ^18.19.34
  • @voxpelli/eslint-config ^20.0.0-alpha8
  • @voxpelli/tsconfig ^12.0.1
  • c8 ^10.1.2
  • chai ^4.4.1
  • eslint ^9.5.0
  • husky ^9.1.1
  • installed-check ^9.3.0
  • knip ^5.18.0
  • mocha ^10.7.0
  • nodemon ^3.1.4
  • npm-run-all2 ^6.2.2
  • pegjs ^0.9.0
  • type-coverage ^2.29.0
  • typescript ^5.4.5
  • validate-conventional-commit ^1.0.3
  • node ^18.18.0 || ^20.9.0 || >=21.1.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.