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

regent

v3.6.0

Published

Javascript rules engine

Downloads

74

Readme

Regent: Business Rules in JavaScript

regent logo (the letter R wearing a crown)

Regent lets you query a data structure by asking true or false questions. Regent logic is written as single responsibility rules that are self-documenting, composable, and human readable. Let's look at an example.

import { equals } from 'regent';

// return a function that evaluates to true
// if prop `isRaining` is equal to true
const isRaining = equals('@isRaining', true);

// Define your data structure
const data = { isRaining: true };

// Evaluate the rule
const isUmbrellaNeeded = isRaining(data); // true

equals predicate documentation

Taking the previous example a bit further, we can refine the scenario to be more precise. We can create and combine multiple rules to test this condition

If it is raining and the wind isn't so strong the umbrella will turn inside-out and blow out of our hands, we need an umbrella.

import { and, equals, lessThan } from 'regent';

// Define a rule for `isRaining` and a rule for `isCalm`.
// Use regent and to compose them together
const isRaining = equals('@isRaining', true);
const isCalm = lessThan('@windSpeedInMph', 25);
const isRainingAndCalm = and(isRaining, isCalm);

// Define your data structure
const data = { isRaining: true, windSpeedInMph: 20 };

// Evaluate the rule
isRainingAndCalm(data); // true

composition documentation

Regent also provides a simple way to find or filter array items based on a regent rule.

import { equals, lessThan, find, filter } from 'regent';

const isRaining = equals('@isRaining', true);
const isSunny = lessThan('@cloudCover', 10);
const isCold = lessThan('@temperature', 60);

const data = {
  isRaining: false,
  cloudCover: 0,
  temperature: 42
};

const items = [
  { item: 'Winter hat', rule: isCold },
  { item: 'Sunglasses', rule: isSunny },
  { item: 'Umbrella', rule: isRaining },
]

// filter will return an array with the Winter Hat and Sunglasses objects
// because it is cold and sunny
// [{ item: 'Winter hat', rule: isCold }, { item: 'Sunglasses', rule: isSunny }]
filter(items, data)

Installation

npm install --save regent

Documentation

License

MIT