npm

replace-strings-in-dir

1.0.0 • Public • Published

replace_all_strings_in_directory_promise

Iterate all files in a directory async Replace all occurrences of a string with another string. Does not iterate sub_folders

NO BACKUP IS TAKEN OF YOUR FILES. THIS WILL OVERWRITE ALL EXISTING FILES IN THE SUPPLIED DIRECTORY.

NOTE "./test_folder/" in example below

How it works

It reads the directory with filestream and returns array of filenames for each filename a promise made inside a promise_all function is generated. The replacements all happen in a promise loop, this should prevent callstack errors. Once it is done it returns ana array of all modified directory+file. No report of replacements is given. But it would be easy to modify it to do so.

How to use

let replace_strings_in_dir = require("replace-strings-in-dir")
replace_strings_in_dir(
    "./test_folder/", //dont forget to make it end with '/'
    "words_to_rep",//string that you wish to replace in all the files
    "repped_words",//string that you wish to replace the previous string with
    "utf-8"//encoding i have not tested with others
).then((responses)=>{
    //returns an array of dir+filename that were saved
    console.log(responses)
}).catch((err)=>{
    //what to do if something goes wrong
    console.log(err)
})

Package Sidebar

Install

npm i replace-strings-in-dir

Weekly Downloads

0

Version

1.0.0

License

ISC

Last publish

Collaborators

  • wouldbenerd