UNPKG

@wmfs/asl-choice-processor

Version:

For determining the next state given an Amazon States Language 'Choices' definition and a set of values.

36 lines (28 loc) 645 B
'use strict' const jp = require('jsonpath') class InputValueCache { constructor () { this.cache = {} } get (inputPath, values) { if (!values) { return null } if (Object.prototype.hasOwnProperty.call(this.cache, inputPath)) { return this.cache[inputPath] } let value = jp.query(values, inputPath) if (Array.isArray(value)) { const l = value.length switch (l) { case 0: value = undefined break case 1: value = value[0] break } } this.cache[inputPath] = value return value } } // get module.exports = InputValueCache