Skip to content

Commit 2392096

Browse files
committed
[Release] v1.0.0
1 parent 2e759b8 commit 2392096

15 files changed

+289
-5
lines changed

.eslintrc.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"env":
3+
{
4+
"browser": true,
5+
"es6": true,
6+
"node": true
7+
},
8+
"extends": "eslint:recommended",
9+
"parserOptions":
10+
{
11+
"sourceType": "module",
12+
"ecmaVersion": 2017
13+
},
14+
"plugins": [
15+
"snakecasejs"
16+
],
17+
"rules":
18+
{
19+
"indent": [
20+
"error",
21+
4,
22+
{
23+
"SwitchCase": 1
24+
}
25+
],
26+
"linebreak-style": [
27+
"error",
28+
"unix"
29+
],
30+
"quotes": [
31+
"error",
32+
"double"
33+
],
34+
"semi": [
35+
"error",
36+
"always"
37+
],
38+
"no-console": [
39+
"warn"
40+
],
41+
"no-constant-condition": [
42+
"warn"
43+
],
44+
"snakecasejs/snakecasejs": "warn"
45+
}
46+
}

.foreverignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/**/*.js
2+
log/*
3+
logs/*
4+
*.log

.jshintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"esversion": 6
3+
}

AUTHORS.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Patryk Rzucidlo (@ptkdev) [email protected]
2+
[![https://ptkdev.it](https://ptkdev.it/img/ptkdev_patryk_rzucidlo_avatar_150.png)](https://ptkdev.it)
3+
4+
`Lead Developer - June 12, 2018`
5+
* Portfolio: [https://ptkdev.it](https://ptkdev.it/)
6+
* Blog: [https://blog.ptkdev.it](https://blog.ptkdev.it)
7+
* Twitter: [https://twitter.com/ptkdev](https://twitter.com/ptkdev)
8+
* GitHub: [https://github.com/ptkdev](https://github.com/ptkdev)

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# v1.0.0 (June 12, 2018)
2+
3+
* First Release.
4+
* New: logo from [freepik](https://it.freepik.com/) (premium account)

INSTALL.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#### Setup
2+
1. Add dependencies on `package.json`
3+
```
4+
"dependencies": {
5+
"json-token-replace": "^1.0.0",
6+
}
7+
```
8+
9+
2. In your code:
10+
```
11+
const Jtr = require("json-token-replace");
12+
const jtr = new Jtr();
13+
14+
let json_output = jtr.replace("./json_with_tokens.json", "./json.json");
15+
```

ISSUE_TEMPLATE.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Versions
2+
3+
Replace the values below with your own:
4+
5+
- **Version:** v1.0.0
6+
- **Node Version:** v8.9 (Plugin require >= 7.6)
7+
- **Operating System:** Ubuntu 14.04
8+
- **Browser:** Google Chrome 64
9+
10+
11+
### Expected Behavior
12+
13+
Please describe the program's expected behavior.
14+
15+
```
16+
17+
```
18+
19+
### Actual Behavior
20+
21+
Please describe the program's actual behavior. Please include any stack traces
22+
or log output in the back ticks below.
23+
24+
```
25+
26+
```
27+
28+
### Steps to Reproduce
29+
30+
Please include the steps the reproduce the issue, numbered below. Include as
31+
much detail as possible.
32+
33+
1. ...
34+
2. ...
35+
3. ...
36+
37+
### Screenshots (Optional)
38+
39+
If the error is graphical in nature it is helpful to provide a screenshot.

LICENSE

+3-3
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
631631
state the exclusion of warranty; and each file should have at least
632632
the "copyright" line and a pointer to where the full notice is found.
633633

634-
<one line to give the program's name and a brief idea of what it does.>
635-
Copyright (C) <year> <name of author>
634+
{one line to give the program's name and a brief idea of what it does.}
635+
Copyright (C) 2017 PTKDev
636636

637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
652652
If the program does terminal interaction, make it output a short
653653
notice like this when it starts in an interactive mode:
654654

655-
<program> Copyright (C) <year> <name of author>
655+
{project} Copyright (C) 2017 Patryk Rzucidlo
656656
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657
This is free software, and you are welcome to redistribute it
658658
under certain conditions; type `show c' for details.

README.md

100644100755
+52-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# json-token-replace
2-
Replace token string {{hello}} in json with value from another json where key is token {"hello":"bye"}
1+
<p align="center"><a href="https://www.npmjs.com/package/json-token-replace" alt="Logo"><img src="https://ptkdev.it/img/github/json-token-replace.png"></a></p>
2+
3+
<p align="center"><h1 align="center">json-token-replace</h1></p>
4+
5+
<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.0-lightgrey.svg"></a>
7+
<a href="https://slack.ptkdev.io" alt="Slack Chat"><img src="https://img.shields.io/badge/chat%20on-slack-orange.svg"></a>
8+
<a href="http://blog.ptkdev.io" alt="Blog"><img src="https://img.shields.io/badge/blog-medium-2AE176.svg"></a>
9+
<a href="https://twitter.com/ptkdevio" alt="Twitter"><img src="https://img.shields.io/badge/twitter-ptkdevio-2AA3EF.svg"></a>
10+
<a href="mailto:[email protected]" alt="Support: [email protected]"><img src="https://img.shields.io/badge/[email protected]"></a></p>
11+
<p align="center"><a href="http://patreon.ptkdev.io" alt="Patreon Backer"><img src="https://img.shields.io/badge/donate-patreon-F87668.svg"></a> <a href="http://paypal.ptkdev.io" alt="Paypale Donate"><img src="https://img.shields.io/badge/donate-paypal-46AFE0.svg"></a></p>
12+
13+
## What does it do
14+
Replace the token string {{hello}} in json with value from another json where key is token {"hello":"bye"}
15+
16+
#### Example:
17+
Json with tokens:
18+
`{ "john":"Alex" }`
19+
20+
Json:
21+
`{ "text": "hello {{john}}"}`
22+
23+
Output:
24+
`{ "text": "hello Alex"}`
25+
26+
## Features
27+
* [] Easy to use
28+
29+
## Fast setup
30+
1. Add dependencies on `package.json`
31+
```
32+
"dependencies": {
33+
"json-token-replace": "^1.0.0",
34+
}
35+
```
36+
2. In your code:
37+
```
38+
const Jtr = require("json-token-replace");
39+
const jtr = new Jtr();
40+
41+
let json_output = jtr.replace("./json_with_tokens.json", "./json.json");
42+
```
43+
3. If work add star :star: at this project :heart:
44+
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>.
45+
46+
For advanced configuration see [INSTALL.md](https://github.com/ptkdev/json-token-replace/blob/master/INSTALL.md).
47+
48+
<h1>License</h1>
49+
50+
GNU GENERAL PUBLIC LICENSE
51+
52+
Copyright (c) 2018 Patryk Rzucidło (PTKDev)

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Roadmap
2+
Nothing

example/json_sample.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"text1":"i love {{fortnite}}",
3+
"text2":"good{{hello}}",
4+
"text3":"opensource is {{github}}"
5+
}

example/json_tokens.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hello":"bye",
3+
"fortnite":"league of legends",
4+
"github":"microsoft"
5+
}

example/test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Example and Test
3+
* =====================
4+
* How this utility work
5+
*
6+
* @author: Patryk Rzucidlo [@ptkdev] <[email protected]> (https://ptkdev.it)
7+
* @license: This code and contributions have 'GNU General Public License v3'
8+
* @version: 0.1
9+
* @changelog: 0.1 initial release
10+
*
11+
*/
12+
13+
// If you use npm repository: require("json-token-replace");
14+
let Jtr = require("../main");
15+
let jtr = new Jtr();
16+
17+
// Import json with token<->value
18+
let json_tokens = require("./json_tokens.json");
19+
20+
// Import full json with token {{test}}
21+
let json_sample = require("./json_sample.json");
22+
23+
// This is where the magic happens
24+
let json_output = jtr.replace(json_tokens, json_sample);
25+
26+
// Test output
27+
console.log(json_output);

