-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"env": | ||
{ | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": | ||
{ | ||
"sourceType": "module", | ||
"ecmaVersion": 2017 | ||
}, | ||
"plugins": [ | ||
"snakecasejs" | ||
], | ||
"rules": | ||
{ | ||
"indent": [ | ||
"error", | ||
4, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"no-console": [ | ||
"warn" | ||
], | ||
"no-constant-condition": [ | ||
"warn" | ||
], | ||
"snakecasejs/snakecasejs": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/**/*.js | ||
log/* | ||
logs/* | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"esversion": 6 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Patryk Rzucidlo (@ptkdev) support@ptkdev.io | ||
[![https://ptkdev.it](https://ptkdev.it/img/ptkdev_patryk_rzucidlo_avatar_150.png)](https://ptkdev.it) | ||
|
||
`Lead Developer - June 12, 2018` | ||
* Portfolio: [https://ptkdev.it](https://ptkdev.it/) | ||
* Blog: [https://blog.ptkdev.it](https://blog.ptkdev.it) | ||
* Twitter: [https://twitter.com/ptkdev](https://twitter.com/ptkdev) | ||
* GitHub: [https://github.com/ptkdev](https://github.com/ptkdev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# v1.0.0 (June 12, 2018) | ||
|
||
* First Release. | ||
* New: logo from [freepik](https://it.freepik.com/) (premium account) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#### Setup | ||
1. Add dependencies on `package.json` | ||
``` | ||
"dependencies": { | ||
"json-token-replace": "^1.0.0", | ||
} | ||
``` | ||
|
||
2. In your code: | ||
``` | ||
const Jtr = require("json-token-replace"); | ||
const jtr = new Jtr(); | ||
let json_output = jtr.replace("./json_with_tokens.json", "./json.json"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
### Versions | ||
|
||
Replace the values below with your own: | ||
|
||
- **Version:** v1.0.0 | ||
- **Node Version:** v8.9 (Plugin require >= 7.6) | ||
- **Operating System:** Ubuntu 14.04 | ||
- **Browser:** Google Chrome 64 | ||
|
||
|
||
### Expected Behavior | ||
|
||
Please describe the program's expected behavior. | ||
|
||
``` | ||
``` | ||
|
||
### Actual Behavior | ||
|
||
Please describe the program's actual behavior. Please include any stack traces | ||
or log output in the back ticks below. | ||
|
||
``` | ||
``` | ||
|
||
### Steps to Reproduce | ||
|
||
Please include the steps the reproduce the issue, numbered below. Include as | ||
much detail as possible. | ||
|
||
1. ... | ||
2. ... | ||
3. ... | ||
|
||
### Screenshots (Optional) | ||
|
||
If the error is graphical in nature it is helpful to provide a screenshot. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,52 @@ | ||
# json-token-replace | ||
Replace token string {{hello}} in json with value from another json where key is token {"hello":"bye"} | ||
<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> | ||
|
||
<p align="center"><h1 align="center">json-token-replace</h1></p> | ||
|
||
<p align="center"><a href="#" alt="License"><img src="https://img.shields.io/badge/license-GLPv3-brightgreen.svg"></a> | ||
<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> | ||
<a href="https://slack.ptkdev.io" alt="Slack Chat"><img src="https://img.shields.io/badge/chat%20on-slack-orange.svg"></a> | ||
<a href="http://blog.ptkdev.io" alt="Blog"><img src="https://img.shields.io/badge/blog-medium-2AE176.svg"></a> | ||
<a href="https://twitter.com/ptkdevio" alt="Twitter"><img src="https://img.shields.io/badge/twitter-ptkdevio-2AA3EF.svg"></a> | ||
<a href="mailto:support@ptkdev.io" alt="Support: support@ptkdev.io"><img src="https://img.shields.io/badge/help-support@ptkdev.io-fbbc05.svg"></a></p> | ||
<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> | ||
|
||
## What does it do | ||
Replace the token string {{hello}} in json with value from another json where key is token {"hello":"bye"} | ||
|
||
#### Example: | ||
Json with tokens: | ||
`{ "john":"Alex" }` | ||
|
||
Json: | ||
`{ "text": "hello {{john}}"}` | ||
|
||
Output: | ||
`{ "text": "hello Alex"}` | ||
|
||
## Features | ||
* [✓] Easy to use | ||
|
||
## Fast setup | ||
1. Add dependencies on `package.json` | ||
``` | ||
"dependencies": { | ||
"json-token-replace": "^1.0.0", | ||
} | ||
``` | ||
2. In your code: | ||
``` | ||
const Jtr = require("json-token-replace"); | ||
const jtr = new Jtr(); | ||
let json_output = jtr.replace("./json_with_tokens.json", "./json.json"); | ||
``` | ||
3. If work add star :star: at this project :heart: | ||
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>. | ||
|
||
For advanced configuration see [INSTALL.md](https://github.com/ptkdev/json-token-replace/blob/master/INSTALL.md). | ||
|
||
<h1>License</h1> | ||
|
||
GNU GENERAL PUBLIC LICENSE | ||
|
||
Copyright (c) 2018 Patryk Rzucidło (PTKDev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Roadmap | ||
Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"text1":"i love {{fortnite}}", | ||
"text2":"good{{hello}}", | ||
"text3":"opensource is {{github}}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"hello":"bye", | ||
"fortnite":"league of legends", | ||
"github":"microsoft" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Example and Test | ||
* ===================== | ||
* How this utility work | ||
* | ||
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it) | ||
* @license: This code and contributions have 'GNU General Public License v3' | ||
* @version: 0.1 | ||
* @changelog: 0.1 initial release | ||
* | ||
*/ | ||
|
||
// If you use npm repository: require("json-token-replace"); | ||
let Jtr = require("../main"); | ||
let jtr = new Jtr(); | ||
|
||
// Import json with token<->value | ||
let json_tokens = require("./json_tokens.json"); | ||
|
||
// Import full json with token {{test}} | ||
let json_sample = require("./json_sample.json"); | ||
|
||
// This is where the magic happens | ||
let json_output = jtr.replace(json_tokens, json_sample); | ||
|
||
// Test output | ||
console.log(json_output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Utils: json-token-replace | ||
* ===================== | ||
* Replace the token string {{hello}} in json with value from another json where key is token {"hello":"bye"} | ||
* | ||
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it) | ||
* @license: This code and contributions have 'GNU General Public License v3' | ||
* @version: 0.1 | ||
* @changelog: 0.1 initial release | ||
* | ||
*/ | ||
class Utils { | ||
constructor() { | ||
|
||
} | ||
|
||
replace(json_tokens, json_input) { | ||
let json_string = JSON.stringify(json_input); | ||
for (var key in json_tokens) { | ||
json_string = json_string.replace("{{" + key + "}}", json_tokens[key]); | ||
} | ||
|
||
return JSON.parse(json_string); | ||
} | ||
} | ||
|
||
module.exports = Utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "json-token-replace", | ||
"version": "1.0.0", | ||
"main": "main.js", | ||
"author": "Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)", | ||
"license": "GPL-3.0", | ||
"homepage": "https://ptkdev.io", | ||
"bugs": { | ||
"url": "https://github.com/ptkdev/json-token-replace/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ptkdev/json-token-replace.git" | ||
}, | ||
"scripts": { | ||
"start": "node main.js", | ||
"example": "node example/test.js", | ||
"lint": "eslint ./ --cache --ignore-pattern .gitignore --fix", | ||
"precommit-lint-check": "echo 'Pre-commit lint checks...' && exit 0" | ||
}, | ||
"pre-commit": [ | ||
"precommit-lint-check", | ||
"lint" | ||
], | ||
"keywords": [ | ||
"ptkdev", | ||
"json", | ||
"token", | ||
"webtokens" | ||
], | ||
"dependencies": { | ||
"colors": "^1.2.1", | ||
"eslint": "^4.19.1", | ||
"path": "^0.12.7", | ||
"request": "^2.85.0" | ||
}, | ||
"engines": { | ||
"node": ">=7.6.0" | ||
}, | ||
"devDependencies": { | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.11.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.1.0", | ||
"eslint-plugin-snakecasejs": "^1.0.0", | ||
"pre-commit": "^1.2.2" | ||
} | ||
} |