expands expressions in object graphs
npm install expression-expander










Expands \\${to be evaluated} expressions in object graphs. The actual expression syntax inside of the \\${evaluated} is not defined within this module (only simple key lookup)
``js
import { createContext } from "expression-expander";
const context = createContext();
context.properties = { aKey: "aValue", moreKeys: { a: 1, b: 2 } };
// expanding whole expressions at the key position
console.log(
JSON.stringify(
context.expand({ simple: "${aKey}", complex: { "${moreKeys}": {} } })
)
);
`
Output
`json`
{ "simple": "aValue", "complex": { "a": 1, "b": 2 } }
* String
* Number
* BigInt
* Buffer
* Object (key and value will be expanded)
* Array
* Map (key and value will be expanded)
* Set
* Boolean
* Promise
* Evaluator
* Parameters
* PathEntry
* Properties
* Quoter
* Parameters
* Expander
* Parameters
* ExpressionExpander
* Properties
* createContext
* Parameters
* expand
* Parameters
* properties
Type: Function
* expression string context
* Object path
* \[PathEntry]
Returns Object expression evaluation result
Type: Object
* value Object
Type: Function
* value string to be quoted
Returns string quoted value
Type: Function
* value (string | boolean | number | bigint | Object | Map | Set) path
* Array<PathEntry>?
Returns (string | boolean | number | bigint | Object | Map | Set) expression evaluation result
Type: Object
* properties Object expand
* Expander
Creates a new expansion context
* options Object? object with the following keys
* options.leftMarker string? lead in of expressionoptions.rightMarker
* string? lead out of expressionoptions.markerRegexp
* (RegExp | string)? expression with lead in / outoptions.valueQuoter
* Quoter? to quote expanded valuesoptions.evaluate
by default no special quoting is done and the evaluated result will be direcly
inserted into the output string
* Evaluator? evaluate(expression,context,path) function to evaluate expressionsoptions.keepUndefinedValues
the default evaluation function does a lookup into the properties
* boolean? true: is expression resolves to undefind the original string will be used (with surrounding ${})options.maxNestingLevel
* number? max number of recursive calls to expand defaults to 20options.properties
* Object? default properties to evaluate expression against
Returns ExpressionExpander newly created expansion context
Type: Expander
* object path
* (optional, default [{value:object}])
Properties used for the default expander implementation
With npm do:
`shell``
npm install expression-expander
BSD-2-Clause