Gathering detailed insights and metrics for picklogic
Gathering detailed insights and metrics for picklogic
Gathering detailed insights and metrics for picklogic
Gathering detailed insights and metrics for picklogic
A JS engine to pick among JSON objects based on simple logic conditions
npm install picklogic
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
1 Stars
14 Commits
8 Branches
1 Contributors
Updated on Jul 25, 2024
Latest Version
1.0.2
Package Id
picklogic@1.0.2
Unpacked Size
134.81 kB
Size
20.45 kB
File Count
18
NPM Version
7.5.4
Node Version
14.4.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A format for bundling JSON objects with selection conditions
An engine to do the selecting
Created by Global Strategies for NoviGuide
Install with npm:
1$ npm install picklogic
Install with yarn:
1$ yarn add picklogic
Clone the PickLogic Demo repo, install dependencies, and run:
1$ git clone git@github.com:GlobalStrategies/picklogic-demo.git 2$ yarn 3$ yarn demo
Suppose you have two objects that you need to choose between:
const NORMAL = { "color": "green", "message": "Your temperature is normal." }
const FEVER = { "color": "red", "message": "You have a fever." }
You could write conditions to choose:
if ((system === FAHRENHEIT && temperature > 100) || (system === CELSIUS && temperature > 37.8)) { return FEVER; }
Or you could include the conditions with the data, thinking of them as the criteria to select the JSON object:
{
"pickCriteria": <CRITERIA>,
"payload": { "color": "red", "message": "You have a fever." }
}
The criteria can be encoded as equally acceptable sets of conditions that must be fulfilled:
{
"pickCriteria": [
{
IF system === FAHRENHEIT && temperature > 100
},
{
IF system === CELSIUS && temperature > 37.8
}
],
"payload": { "color": "red", "message": "You have a fever." }
}
If any of the pickCriteria
are satisfied, the payload is delivered. The array elements can be thought of as conditions separated by OR
s. We call each of these condition sets sufficientToPick
. We then translate the AND
conditions to array elements within each sufficientToPick
property:
{
"pickCriteria": [
{
"sufficientToPick": [system === FAHRENHEIT, temperature > 100]
},
{
"sufficientToPick": [system === CELSIUS, temperature > 37.8]
}
],
"payload": { "color": "red", "message": "You have a fever." }
}
Finally we rewrite conditions in this form:
"sufficientToPick": [
{
"dataKey": "system",
"operator": "=",
"referenceValue": "FAHRENHEIT"
},
{
"dataKey": "temperature",
"operator": ">",
"referenceValue": 100
}
]
A pickable is a JSON object that includes an id
, the pickCriteria
under which it should be selected, and the payload
it should deliver if selected.
The Pickable
class constructor function is a convenience for making this JSON format human-readable.
Params
pickable
{Object}: A pickable JSON object of the form { "id": {string}, "pickCriteria": {Array}, "payload": {Object} }
defaultKey
{string}: (optional). If all conditions perform logic on the same key, this property can be passed in and the "dataKey"
property can be left out of all conditions.lowerRanked
{boolean}: (optional). Important only for condition readouts; determines whether an "always pick" condition is rendered as ALWAYS
or IF not otherwise diverted
. If an "always pick" condition (pickCriteria: []
) is the only pickable in a set (lowerRanked = false
), the conditionality is simply output as ALWAYS
. Otherwise, it must be a final "catch-all" (lowerRanked = true
), so the conditionality is output as IF not otherwise diverted
.Example
const pickable = new Pickable(FEVER_PICKABLE, null, true)
Outputs an object containing simplified string versions of the conditions, optionally localizing fixed words like IF and AND. This can be used to help non-engineers validate the conditional logic.
Params
localized
{function}: (optional). A function that takes keywords and outputs localized equivalents (keywords used are ALWAYS, AND, OR, IF, NOT, NO, and 'not previously diverted'.Example
pickable.readoutsForPickableWithLocalized()
Sample output
[{
conjunction: 'IF',
conditionString: 'system = F & temperature > 100'
}, {
conjunction: 'OR',
conditionString: 'system = C & temperature > 37.8'
}]
This can be easily converted to a simple text format, as seen in the demo.
The Picker class digests passed JSON conditions (pickables
) and can evaluate them against passed data
hashes.
Params
pickables
{Array}: The JSON pickables
to select among, each of the form { "id": {string}, "pickCriteria": {Array}, "payload": {Object} }
. You can optionally include a "logicRank": {number}
property to evaluate the conditions on each object in a specific order.defaultKey
{string}: (optional) If all conditions perform logic on the same key, this property can be passed in and the "dataKey"
property can be left out of all conditions.Example
const picker = new Picker(jsonFile.pickables, 'temperature')
Given the passed data, get a matching JSON object, if any.
Params
data
{Object}: The data object should be a hash in the form { [dataKey]: { "value": {string | number | boolean | Array}, "datatype": {string} }
.Example
const pick = picker.pickForData({ system: { value: 'FAHRENHEIT', datatype: 'string' }, temperature: { value: 101, datatype: 'number' } })
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
19 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More