【文件属性】:
文件名称:conditional-stream:仅当 set 函数返回 true 时才通过数据的双工流
文件大小:6KB
文件格式:ZIP
更新时间:2021-06-11 10:03:23
JavaScript
条件流
条件流是双工流,仅在 set 函数返回 true 时才传递数据
要求
(这里使用streams2)
安装
npm 安装条件流
例子
将流过滤/限制为仅数字
onlyNumbers.js
var CondStream = require ( './index' )
, cond
cond = new CondStream ( function ( input ) {
// return true if input string is of type Number
return ( ! isNaN ( Number ( input . toString ( ) ) ) )
} )
process . stdin . pipe ( cond ) . pipe ( process . stdout )
安慰
> echo 2 | node onlyNumbers.js
【文件预览】:
conditional-stream-master
----.travis.yml(110B)
----.jshintignore(21B)
----index.js(58B)
----.jscsrc(2KB)
----package.json(852B)
----test()
--------test.js(873B)
----src()
--------index.js(606B)
----.npmignore(93B)
----examples()
--------onlyNumbers.js(246B)
----.gitignore(38B)
----lib()
--------index.js(3KB)
----README.md(822B)
----.jshintrc(272B)