Replace Json in file
A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.
Index
Installation
# Using npm, installing to local project npm i --save replace-js-file # Using npm, installing globally for global cli usage npm i -g replace-js-file # Using yarn yarn add replace-js-file
Basic usage
//Load the libraryconst replace = ;var path = ;var file = path; var find = "email": "type": "String" "unique": true "required": true "password": "String"; var input = "email": "type":"String""unique":true"required": true "password": "String" "usergroup": "type": "ObjectId" "ref": "group" "required": true ; ;
Asynchronous replacement with promises
;
Replacement and copy to another file
var file_output = path;;
Asynchronous replacement with promises and copy to another file
var file_output = path; ;
Return Values
When it is a promise, it returns an object with the answer, in it there are two variables, success and message.
success Initiates that everything is successful and message details the result of the operation.
When callback is used, two parameters are returned, the first is an error and the second the path of the created or modified file.
License
(MIT License)
Copyright 2019, Fabian Vargas, co-founder at Donec Lab