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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jeffrey04/ruler

v0.1.0

Published

A rule dsl language parser in Javascript

Readme

ruler

A rule dsl language parser in Javascript

ruler DSL

This mini-language is partially inspired by LISP. A rule is represented by a list of string, including the name of the function. The main advantage of the language is that it is actually JSON, which makes it easy to be serialized.

Syntax & Structure

["namespace.Function_Name", "some_arguments", "more_arguments_if_applicable"]

A rule is usually consist of a function name, and a list of (sometimes optional) arguments. Function names are often namespaced (e.g. "boolean.And", "condition.Equal" etc.) and usually only recognized if placed in the first elemnt.

Unless otherwise specified, a rule can be inserted as an argument to another rule, for example a boolean.And rule.

["boolean.And", ["condition.Equal", ["basic.Field", "fieldA"], "X"],
                ["condition.Equal", ["basic.Field", "fieldB"], "Y"]]

Parsing and computing result

In order to parse the rule, just call ruler.parse. The result is a function where you can put in a context object in order for it to compute a result. Check demo.html from the repository or the hosted version here for live interactive examples.

rule = ruler.parse(["condition.Equal", ["basic.Field", "fieldA"], "X"])
context = {"fieldA": "X"}
rule(context) // should yield true

Usage

I am relatively new to modern Javascript development, kindly send a PR to update this section (:

Pre-requisite

  • Iodash.js is needed

In a Node.js project

Add the library as a dependency (I use yarn myself, but I suppose it is similar for npm user)

yarn add https://github.com/Jeffrey04/ruler

Then in your code, import and use as follows

import ruler from "ruler";

let rule = ruler.parse(["boolean.Tautology"])
console.log(rule({}))

Web browser

Use the es-module-shims library by Guy Bedford to first load the dependencies.

<script defer src="https://unpkg.com/es-module-shims@latest/dist/es-module-shims.js"></script>
<script type="importmap-shim">
  {
    "imports": {
      "lodash": "https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"
    }
  }
</script>
<script defer type="module-shim" src="path/to/your-script.js"></script>

Import the library in your script as follows

import ruler from "path/to/ruler.js";

let rule = ruler.parse(["boolean.Tautology"])
console.log(rule({}))

Ruler API overview

Array functions

Some array related functions.

array.Length

["array.Length", $argument]

Returns the length of a given array $argument.

Basic functions

Some random functions that don't fit anywhere else goes here

basic.Context

["basic.Context", $context_sub, $rule]

Temporarily change the context to $context_sub, and perform $rule with $context_sub as the new context

  • $context_sub (required): A struct, or a rule to extract a new struct w.r.t. the original context
  • $rule (required): the rule to be applied w.r.t. $context_sub

An example:

context = {'sub': {'foo': 'bar'}}
rule = ruler.parse(['basic.Context', ['basic.Field', 'sub'],
                                     ['basic.Field', 'foo']])
result = rule(context)
print(result) # returns context['sub']['foo'], which is 'bar'

Basic.Field

["basic.Field", $key, $default]

Returns a field value from context when called.

  • $key (required): is a key in the context.
  • $default (optional): is a default value to be returned when context[key] does not exist.

basic.Value

["basic.Value", $value]

Returns a value, regardless what is in the context

  • $value (required): a value to return. MAY NOT be a sub-rule

Boolean operators

Usually used to chain condition rules (see next section) together

boolean.And

["boolean.And", $argument1, $argument2, ...]

Returns True if all arguments returns True, or False otherwise.

boolean.Contradiction

["boolean.Contradiction"]

Always returns a False, a shorthand for

["basic.Value", false]

boolean.Not

["boolean.Not", $argument]

Returns the result of negation done to $argument.

boolean.Or

["bolean.Or", $argument2, $argument2]

Returns True if any of the arguments is True, or False otherwise.

boolean.Tautology

["boolean.Tautology"]

Returns True regardless

Condition rules

Usually returns either true or false

condition.Equal

["condition.Equal", $alpha, $beta]

Returns True if and only if $alpha is equivalent to $beta.

condition.Greater_Than

["condition.Greater_Than", $alpha, $beta]

Returns True if and only if $alpha is greater than $beta.

condition.Greater_Than_Equal

["condition.Greater_Than_Equal", $alpha, $beta]

Returns True if and only if $alpha is greater than or equal to $beta.

condition.In

["condition.In", $alpha, $values]

Returns True if $alpha is in $values

condition.Is_Null

["condition.Is_Null", $alpha]

Returns True if $alpha is null

condition.Is_True

["condition.Is_True", $alpha]

Returns True if $alpha is True

condition.Less_Than

["condition.Less_Than", $alpha, $beta]

Returns True if and only if $alpha is less than $beta.

condition.Less_Than_Equal

["condition.Less_Than_Equal", $alpha, $beta]

Returns True if and only if $alpha is less than or equal to $beta.

String operations

Some basic string operations

string.Concat

["string.Concat", $link, $argument1, $argument2, ..]

Concatenate arguments by $link

string.Concat_Fields

["string.Concat_Fields", $link, $key1, $key2, ..]

A short hand for

["string.Concat", $link, ["string.Field", $key1], ["string.Field", $key2], ...]

Note: $key1, $key2 etc.

string.Lower

["string.Lower", $value]

Change $value to lowercase