main.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Utils: json-token-replace
3+
* =====================
4+
* Replace the token string {{hello}} in json with value from another json where key is token {"hello":"bye"}
5+
*
6+
* @author: Patryk Rzucidlo [@ptkdev] <[email protected]> (https://ptkdev.it)
7+
* @license: This code and contributions have 'GNU General Public License v3'
8+
* @version: 0.1
9+
* @changelog: 0.1 initial release
10+
*
11+
*/
12+
class Utils {
13+
constructor() {
14+
15+
}
16+
17+
replace(json_tokens, json_input) {
18+
let json_string = JSON.stringify(json_input);
19+
for (var key in json_tokens) {
20+
json_string = json_string.replace("{{" + key + "}}", json_tokens[key]);
21+
}
22+
23+
return JSON.parse(json_string);
24+
}
25+
}
26+
27+
module.exports = Utils;

package.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "json-token-replace",
3+
"version": "1.0.0",
4+
"main": "main.js",
5+
"author": "Patryk Rzucidlo [@ptkdev] <[email protected]> (https://ptkdev.it)",
6+
"license": "GPL-3.0",
7+
"homepage": "https://ptkdev.io",
8+
"bugs": {
9+
"url": "https://github.com/ptkdev/json-token-replace/issues"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/ptkdev/json-token-replace.git"
14+
},
15+
"scripts": {
16+
"start": "node main.js",
17+
"example": "node example/test.js",
18+
"lint": "eslint ./ --cache --ignore-pattern .gitignore --fix",
19+
"precommit-lint-check": "echo 'Pre-commit lint checks...' && exit 0"
20+
},
21+
"pre-commit": [
22+
"precommit-lint-check",
23+
"lint"
24+
],
25+
"keywords": [
26+
"ptkdev",
27+
"json",
28+
"token",
29+
"webtokens"
30+
],
31+
"dependencies": {
32+
"colors": "^1.2.1",
33+
"eslint": "^4.19.1",
34+
"path": "^0.12.7",
35+
"request": "^2.85.0"
36+
},
37+
"engines": {
38+
"node": ">=7.6.0"
39+
},
40+
"devDependencies": {
41+
"eslint-config-standard": "^11.0.0",
42+
"eslint-plugin-import": "^2.11.0",
43+
"eslint-plugin-node": "^6.0.1",
44+
"eslint-plugin-promise": "^3.7.0",
45+
"eslint-plugin-standard": "^3.1.0",
46+
"eslint-plugin-snakecasejs": "^1.0.0",
47+
"pre-commit": "^1.2.2"
48+
}
49+
}

0 commit comments

Comments
 (0)