JSPM

pull-splitter

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q33176F

Split a stream into other streams using filters

Package Exports

  • pull-splitter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pull-splitter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pull-splitter

Split a stream into other streams using filters

const { pull, drain } = require('pull-stream')
const { read, write } = require('pull-splitter')
const splitter = require('pull-splitter')
const { extname } = require('path')

const project = splitter({
  js: file => extname(file.path) === '.js',
  css: file => extname(file.path) === '.css',
  html: file => extname(file.path) === '.html',
  // Pass other files through
  rest: true
})

// Pull files into splitter:
pull(
  read('src/**/*'),
  project.sink
)

// Pull results out
pull(
  project.css,
  write('out/css')
)

// Pull results with no match
pull(
  project.rest,
  write('out/assets')
)

The splitter is an object with { sink, rest?, ...streams }, where files go into sink, are filtered into streams, and the unmatched items stream out of rest.

See pull-merge and pull-sorted-merge for joining the streams back together

Install

npm install --save pull-splitter
yarn add pull-splitter

Usage

splitter(channels)

Returns a splitter stream based on the channels object provided.

The channels is an object of filter functions, such as:

var split = splitter({
  foo: item => item > 10,
  bar: item => item > 5,
  // ...
  rest: true
})

You can also provide a boolean for one of the properties to capturing any unmatching items.

Each channel turns into a source stream that streams out item based on the condition:

pull(
  split.foo,
  drain(console.log)
)

pull(
  split.bar,
  drain(console.log)
)

Then to stream data in, you use split.sink:

pull(
  values([ 3, 6, 9, 12, 15 ]),
  split.sink
)

Also see


Maintained by Jamen Marz (See on Twitter and GitHub for questions & updates)