toolkit

toolkit

Contains core functions for Griffon.

Source:

Methods

(static) combineAll(matchers) → {string}

Takes a set of JMESPath matchers and combines together with a &&. The result is that all of the provided matchers must match for the resulting matcher to evaluate true

Parameters:
Name Type Description
matchers Array.<string>

valid JMESPath comparator expression

Source:

(static) combineAny(matchers) → {string}

Takes a set of JMESPath matchers and combines together with a ||. The result is that any of the provided matchers can match for the resulting matcher to evaluate true

Parameters:
Name Type Description
matchers Array.<string>

valid JMESPath comparator expression

Source:

(static) combineNone(matchers) → {string}

Takes a set of JMESPath matchers and combines together with a &&. The result is that all of the provided matchers must match for the resulting matcher to evaluate true

Parameters:
Name Type Description
matchers Array.<string>

valid JMESPath comparator expression

Source:

(static) convertPath(path) → {Array}

Takes a path and coverts it to an array by splitting the periods.

Parameters:
Name Type Description
path string

A valid JMESPath

Source:

(static) expand(kvps) → {object}

Expands all the provided path/value pairs, converting JMESPaths into actual object paths.

Parameters:
Name Type Description
kvps object

Flat object where keys are JMESPaths

Example
import core from 'griffon-toolkit/core';

// returns { size: 's' }
core.expand({ size: 's' });

// returns { size: { width: 200, height: 300 } }
core.expand({ 'size.width': 200, 'size.height': 300 });
Source:
See:
  • core.convertPath

(static) expandWithPaths(paths, kvps) → {object}

Expands with paths. Calls expand, but first will map the provided datas keys using the provided path map.

Parameters:
Name Type Description
paths object

Flat object that maps keys to JMESPaths

kvps object

Flat object where keys are JMESPaths or path keys

Example
import core from 'griffon-toolkit/core';

const path = {
  width: 'size.width',
  height: 'size.height'
};

// returns { size: { width: 200, height: 300 } }
core.expandWithPath({ width: 200, height: 300 });
Source:
See:
  • kit.expand

(static) isMatch(matcher, data) → {*}

Tests to see if the specified data matches the specified JMESPath filter.

Parameters:
Name Type Description
matcher string

A valid JMESPath comparator expression

data Array.<object>

Item to match against

Source:

(static) match(matcher, data) → {*}

Performs a JMESPath filter using the provided expression.

Parameters:
Name Type Description
matcher string

A valid JMESPath comparator expression

data Array.<object>

Data to search

Source:

(static) modify(modifications, matcher, data) → {*}

Matches data from the event list and performs operations on the results. You can provide an object that will be merged into the resulting data.

Parameters:
Name Type Description
modifications object

An object that gets merged with the result. Optionally can be a function that takes the matching data and returns and object

matcher string

A valid JMESPath comparator expression

data Array.<object>

Data to search

Examples
// takes all objects and adds a red color
const makeRed = modify({ color: 'red' }, '*');

const result = makeRed([{ color: 'yellow' }, { name: 'Joe' } ]);
// result is [{ color: 'red' }, { name: 'Joe', color: 'red' } ]
// can provide a modification function
const applyGender = modify((data) => {
 if (data.name === 'Joe') { return { gender: 'male' }; }
 return { gender: 'female' };
}, '*');

const result = applyGender([{ name: 'Jill' }, { name: 'Joe' } ]);
// result is [{ color: 'red', gender: 'female' }, { name: 'Joe', gender: 'male' } ]
Source:
See:
  • core.modifyBulk

(static) modifyBulk(instructions, data) → {*}

Performs a series of match and modify operations on the data. Takes an array of { matcher, modifications } and will perform each on the provided data.

Note you can use mods as an alias for modifications.

Parameters:
Name Type Description
instructions string

{ matcher, modifications }

data Array.<object>

Data to search

Example
// takes all objects and adds a red color
const instructions = [
  { matcher: "*", modification: { color: 'red' } }
  { matcher: "name=='Joe'", mods: { gender: 'male' } }
];

const result = bulkModify(instructions, [{ color: 'yellow' }, { name: 'Joe' } ]);
// result is [{ color: 'red' }, { name: 'Joe', color: 'red', gender: 'male' } ]
Source:
See:
  • core.modify

(static) not(matcher) → {string}

Takes a matcher and returns the opposite (!) matcher.

Parameters:
Name Type Description
matcher string

valid JMESPath comparator expression

Source:

(static) search(path, data) → {*}

Performs a JMESPath lookup on the provided data.

Parameters:
Name Type Description
path string

A valid JMESPath

data *

Data to search

Source: