Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@universal-packages/variable-replacer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@universal-packages/variable-replacer - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

isolatedEval.d.ts

2

evaluateAndReplace.d.ts

@@ -1,1 +0,1 @@

export declare function evaluateAndReplace(input: string, enclosures?: [string, string]): string;
export declare function evaluateAndReplace(input: string, scope?: Record<string, any>, enclosures?: [string, string]): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluateAndReplace = void 0;
function evaluateAndReplace(input, enclosures = ['<%', '%>']) {
const isolatedEval_1 = require("./isolatedEval");
function evaluateAndReplace(input, scope = {}, enclosures = ['<%', '%>']) {
let finalValue = input;

@@ -17,3 +18,3 @@ const enclosureA = `\\${enclosures[0].split('').join('\\')}`;

const jsCode = execResult[1];
const evaluation = eval(jsCode);
const evaluation = (0, isolatedEval_1.____MMMEVALUEATE98786875674674)(jsCode, scope);
// "result is << 1 + 1 >>" --> "result is 2"

@@ -20,0 +21,0 @@ finalValue = finalValue.replace(currentMatch, evaluation);

{
"name": "@universal-packages/variable-replacer",
"version": "1.2.0",
"version": "1.3.0",
"description": "Easily inject environment variables or provided variables to compose richer strings.",

@@ -5,0 +5,0 @@ "author": "David De Anda <david@universal-packages.com> (https://github.com/universal-packages)",

@@ -77,3 +77,3 @@ # Variable Replacer

#### **`evaluateAndReplace(input: string, [enclosures: [string, string]])`**
#### **`evaluateAndReplace(input: string, scope: Object, [enclosures: [string, string]])`**

@@ -93,2 +93,17 @@ Captures what is between the enclosures and evaluates it as a JS expression. The result is then used to replace the match in the string.

#### Scope
You can provide your own scope to use in your expression.
```js
import { evaluateAndReplace } from '@universal-packages/variable-replacer'
const string = 'key: <% cpusCount / 2 %>, another: <% mem / 2 %>'
const finalString = evaluateAndReplace(string, { cpusCount: 4, mem: 16 })
console.log(finalString)
// > 'key: 2, another: 8'
```
#### Enclosures

@@ -95,0 +110,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc