# @banjoanton/replacer

> Simple API to replace text in multiple text files.

Latest version **0.0.2** (published 2022-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @banjoanton/replacer
pnpm add @banjoanton/replacer
yarn add @banjoanton/replacer
bun add @banjoanton/replacer
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2022-12-21 |
| First published | 2022-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anton Ödman |
| Maintainers | banjoanton |

## Links

- npm: https://www.npmjs.com/package/@banjoanton/replacer
- Repository: https://github.com/banjo/replacer
- Homepage: https://github.com/banjo/replacer#readme
- Issues: https://github.com/banjo/replacer/issues
- npm.io page: https://npm.io/package/@banjoanton/replacer

## Dependencies (1)

- [globby](https://npm.io/package/globby.md) ^13.1.3

## Recent versions

- 0.0.2 (latest) — 2022-12-21
- 0.0.1 — 2022-12-21

## README

# 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

```ts
npm i @banjoanton/replacer
```

```ts
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
```

---
_Source: https://npm.io/package/@banjoanton/replacer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
