Socket
Book a DemoInstallSign in
Socket

rx-extra

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rx-extra

rx-extra extends the library RxJS 5 with extra methods like 'fromNodeReadableStream' and 'splitOnChange'

2.1.4
latest
Source
npmnpm
Version published
Weekly downloads
8
-52.94%
Maintainers
1
Weekly downloads
 
Created
Source

rx-extra

rx-extra extends the RxJS 5 library with extra methods like fromNodeReadableStream and splitOnChange. If you're still using RxJS 4, you can find the compatible version of rx-extra in the RxJS4 branch.

Install

npm install --save rx-extra

Methods

fromNodeReadableStream

import { Observable } from 'rxjs/Observable';
import 'rx-extra/add/observable/fromNodeReadableStream';
import 'rxjs/add/operator/map';

Observable.fromNodeReadableStream(myStream)
  .map(x => objectMode ? x : x.toString())
  .subscribe(console.log, console.error);

partitionNested

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/range';
import 'rx-extra/add/operator/partitionNested';

let partitioned = Observable.range(1, 20)
  .partitionNested(x => x % 2 === 0);

let [evenSource, oddSource] = partitioned;

let [multipleOfSixSource, notMultipleOfSixSource] = partitioned
  .partitionNested(x => x % 3 === 0);

multipleOfSixSource
  .subscribe(console.log, console.error);

splitOnChange

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rx-extra/add/operator/splitOnChange';

Observable.from([{
  value: 5,
}, {
  value: 5,
}, {
  value: 6,
}, {
  value: 7,
}
}])
  .splitOnChange(function(item) {
    return item.value;
  })
  .subscribe(console.log, console.error);

then (Promise)

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/range';
import 'rx-extra/add/operator/then';

Observable.range(1, 3)
  .then(console.log, console.error);

throughNodeStream

import * as JSONStream from 'JSONStream';
import { Observable } from 'rxjs/Observable';
import 'rx-extra/add/operator/throughNodeStream';

Observable.from([
  '[{"a": 1},',
  '{"a": 2},{"a":',
  '3},',
  '{"a": 4}]'
])
  .throughNodeStream(JSONStream.parse('..a'))
  .subscribe(console.log, console.error);

If the objectMode option for your transform stream is not true, you will need to handle any required conversion(s) between String|Buffer and Number|Boolean|Object, e.g.:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/range';
import 'rxjs/add/operator/map';
import 'rx-extra/add/operator/throughNodeStream';
import * as through2 from 'through2';

Observable.range(1, 3)
  .map(x => x.toString())
  .throughNodeStream(through2(function(chunk, enc, callback) {
    var that = this;
    let x = parseInt(chunk.toString());
    for (var i=0; i<x; i++) {
      that.push(String(x + 1));
    }
    callback();
  }))
  .map(x => parseInt(x.toString()))
  .subscribe(console.log, console.error);

toNodeCallback

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/range';
import 'rx-extra/add/operator/toNodeCallback';

Observable.range(1, 3)
  .toNodeCallback(function(err, result) {
    if (err) {
      throw err;
    }
    console.log(result);
  });

Keywords

rx

FAQs

Package last updated on 30 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.