expression-expander v7.2.5
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)
example
file.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
{ "simple": "aValue", "complex": { "a": 1, "b": 2 } }Any Object of the following types may be expanded
- String
- Number
- BigInt
- Buffer
- Object (key and value will be expanded)
- Array
- Map (key and value will be expanded)
- Set
- Boolean
- Promise
API
Table of Contents
Evaluator
Type: Function
Parameters
Returns Object expression evaluation result
PathEntry
Type: Object
Properties
valueObject
Quoter
Type: Function
Parameters
valuestring to be quoted
Returns string quoted value
Expander
Type: Function
Parameters
Returns (string | boolean | number | bigint | Object | Map | Set) expression evaluation result
ExpressionExpander
Type: Object
Properties
createContext
Creates a new expansion context
Parameters
optionsObject? object with the following keysoptions.leftMarkerstring? lead in of expressionoptions.rightMarkerstring? lead out of expressionoptions.markerRegexpRegExp? expression with lead in / outoptions.valueQuoterQuoter? to quote expanded values by default no special quoting is done and the evaluated result will be direcly inserted into the output stringoptions.evaluateEvaluator? evaluate(expression,context,path) function to evaluate expressions the default evaluation function does a lookup into the propertiesoptions.keepUndefinedValuesboolean? true: is expression resolves to undefind the original string will be used (with surrounding ${})options.maxNestingLevelnumber? max number of recursive calls to expand defaults to 20options.propertiesObject? default properties to evaluate expression against
Returns ExpressionExpander newly created expansion context
expand
Type: Expander
Parameters
objectpath(optional, default[{value:object}])
properties
Properties used for the default expander implementation
install
With npm do:
npm install expression-expanderlicense
BSD-2-Clause
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago