From 2392096a6ae4b7c9a14e60f3f8549595e2e0ce8e Mon Sep 17 00:00:00 2001 From: "Patryk Rzucidlo (PTKDev)" Date: Tue, 12 Jun 2018 17:36:05 +0200 Subject: [PATCH] [Release] v1.0.0 --- .eslintrc.json | 46 ++++++++++++++++++++++++++++++++++ .foreverignore | 4 +++ .jshintrc | 3 +++ AUTHORS.md | 8 ++++++ CHANGELOG.md | 4 +++ INSTALL.md | 15 +++++++++++ ISSUE_TEMPLATE.md | 39 +++++++++++++++++++++++++++++ LICENSE | 6 ++--- README.md | 54 ++++++++++++++++++++++++++++++++++++++-- TODO.md | 2 ++ example/json_sample.json | 5 ++++ example/json_tokens.json | 5 ++++ example/test.js | 27 ++++++++++++++++++++ main.js | 27 ++++++++++++++++++++ package.json | 49 ++++++++++++++++++++++++++++++++++++ 15 files changed, 289 insertions(+), 5 deletions(-) create mode 100755 .eslintrc.json create mode 100644 .foreverignore create mode 100644 .jshintrc create mode 100755 AUTHORS.md create mode 100755 CHANGELOG.md create mode 100755 INSTALL.md create mode 100644 ISSUE_TEMPLATE.md mode change 100644 => 100755 README.md create mode 100755 TODO.md create mode 100644 example/json_sample.json create mode 100644 example/json_tokens.json create mode 100644 example/test.js create mode 100644 main.js create mode 100644 package.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100755 index 0000000..da87b2b --- /dev/null +++ b/.eslintrc.json @@ -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" + } +} \ No newline at end of file diff --git a/.foreverignore b/.foreverignore new file mode 100644 index 0000000..6be12e4 --- /dev/null +++ b/.foreverignore @@ -0,0 +1,4 @@ +node_modules/**/*.js +log/* +logs/* +*.log \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..53b202c --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esversion": 6 +} \ No newline at end of file diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100755 index 0000000..ef3b56c --- /dev/null +++ b/AUTHORS.md @@ -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) \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..e64ca6d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# v1.0.0 (June 12, 2018) + +* First Release. +* New: logo from [freepik](https://it.freepik.com/) (premium account) \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md new file mode 100755 index 0000000..9553cac --- /dev/null +++ b/INSTALL.md @@ -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"); +``` \ No newline at end of file diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..3bf7324 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -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. diff --git a/LICENSE b/LICENSE index 94a9ed0..f43eaf4 100644 --- a/LICENSE +++ b/LICENSE @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - Copyright (C) + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) 2017 PTKDev This program is free software: you can redistribute it and/or modify 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. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - Copyright (C) + {project} Copyright (C) 2017 Patryk Rzucidlo This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7fdc631..c5b8583 --- a/README.md +++ b/README.md @@ -1,2 +1,52 @@ -# json-token-replace -Replace token string {{hello}} in json with value from another json where key is token {"hello":"bye"} +

+ +

json-token-replace

+ +

+ + + + +

+

+ +## 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: donate on paypal or become a backer on patreon. + +For advanced configuration see [INSTALL.md](https://github.com/ptkdev/json-token-replace/blob/master/INSTALL.md). + +

License

+ +GNU GENERAL PUBLIC LICENSE + +Copyright (c) 2018 Patryk Rzucidło (PTKDev) diff --git a/TODO.md b/TODO.md new file mode 100755 index 0000000..b481d2d --- /dev/null +++ b/TODO.md @@ -0,0 +1,2 @@ +# Roadmap +Nothing diff --git a/example/json_sample.json b/example/json_sample.json new file mode 100644 index 0000000..0c83027 --- /dev/null +++ b/example/json_sample.json @@ -0,0 +1,5 @@ +{ + "text1":"i love {{fortnite}}", + "text2":"good{{hello}}", + "text3":"opensource is {{github}}" +} \ No newline at end of file diff --git a/example/json_tokens.json b/example/json_tokens.json new file mode 100644 index 0000000..c2a5bc2 --- /dev/null +++ b/example/json_tokens.json @@ -0,0 +1,5 @@ +{ + "hello":"bye", + "fortnite":"league of legends", + "github":"microsoft" +} \ No newline at end of file diff --git a/example/test.js b/example/test.js new file mode 100644 index 0000000..cfa1ce3 --- /dev/null +++ b/example/test.js @@ -0,0 +1,27 @@ +/** + * Example and Test + * ===================== + * How this utility work + * + * @author: Patryk Rzucidlo [@ptkdev] (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); \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..50f99f5 --- /dev/null +++ b/main.js @@ -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] (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; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..2990712 --- /dev/null +++ b/package.json @@ -0,0 +1,49 @@ +{ + "name": "json-token-replace", + "version": "1.0.0", + "main": "main.js", + "author": "Patryk Rzucidlo [@ptkdev] (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" + } +}