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

@mangar2/decision

v2.3.1

Published

derives decisions from json rules, variables and explains them

Downloads

5

Readme

Abstract

Provides a JSON based term evaluator to calculate decisions based on configuration files The syntax of the JSON-terms is derived from Lisp .

Contents

Meta

| | | | --- | --- | | File | decision.js | | Abstract | Provides a JSON based term evaluator to calculate decisions based on configuration files The syntax of the JSON-terms is derived from Lisp . | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

Class Decision

new Decision(variables)

Creates a value class providing the ability to evalutate a json based value . Additionally it explains the value in a juman readable string . Supported operations are

  • [ "or" , t1 , t2 , . . . ]
  • [ "and" , t1 , t2 , . . . ]
  • [ operator , t1 , t2 ] with operators '>' , '<' , '> = ' , '< = ' , ' ! = ' , ' = '
  • [ "+/-" , t1 , t2 ]
  • [ "if" , t1 , then , else ]
  • [ "switch" , t1 , { map } ] where map is an array of variable value maps . Example [ "switch" , 1 , { 1 : "a" , 2 : "b" } ] results in 'a'
  • [ "function" , . . . parameter ] where function is registrated by a call to 'on'

Example

const variables = {
   'a/b': 1,
   'b/c': 2,
   'system/presence': 'awake'
}
const value = new Decision(variables)
const result = value.decide(
     [
          'and',
          ['or', ['<', 'a/b', 10], ['<', 'b/c', 2]],
          ['or', ['>=', 'a/b', 10], ['>=', 'b/c', 2]]
      ]
)
// returns result.value = true and result.reason = 'a/b (1) is < 10 and b/c (2) is >= 2'

Decision Parameters

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | variables | Object | optional | { } | list of known variables and values | |

Decision Methods

_ISOStringToDate

_ISOStringToDate (value) => {Date, any}

Converts any value from an ISO formatted date string to a date object If it is not an ISO formatted date string , the original value will be returned

_ISOStringToDate Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | value | any | any value | |

_ISOStringToDate returns

| Type | Description | | ---- | ----------- | | Date, any | a Date object or the original value |

eval

eval (jsonTree) => {EvalResult}

Calculates a value based on a json based json tree

eval Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | jsonTree | Object | json structured boolean logic | |

eval throws

| Type | Description | | ---- | ----------- | | Error | on any error in the jsonTree |

eval returns

| Type | Description | | ---- | ----------- | | EvalResult | result of the evaluation |

on

on (event, callback)

Sets a callback .

on Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | event | string | event name ( not case sensitive ) for the callback | | | callback | function | ( parameter ) | |

on throws

| Type | Description | | ---- | ----------- | | Error | if the callback is not 'function' |

Class EvalResult

new EvalResult(value, reason)

Creates a result object with a "value" and a "reason" and a list of used variable : value pairs

EvalResult Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | value | Date, string, number, boolean | evaluation value | | | reason | string | value reason in human readable form | |

EvalResult Members

| Name | Type | description | | ------------ | ------------ | ------------ | | reason | string | Reason explaining the result | | value | Date, string, number, boolean | Value of the result | | variables | Array.<string> | List of missing variables found |