# ezs

> A wrapper to build Stream transformers with functional style

Latest version **9.4.2** (published 2019-07-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ezs
pnpm add ezs
yarn add ezs
bun add ezs
```

Provides the command `ezs`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 9.4.2 |
| Published | 2019-07-25 |
| First published | 2017-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 179.4 KB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| Author | Nicolas Thouvenin |
| Maintainers | touv |
| Keywords | stream, transformer |

## Links

- npm: https://www.npmjs.com/package/ezs
- Repository: https://github.com/touv/node-ezs
- Homepage: https://github.com/touv/node-ezs#readme
- Issues: https://github.com/touv/node-ezs/issues
- npm.io page: https://npm.io/package/ezs

## Dependencies (19)

- [debug](https://npm.io/package/debug.md) ~4.1.1
- [yargs](https://npm.io/package/yargs.md) ~13.3.0
- [lodash](https://npm.io/package/lodash.md) ~4.17.15
- [merge2](https://npm.io/package/merge2.md) ~1.2.3
- [mkdirp](https://npm.io/package/mkdirp.md) ~0.5.1
- [cacache](https://npm.io/package/cacache.md) ~12.0.0
- [filtrex](https://npm.io/package/filtrex.md) ~1.0.0
- [notevil](https://npm.io/package/notevil.md) ~1.3.1
- [autocast](https://npm.io/package/autocast.md) ~0.0.4
- [node-dir](https://npm.io/package/node-dir.md) ~0.1.17
- [validatorjs](https://npm.io/package/validatorjs.md) ~3.15.1
- [stream-write](https://npm.io/package/stream-write.md) ~1.0.1
- [http-shutdown](https://npm.io/package/http-shutdown.md) ~1.2.1
- [filename-regex](https://npm.io/package/filename-regex.md) ~2.0.1
- [stream-iterate](https://npm.io/package/stream-iterate.md) ~1.2.0
- [app-module-path](https://npm.io/package/app-module-path.md) ~2.2.0
- [concurrent-queue](https://npm.io/package/concurrent-queue.md) ~7.0.2
- [deep-object-diff](https://npm.io/package/deep-object-diff.md) ~1.1.0
- [node-object-hash](https://npm.io/package/node-object-hash.md) ~1.4.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 9.4.2 (latest) — 2019-07-25
- 9.4.1 — 2019-07-24
- 9.4.0 — 2019-07-23
- 9.3.1 — 2019-05-20
- 9.3.0 — 2019-05-08
- 9.2.0 — 2019-04-26
- 9.1.0 — 2019-03-26
- 9.0.2 — 2019-03-23
- 9.0.1 — 2019-03-22
- 9.0.0 — 2019-03-20
- 8.1.2 — 2019-03-18
- 8.1.1 — 2019-03-18
- 8.1.0 — 2019-03-15
- 8.0.3 — 2019-03-10
- 8.0.2 — 2019-02-28
- … 78 more at https://npm.io/package/ezs/versions

## README

# Make pipeline of streams easy : Easy Streams

[![Build Status](https://travis-ci.org/touv/node-ezs.png?branch=master)](https://travis-ci.org/touv/node-ezs)
[![npm version](https://img.shields.io/npm/v/ezs.svg)](https://npm.im/ezs)
[![license](https://img.shields.io/npm/l/ezs.svg)](https://npm.im/ezs)
[![Coverage Status](https://coveralls.io/repos/github/touv/node-ezs/badge.svg?branch=master)](https://coveralls.io/github/touv/node-ezs?branch=master)

It's just a wrapper to build Stream transformers with functional style. It's like the koa / expressjs middlewares !

# Example

```javascript
const ezs = require('ezs')

ezs.use(require('ezs-basics'));

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin
  .pipe(ezs('split', { delimiter: "\n" }))
  .pipe(ezs('counter'))
  .pipe(ezs((input, output) => output.send(input.toString()));
  .pipe(process.stdout);
```

# Installation

With [npm](http://npmjs.org):

    $ npm install ezs

# Concepts

### Scope

Each statement function have its own scope and can access to few methods :

-   this.isLast()
-   this.isFirst()
-   this.getIndex()
-   this.getParam(name, defaultValue)

### Output Object

Output object is an object with few methods :

-   output.write(something)
-   output.end()
-   output.send(something)
-   output.close()
-   output.stop(withAnError)

With a sync statement, you can break the pipe  with throw but with an async statement, you should use `stop(with An Error)` instead of throw.

# CLI

The command line interface is used to create run pipelines described in .ini files.

It is also possible to launch a web server allowing remote execution of .ini files

    $ ezs -h                                                                                                                                                                   ven. 15 mars 2019 16:15:20 CET
    Usage: ezs [options] [<file>|<directory>] [<file2> <file3> ...]

    Options:
      --help         Affiche de l'aide                                     [booléen]
      --version      Affiche le numéro de version                          [booléen]
      --verbose, -v  Enable debug mode with DEBUG=ezs      [booléen] [défaut: false]
      --daemon, -d   Launch daemon on a directory containing commands script
                                                               [chaine de caractère]
      --server, -s   Server to dispach commands                [chaine de caractère]
      --env, -e      Execute commands with environement variables as input
                                                           [booléen] [défaut: false]

    for more information, find our manual at https://github.com/touv/node-ezs

# API Documentation

## ezs(statement : Mixed, [params : Object]) : Stream

Converts a transform stream with existing function or adhoc function.

```javascript
	const ezs = require('ezs'),
	let transformer = ezs(function(input, output) {
		output.send(input.toString())
	})
```

## ezs.use(module: Function) : None

Adding bundle of statements. see the avaible modules here : <https://www.npmjs.com/browse/keyword/ezs>

```javascript
	import ezs from 'ezs';
	import basics from 'ezs-basics';
	import files from 'ezs-files';

	ezs.use(basics);
	ezs.use(files);
```

## ezs.catch(func : Function)

catch Error in NodeJS pipeline

```javascript
    // Example #1
    process.stdin
        .pipe(ezs('truncate', { length: 100 }))
        .pipe(ezs((d, f) => f.send(new Error('Badaboum')))))
        .pipe(ezs.catch(e => e)) // catch errors in chunks and throw a error, which breaking the pipeline
        .on('error', console.error)

    // Example #2
    process.stdin
        .pipe(ezs('truncate', { length: 100 }))
        .pipe(ezs((d, f) => f.send(new Error('Badaboum')))))
        .pipe(ezs.catch(e => console.error('Warning:', e))) // catch errors in chunks to display them without breaking the pipeline
