Socket
Socket
Sign inDemoInstall

flat-map

Package Overview
Dependencies
2
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flat-map

flat map implementation for streams1


Version published
Weekly downloads
1.1K
decreased by-26.28%
Maintainers
1
Install size
23.4 kB
Created
Weekly downloads
 

Readme

Source

#flat-map Build Status

A flat map implementation for node streams

##Installation npm install flat-map

##Usage

When the callback data is already flat passes it maps it normally:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray([1, 2, 3, 4, 5])
    .pipe(flatMap(function(data, callback) { callback(null, data.split(/\s/); }));
  // [1, 2, 3, 4, 5]    

When the callback data is an array it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
    .pipe(flatMap(function(data, callback) { callback(null, data.split(/\s/); });
  // ['one', 'two', 'three', 'four', 'five']    

When the callback data is a stream it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
    .pipe(flatMap(function(data, callback) { callback(null, es.readArray(data.split(/\s+/))) });
  // ['one', 'two', 'three', 'four', 'five']    

When the callback data is a promise it flattens and maps it accordingly:

  var es = require('event-stream');
  var flatMap = require('flat-map');
  es.readArray('one two', 'three', 'four five')
      .pipe(flatMap(function(data, callback) {
        callback(null, new Promise(function(resolve) { resolve(data); }))
      }));
  // ['one', 'two', 'three', 'four', 'five']

Keywords

FAQs

Last updated on 15 Dec 2017

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc