7.2.4 • Published 1 month ago

expression-expander v7.2.4

Weekly downloads
1,195
License
BSD-2-Clause
Repository
github
Last release
1 month ago

npm License Typed with TypeScript bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status

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

Quoter

Type: Function

Parameters

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

  • options Object? object with the following keys

    • options.leftMarker string? lead in of expression
    • options.rightMarker string? lead out of expression
    • options.markerRegexp RegExp? expression with lead in / out
    • options.valueQuoter Quoter? to quote expanded values by default no special quoting is done and the evaluated result will be direcly inserted into the output string
    • options.evaluate Evaluator? evaluate(expression,context,path) function to evaluate expressions the default evaluation function does a lookup into the properties
    • options.keepUndefinedValues 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 20
    • options.properties Object? default properties to evaluate expression against

Returns ExpressionExpander newly created expansion context

expand

Type: Expander

Parameters

  • object
  • path (optional, default [{value:object}])

properties

Properties used for the default expander implementation

install

With npm do:

npm install expression-expander

license

BSD-2-Clause

7.2.4

1 month ago

7.2.3

2 months ago

7.2.2

2 months ago

7.2.1

2 months ago

7.2.0

2 months ago

7.1.4

2 months ago

7.1.3

1 year ago

7.1.2

1 year ago

7.1.1

2 years ago

7.0.20

2 years ago

7.1.0

2 years ago

7.0.18

2 years ago

7.0.19

2 years ago

7.0.17

2 years ago

7.0.16

2 years ago

7.0.12

2 years ago

7.0.13

2 years ago

7.0.14

2 years ago

7.0.15

2 years ago

7.0.11

3 years ago

7.0.10

3 years ago

7.0.9

3 years ago

7.0.8

3 years ago

7.0.7

3 years ago

7.0.6

4 years ago

7.0.5

4 years ago

7.0.4

4 years ago

7.0.3

5 years ago

7.0.2

5 years ago

7.0.1

5 years ago

7.0.0

5 years ago

6.2.0

5 years ago

6.1.3

5 years ago

6.1.2

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.0.1

6 years ago

6.0.0

7 years ago

5.3.11

7 years ago

5.3.10

7 years ago

5.3.9

7 years ago

5.3.8

7 years ago

5.3.7

7 years ago

5.3.6

7 years ago

5.3.5

7 years ago

5.3.4

7 years ago

5.3.3

7 years ago

5.3.2

7 years ago

5.3.1

7 years ago

5.3.0

7 years ago

5.2.10

7 years ago

5.2.9

7 years ago

5.2.8

7 years ago

5.2.7

7 years ago

5.2.6

7 years ago

5.2.5

7 years ago

5.2.4

7 years ago

5.2.3

7 years ago

5.2.2

7 years ago

5.2.1

7 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.0

9 years ago

2.0.0

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago