🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

json-sub

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-sub - npm Package Compare versions

Comparing version

to
1.1.0

1.0.0 / 2016-03-23
==================
* Initial version
* Initial version
1.1.0 / 2016-03-31
==================
* Add Synchronous method

@@ -1,14 +0,40 @@

/**
* Replace Placeholders in any JSON
* @param json {Object}
* @param varibles {Object}
* @param callback {Function}
**/
function jsonSub (json, variables, callback) {
var str = JSON.stringify(json);
var output = str.replace(/\{{\w+}}/g, function(found) {
return variables[found] || found;
});
function jsonSub() {
/**
* Replace Placeholders in any JSON
* @param json {Object}
* @param variables {Object}
* @param callback {Function}
**/
var substitute = function (json, variables, callback) {
var str = JSON.stringify(json);
var output = str.replace(/\{{\w+}}/g, function(found) {
return variables[found] || found;
});
callback(JSON.parse(output));
callback(JSON.parse(output));
}
/**
* Replace Placeholders in any JSON
* Synchronous mode
* @param json {Object}
* @param variables {Object}
* return {Object}
**/
substituteSync = function (json, variables) {
var str = JSON.stringify(json);
var output = str.replace(/\{{\w+}}/g, function(found) {
return variables[found] || found;
});
return JSON.parse(output);
}
return {
substitute : substitute,
substituteSync : substituteSync
}
}

@@ -15,0 +41,0 @@

{
"name": "json-sub",
"version": "1.0.0",
"description": "Substitute placeholders in json.",
"version": "1.1.0",
"description": "Substitute placeholders in json Objects.",
"main": "index.js",
"keywords": ["json", "placeholder", "substitute", "replace", "regular expression", "regex"],
"keywords": ["json", "placeholder", "substitute", "replace", "regular expression", "regex", "sync"],
"scripts": {

@@ -8,0 +8,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

@@ -15,3 +15,3 @@ #jsonSub

```js
var jsonSub = require('json-sub');
var jsonSub = require('json-sub')();

@@ -36,2 +36,19 @@ var json = [{

});
```
// OUTPUTS
/* [
{ method: 'get', path: '/reports/mc1234567d/members' },
{ method: 'get', path: '/city/76890/turnover' }
] */
```
### Synchronous Method
```js
var jsonSub = require('json-sub')();
// In Synchronous mode
var result = jsonSub.SubSync(json, variables);
```