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

@banjoanton/replacer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@banjoanton/replacer

Simple API to replace text in multiple text files.

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

replacer

Simple API to replace text in multiple text files.

  • Using globby to find files
  • Edit by full file output
  • Edit by line
  • Overwrites to file when the changes are commited.

Get started

npm i @banjoanton/replacer
import { replacer } from "@banjoanton/replacer";

const { handleFiles, handleLines, commit } = await replacer(["/path/to/file", "/path/to/another/file"]);

// loop through each file
handleFiles(({ replace, replaceAll, output, filePath }) => {
    console.log(output);        // file output
    console.log(filePath);      // file path

    replace("oldValue", "newValue");        // replace first occurrence
    replaceAll("oldValue", "newValue")      // replace all occurrences 
});

handleLines(({replace, replaceAll, replaceWhole, output, filePath, line, lineNumber}) => {
    console.log(output);        // file output
    console.log(filePath);      // file path
    console.log(line);          // line content
    console.log(lineNumber);    // line number

    replace("oldValue", "newValue");        // replace first occurrence
    replaceAll("oldValue", "newValue")      // replace all occurrences  
    replaceWhole("newValue")                // replace whole line  
})

await commit(); // commit all changes to file

FAQs

Package last updated on 21 Dec 2022

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