Skip to content

Commit 944cda1

Browse files
committed
[Release] v1.1.0
1 parent ffbe0f1 commit 944cda1

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v1.1.0 (July 04, 2018)
2+
3+
* Feature: start string and end string params
4+
5+
16
# v1.0.1 (June 29, 2018)
27

38
* Update: README.md

INSTALL.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#### Setup
2-
1. Add dependencies on `package.json`
3-
```
4-
"dependencies": {
5-
"json-token-replace": "^1.0.0",
6-
}
7-
```
8-
2+
1. Run `npm install json-token-replace --save`
93
2. In your code:
104
```
115
const Jtr = require("json-token-replace");
126
const jtr = new Jtr();
137
14-
let json_output = jtr.replace("./json_with_tokens.json", "./json.json");
8+
let json_output = jtr.replace(require("./json_with_tokens.json"), require("./json.json"), "{{", "}}");
159
```

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<p align="center"><h1 align="center">json-token-replace</h1></p>
44

55
<p align="center"><a href="#" alt="License"><img src="https://img.shields.io/badge/license-GLPv3-brightgreen.svg"></a>
6-
<a href="https://github.com/ptkdev/json-token-replace/releases" alt="Version"><img src="https://img.shields.io/badge/version-v1.0.1-lightgrey.svg"></a>
6+
<a href="https://github.com/ptkdev/json-token-replace/releases" alt="Version"><img src="https://img.shields.io/badge/version-v1.1.0-lightgrey.svg"></a>
77
<a href="https://slack.ptkdev.io" alt="Slack Chat"><img src="https://img.shields.io/badge/chat%20on-slack-orange.svg"></a>
88
<a href="http://blog.ptkdev.io" alt="Blog"><img src="https://img.shields.io/badge/blog-medium-2AE176.svg"></a>
99
<a href="https://twitter.com/ptkdevio" alt="Twitter"><img src="https://img.shields.io/badge/twitter-ptkdevio-2AA3EF.svg"></a>
@@ -34,7 +34,7 @@ Output:
3434
const Jtr = require("json-token-replace");
3535
const jtr = new Jtr();
3636
37-
let json_output = jtr.replace(require("./json_with_tokens.json"), require("./json.json"));
37+
let json_output = jtr.replace(require("./json_with_tokens.json"), require("./json.json"), "{{", "}}");
3838
```
3939
3. If work add star :star: at this project :heart:
4040
4. If you want help me: <b><a href="http://paypal.ptkdev.io">donate on paypal</a></b> or become a <b><a href="http://patreon.ptkdev.io">backer on patreon</a></b>.

example/test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*
66
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)
77
* @license: This code and contributions have 'GNU General Public License v3'
8-
* @version: 0.1
9-
* @changelog: 0.1 initial release
8+
* @version: 1.0.0
9+
* @changelog: 1.0.0 initial release
10+
* 1.1.0 start and end tokens string
1011
*
1112
*/
1213

@@ -21,7 +22,7 @@ let json_tokens = require("./json_tokens.json");
2122
let json_sample = require("./json_sample.json");
2223

2324
// This is where the magic happens
24-
let json_output = jtr.replace(json_tokens, json_sample);
25+
let json_output = jtr.replace(json_tokens, json_sample, "{{", "}}");
2526

2627
// Test output
2728
console.log(json_output);

main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
*
66
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)
77
* @license: This code and contributions have 'GNU General Public License v3'
8-
* @version: 0.1
9-
* @changelog: 0.1 initial release
8+
* @version: 1.0.0
9+
* @changelog: 1.0.0 initial release
10+
* 1.1.0 start and end tokens string
1011
*
1112
*/
1213
class Utils {
1314
constructor() {
1415

1516
}
1617

17-
replace(json_tokens, json_input) {
18+
replace(json_tokens, json_input, start = "{{", end = "}}") {
1819
let json_string = JSON.stringify(json_input);
1920
for (var key in json_tokens) {
20-
json_string = json_string.replace("{{" + key + "}}", json_tokens[key]);
21+
let regex = new RegExp(start + key + end,"g");
22+
json_string = json_string.replace(regex, json_tokens[key]);
2123
}
2224

2325
return JSON.parse(json_string);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "json-token-replace",
33
"description": "Replace the token string {{hello}} in json with value from another json where key is token {\"hello\":\"bye\"}",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"main": "main.js",
66
"author": "Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)",
77
"license": "GPL-3.0",

0 commit comments

Comments
 (0)