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.1.2 to 1.2.0

cleanOrphanReplaceable.d.ts

5

index.d.ts

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

export * from './variable-replacer';
export * from './replaceVars';
export * from './replaceEnv';
export * from './cleanOrphanReplaceable';
export * from './evaluateAndReplace';

@@ -17,3 +17,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./variable-replacer"), exports);
__exportStar(require("./replaceVars"), exports);
__exportStar(require("./replaceEnv"), exports);
__exportStar(require("./cleanOrphanReplaceable"), exports);
__exportStar(require("./evaluateAndReplace"), exports);
//# sourceMappingURL=index.js.map

35

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

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

"test:clear": "jest --clearCache",
"format": "prettier --write \"./{src,tests}/**/*.{ts,tsx,js,jsx,json}\""
"format": "prettier --write \"./{src,tests}/**/*.{ts,tsx,js,jsx,json}\"",
"update-dependents": "umaintenance update-dependents"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^28.1.0",
"@types/node": "^17.0.39",
"jest": "^28.1.0",
"jest-circus": "^28.1.0",
"prettier": "^2.8.7",
"ts-jest": "^28.0.4",
"typescript": "^4.7.3"
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/jest": "^29.5.5",
"@types/node": "^18.11.9",
"@universal-packages/maintenance": "^1.2.4",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"jest": {
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"testRegex": "(/tests/.*\\.test\\.ts?)$",
"preset": "ts-jest",
"collectCoverageFrom": [

@@ -38,6 +35,3 @@ "src/**/*.ts"

"setupFilesAfterEnv": [
"<rootDir>/tests/setupTests.ts"
],
"watchPathIgnorePatterns": [
"<rootDir>/tmp"
"<rootDir>/tests/setup.ts"
]

@@ -50,2 +44,5 @@ },

"trailingComma": "none",
"plugins": [
"@trivago/prettier-plugin-sort-imports"
],
"importOrder": [

@@ -52,0 +49,0 @@ "^[./]"

@@ -77,2 +77,32 @@ # Variable Replacer

#### **`evaluateAndReplace(input: string, [enclosures: [string, string]])`**
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.
```js
import { evaluateAndReplace } from '@universal-packages/variable-replacer'
const string = 'key: <% 1 + 1 %>, another: <% 2 + 2 %>'
const finalString = evaluateAndReplace(string)
console.log(finalString)
// > 'key: 2, another: 4'
```
#### Enclosures
You can provide your own enclosure characters to match for replacements.
```js
import { evaluateAndReplace } from '@universal-packages/variable-replacer'
const string = 'key: ${ 1 + 1 }$ , another: ${2+2}$'
const finalString = evaluateAndReplace(string, ['${', '}$'])
console.log(finalString)
// > 'key: 2, another: 4'
```
## Combine replacements

@@ -116,3 +146,3 @@

Same as with env you can provide your own enclosure characters to match for replacements.
You can provide your own enclosure characters to match for replacements.

@@ -127,3 +157,3 @@ ```js

// > 'key: key, another: value'
// > 'key: "", another: ""'
```

@@ -130,0 +160,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