Socket
Book a DemoInstallSign in
Socket

expression-expander

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expression-expander

expands expressions in object graphs

latest
Source
npmnpm
Version
7.2.7
Version published
Weekly downloads
3.1K
155.1%
Maintainers
1
Weekly downloads
 
Created
Source

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 | string)? 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

Keywords

evaluate

FAQs

Package last updated on 06 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts