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-files')
const splitter = require('pull-splitter')
const { extname } = require('path')
const [split, channels, rest] = 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/**/*'),
split
)
// Pull results out
pull(
channels.css,
write('out/css')
)
pull(
channels.js,
write('out/js')
)
// Pull results with no match
pull(
rest,
write('out/assets')
)The splitter returns [split, channels, rest], where split is a sink that pushes onto one of the channels, or rest if none match
See pull-merge and pull-sorted-merge for joining the streams back together
Install
npm install --save pull-splitteryarn add pull-splitterUsage
splitter(config)
Returns a sink and sources (channels and rest), based on the config provided
var [split, channels, rest] = splitter({
high: item => item > 10,
low: item => item > 5,
// ...
})Each field in config turns into a source stream on channels based on the filter
pull(
channels.high,
drain(console.log)
)
pull(
channels.low,
drain(console.log)
)Then to stream data in, you use split.sink:
pull(
values([ 3, 6, 9, 12, 15 ]),
split
)Pull unmatching items through rest:
pull(rest, drain(console.log))Also see
pull-mergeto merge the streamspull-sorted-mergeto merge the streams with sortingpull-pairfor a basic way to link streamspull-teefor a different mechanism of splitting a stream
Maintained by Jamen Marz (See on Twitter and GitHub for questions & updates)