New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

replace-js-file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace-js-file

A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Replace Json in file

A simple utility to quickly replace the contents of text blocks in Json format within JavaScript files.

Index

  • Instalation
  • Basic usage
  • Return Values
  • License

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 library
const replace = require('replace-js-file');
var path = require("path");
var file = path.join(__dirname,'<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
    }
};

replace(file,find,input,function(err,file_path){
   console.log("path: ",file_path); 
});

Asynchronous replacement with promises


replace(file,find,input)
.then(response => {
    console.log(response.message);
}, err => {
    console.log(err.message);
});

Replacement and copy to another file


var file_output = path.join(__dirname,'<FILE_PATH>');
replace(file,find,input,file_output,function(err,file_path){
   console.log("path: ",file_path); 
});

Asynchronous replacement with promises and copy to another file


var file_output = path.join(__dirname,'<FILE_PATH>');

replace(file,find,input,file_output)
.then(response => {
    console.log(response.message);
}, err => {
    console.log(err.message);
});
    

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

Keywords

replace

FAQs

Package last updated on 19 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts