# @web-stack/fsu

> File update utility to edit and write back the file at same path

Latest version **0.0.4** (published 2020-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @web-stack/fsu
pnpm add @web-stack/fsu
yarn add @web-stack/fsu
bun add @web-stack/fsu
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-03-27 |
| First published | 2020-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.18 |
| Dependencies | 2 |
| Unpacked size | 4.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | WebStack |
| Maintainers | abhijeetkpawar |
| Keywords | fsu, file |

## Links

- npm: https://www.npmjs.com/package/@web-stack/fsu
- Repository: https://github.com/web-stack/fsu
- Homepage: https://github.com/web-stack/fsu#readme
- Issues: https://github.com/web-stack/fsu/issues
- npm.io page: https://npm.io/package/@web-stack/fsu

## Dependencies (2)

- [globby](https://npm.io/package/globby.md) ^11.0.0
- [normalize-path](https://npm.io/package/normalize-path.md) ^3.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2020-03-27
- 0.0.3 — 2020-03-18
- 0.0.2 — 2020-03-17
- 0.0.1 — 2020-03-16

## README

# fsu - File Update utility

## Installation

```
npm install @web-stack/fsu
```

## Usage

```
const fsu = require('@web-stack/fsu');

fsu.update(patterns, (content) => {
  // Manke changes to content
  return content;
});
```

## API

### `update(patterns, modifier)`

Updates the file by applying the modifications to content and writes back to same path.
It accepts glob pattern to modify multiple files in one command. 

Returns: `Promise`

#### patterns

Type: `string | string[]`

See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).

#### modifier

Type: `function`

Parameters:
  * `content`: Contents of file as `string`

Returns: `string`

Modifier function has one argument passed - `contents` of the file. This function should return the modified contents as string.


### `updateSync(patterns, modifier)`

This is synchronous variant of `update()`.

## Example

This utility can covert 
 
```   
const files = globby.sync(path.join(__dirname, 'config*.js'));

files.forEach(file => {
  let cnt = fs.readFileSync(file, 'utf8');
  cnt = cnt.replace('"${ENV}"', 'prod');
  fs.writeFileSync(file, cnt, 'utf8');
});
```
to

```
fsu.updateSync(path.join(__dirname, 'config*.js'), c => c.replace('${ENV}', 'prod'));
```

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