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

corollary

v0.0.2

Published

A framework for defining and evaluating complex logical systems. (A cool bool rule tool.)

Downloads

5

Readme

corollary

An alternative boolean framework for complex logical systems. More succinctly: a cool bool rule tool.

This is very experimental and a work-in-progress. Just use for fun.

Usage

The basic usage is to define rules using callbacks. Then, you compose rules using the names of the rules in combination with boolean primitives, like and, or, and not. Eventually, you have a heirarchy of rules that you can query using ask().

const { and, not, createRule, ask } = require('corollary');

createRule('isSkyBlue', weather => weather.skyColor === 'blue');
createRule('isSkyRed', weather => weather.skyColor === 'red');
createRule('isSunOut', weather => weather.cloudCoverage < 0.5);
createRule('isRainy', weather => weather.precipitation > 0.25);

createRule('isNice',
  and(
    'isSkyBlue',
    'isSunOut',
    not('isRainy')
  )
);

const today = {
  skyColor: 'blue',
  cloudCoverage: 0.2,
  precipitation: 0.2
};

const tomorrow = {
  skyColor: 'blue',
  cloudCoverage: 0.8,
  precipitation: 0
};

console.log('Is today nice?', today);

if (ask('isNice', today))
  console.log('Yes!');
else
  console.log('No...');

console.log('\nWill tomorrow be nice?', tomorrow);

if (ask('isNice', tomorrow))
  console.log('Yes!');
else
  console.log('No...');

Roadmap (Future Features)

Where to go from here? The end goal of this module is to simplify and centralize the often thousands of business rules that usually accumulate as spaghetti code if unchecked. With that goal in mind, there are a few features that would be nice to have. Since this is an early project, the API will need to be refined such that the module encourages a good programming style that supports the features.

Dependency Graph Generation

It's easy to get lost in the thousands of relationships between object types and their associations. The corollary API should expose a dependency graph-generator that shows the relationships between rules. An explicit rule system would be necessary define this dependency graph.

Dependency Graph Enforcement

We can take this a step further and enforce dependency graph restrictions. What makes dependency graph hard to completely infer would be the use of ask() in a callback. One approach is to have callback rules declare their dependencies, which are evaluated and passed to the callback.

Heirarchical Naming Convention

A heirarchy based on object types and dependencies could help users better locate and understand their rules. A convention-based API that supports a heirarchical pattern would encourage this type of rule definition and potentially make a dependency graph easier to infer.

Non-Boolean Rule Types and Lots of Primitives

It makes sense for rules to calculate non-boolean return values. The more primitives that corollary can provide to support this, the better. Think sum(), isIn(), isDeepEqual(), set operations, etc. These can be optimized. The primitives could just be rules, and more primitives could be added by the user if needed. It would be helpful to corollary for the user to provide the arity of rules. Maybe this could be part of the dependency API.