Skip to content
Eugene Ghanizadeh edited this page Feb 22, 2020 · 14 revisions

RxLine helps you manage complex (possibly async) operations on collections (or streams) of entities. A common example is performing a series of tasks on a list of files (compiling sass to css or markdown to html).

Installation

npm i rxline

Usage

Typical usage of RxLine looks like this:

  1. You define a line, i.e. a collection/stream of objects (called its content),
  2. You define some (sync or async) transformations on the objects of the line (called its transform),
  3. You request the line to be processed, i.e. its transform to be applied on its content.
import { line } from 'rxline';

line([1, 2, 3, 4])         // --> define the line
  .pipe(x => x * 2,        // --> add a transform
        x => x + 11)       // --> expand the transform
  .collect(console.log);   // --> process and collect the results.

// Result:
// [13, 15, 17, 19]
import { concurrently } from 'rxline';
import { files, mapContent, readFile, writeFile, pathMatch } from 'rxline/fs';

files('./src')                                // --> define the line
  .pick(pathMatch(/\.js$/))                   // --> filter its content
  .pipe(readFile())                           //
  .pipe(mapContent(                           //
    (content, path) =>                        // --> define the transform
      `/** @file ${path} **/\n` + content     //
  ))                                          //
  .pipe(writeFile())                          //
  .process(concurrently);                     // --> process the line

// Result:
// adds a first line `/** @file module/filename.js **/` to each javascript file in `./src`

Checkout these wiki entries for more detailed usage guides:

  • Lines: more detailed overview of lines and their functionality.
  • Files: utilities of RxLine for working with files.
Clone this wiki locally