```

## ezs.toBuffer(options : Object)

get chunk of in NodeJS pipeline and send Buffer of the chunk

```javascript
    process.stdin
        .pipe(ezs('replace', { path: 'id', value: 'xxxxx' }))
        .pipe(ezs('dump'))
        .pipe(ezs.toBuffer())
        .pipe(process.stdout);
```

# Statements

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [assign](#assign)
    -   [Parameters](#parameters)
-   [concat](#concat)
    -   [Parameters](#parameters-1)
-   [debug](#debug)
    -   [Parameters](#parameters-2)
-   [delegate](#delegate)
    -   [Parameters](#parameters-3)
-   [dispatch](#dispatch)
    -   [Parameters](#parameters-4)
-   [dump](#dump)
    -   [Parameters](#parameters-5)
-   [env](#env)
    -   [Parameters](#parameters-6)
-   [extract](#extract)
    -   [Parameters](#parameters-7)
-   [group](#group)
    -   [Parameters](#parameters-8)
-   [keep](#keep)
    -   [Parameters](#parameters-9)
-   [pack](#pack)
    -   [Parameters](#parameters-10)
-   [replace](#replace)
    -   [Parameters](#parameters-11)
-   [shift](#shift)
    -   [Parameters](#parameters-12)
-   [shuffle](#shuffle)
    -   [Parameters](#parameters-13)
-   [tracer](#tracer)
    -   [Parameters](#parameters-14)
-   [transit](#transit)
    -   [Parameters](#parameters-15)
-   [truncate](#truncate)
    -   [Parameters](#parameters-16)
-   [ungroup](#ungroup)
    -   [Parameters](#parameters-17)
-   [unpack](#unpack)
    -   [Parameters](#parameters-18)
-   [validate](#validate)
    -   [Parameters](#parameters-19)

## assign

Take `Object` and add new field

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the new field
-   `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** value of the new field

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## concat

Take all `String`, concat them and thow just one

### Parameters

-   `data`  
-   `feed`  
-   `beginWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Add value at the begin
-   `joinWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** use value to join 2 chunk
-   `endWith` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Add value at the end

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## debug

Take `Object` , print it and throw the same object

### Parameters

-   `data`  
-   `feed`  
-   `level` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** console level : log or error (optional, default `log`)
-   `text` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** text before the dump (optional, default `valueOf`)
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of field to print

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## delegate

Takes an `Object` delegate processing to an external pipeline

### Parameters

-   `data`  
-   `feed`  
-   `file` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in a file
-   `script` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in a sting of characters
-   `commands` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in object

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## dispatch

Takes an `Object` dispatch processing to an external pipeline in one or more servers

### Parameters

-   `data`  
-   `feed`  
-   `server` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** servers to dispatch data
-   `file` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in a file
-   `script` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in a sting of characters
-   `commands` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** the external pipeline is descrbied in object

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## dump

Take all `Object` and genereta a json array

### Parameters

-   `data`  
-   `feed`  
-   `indent` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** indent JSON (optional, default `false`)

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## env

Take `Object` and send the same object
but in the meantime, it is possible to add
new environment field

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the new field
-   `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** value of the new field

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## extract

Take `Object` and throw each value of fields

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of field to extract

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## group

Take all `chunk`, and throw array of chunks

### Parameters

-   `data`  
-   `feed`  
-   `size` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Size of each partition

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## keep

Take `Object` and throw the same object but keep only
spefici fields

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of field to keep

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## pack

Take all `Object`, throw encoded `String`

### Parameters

-   `data`  
-   `feed`  

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## replace

Take `Object` and create a new object with some fields

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the new field
-   `value` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** value of the new field

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## shift

Take the first `Object` and close the feed

### Parameters

-   `data`  
-   `feed`  

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## shuffle

Take `Object`, shuffle data of the whole object or only some fields specified by path

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of field to shuffle

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## tracer

Take `Object`, print a character and throw the same object

### Parameters

-   `data`  
-   `feed`  
-   `print` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** character to print at each object (optional, default `.`)
-   `last` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** character to print at last call (optional, default `.`)
-   `first` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** character to print at first call (optional, default `.`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## transit

Take `Object` and throw the same object

### Parameters

-   `data`  
-   `feed`  

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

## truncate

Takes all the chunks, and closes the feed when the total length is equal to the parameter

### Parameters

-   `data`  
-   `feed`  
-   `length` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Length of the feed

Returns **Mixed** 

## ungroup

Take all `chunk`, and throw each item of chunks

### Parameters

-   `data`  
-   `feed`  

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## unpack

Take `String` and throw `Object` builded by JSON.parse on each line

### Parameters

-   `data`  
-   `feed`  

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 

## validate

-   **See: laravel validtor rules**

Take `Object` and throw the same object if all rules passes

### Parameters

-   `data`  
-   `feed`  
-   `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** path of the field
-   `rule` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** rule to validate the field

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**

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