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

logical-json

v0.0.3

Published

A structurized logic executer in JavaScript.

Downloads

15

Readme

logical-json

A structurized logic executer in JavaScript.

Warning

This package is under development, and everyting may change in the future.

Please do NOT use this package in production environment unless you understand what it is doing.

About this Package

This is a JavaScript logic executer for a set of rules described by JSON, witch may have several named inputs and outputs. This may help when you need to structurize or serialize some logical rules, or even to store them in a database.

Tutorial

Basic Usage

const LogicalJson = require ('logical-json');

let parser = new LogicalJson({
  /* Here goes your JSON structure, supportting JSON string */
});

let output = parser.run({
  /* Here is your input in key-value pairs */
});

Mutate Inputs

If some of your inputs have changed, you can use parser.mutate() and pass these changed inputs, instead of run the entire logic. mutate will detect which rules are "dirty" and should be excuted. This results in higher perfomance.

Note that mutate only returns outputs infected by the mutation. If none of the outputs was infected, it returns an empty object.

Async Mode

You can pass a configuration object as the second parameter into the constructor, in which you can run this in async mode:

let parser = new LogicalJson({ /* JSON here */ }, { async: true });

parser.run() and parser.mutate() will return a promise in async mode. Some of rules containing async operations can only be run in this mode.

Aware of part of outputs

awareOf is useful when you only want to know part of outputs in your application. This may help when you need higher performance, since calculations for the unconcerned outputs are ignored:

let parser = new LogicalJson({ /* JSON here */ }, { awareOf: ['some', 'important', 'keys'] });

parser.run() and parser.mutate() will only return keys in awareOf if present.

About the JSON Structure

A set of logical rules is descripted by inputs, outputs, logical nodes and links between them. An input or an output has an unique name, which is corresponded to the keys of input or output objects in the parser. A logical node represents a function, or a logical operation in the rule. IOs and nodes have unique IDs, which can be linked together.

Unfortunately, the structure is optimized for storage and is not for humans. Thus I don't recommend to write complex logical rules by yourself. A visualized design tool is on the way.

If you want to learn more or try write one by your own, see test cases in /tests/LogicParser.test.js.

Contributions are always welcome :)