# klei-fs

> Some nice to have addons to the native node fs module

Latest version **0.4.2** (published 2013-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install klei-fs
pnpm add klei-fs
yarn add klei-fs
bun add klei-fs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2013-06-29 |
| First published | 2013-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Joakim Bengtson |
| Maintainers | joakimbeng |
| Keywords | fs, filesystem, readdir, foreach, filter, mkdirp, mkdir |

## Links

- npm: https://www.npmjs.com/package/klei-fs
- Repository: https://github.com/klei-dev/fs
- Issues: https://github.com/klei-dev/fs/issues
- npm.io page: https://npm.io/package/klei-fs

## 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.4.2 (latest) — 2013-06-29
- 0.4.1 — 2013-06-28
- 0.4.0 — 2013-06-08
- 0.3.0 — 2013-05-04
- 0.2.0 — 2013-04-14
- 0.1.2 — 2013-04-14
- 0.1.0 — 2013-04-12

## README

# klei-fs

The `klei-fs` module contains some nice to have addons to the native node.js fs (filesystem) module.

## Installation

```bash
npm install klei-fs
```

## Usage

```javascript
var fs = require('klei-fs');

// Now you can use it as the native fs module,
// and you also have access to klei-fs own functions
```

## Functions

### forEachInDir

#### Params

 * *String* **dir** - The directory to read
 * *Function* **cb** - A callback that is called for each file in the directory, and gets following parameters:
    * *Error* **err** - An error if something went wrong, or empty if everything is ok
    * *String* **file** - The full path to the file
    * *Number* **index** - The index of the file in the files array
    * *Array* **files** - The files array, containing only the filenames and not the full paths
 * *Function* **emptyCb** - A callback that is called if the directory is empty

Reads a directory (like fs.readdir), iterates over all files and returns the full file path to the callback. (i.e. you don't have to do a `path.join(dir, file)` in order to read the file)

### filterDir

#### Params

 * *String* **dir** - The directory to read
 * *Function* **filter** - The filter method. *cb* is only called for the files where *filter* returns a thruthy value.
    * *String* **file** - The full path to the file
 * *Function* **cb** - A callback that is called for each file in the directory, and gets following parameters:
    * *Error* **err** - An error if something went wrong, or empty if everything is ok
    * *String* **file** - The full path to the file

Reads a directory (like fs.readdir), filters the files with the given *filter* function, iterates over the filtered files and returns the full file path to the callback. (i.e. you don't have to do a `path.join(dir, file)` in order to read the file)

### readJson

#### Params

 * *String* **file** - The file to read
 * *Function* **cb** - A callback that is called when the file has been read and parsed:
    * *Error* **err** - An error if something went wrong, or empty if everything is ok
    * *String* **json** - The parsed json contents of the file

### mkdirp

#### Params

 * *String* **path** - The directory path to create
 * *String* **mode** - The mode to create the dir(s) with, defaults to `0777`
 * *Function* **cb** - A callback that is called when the dir(s) have been created:
    * *Error* **err** - An error if something went wrong, or empty if everything is ok

Creates directories recursively, like `mkdir -p` in the shell.

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