barnard59-base 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/filter.js +4 -4
- package/index.js +1 -1
- package/manifest.ttl +8 -1
- package/package.json +1 -1
- package/{stdout.js → process.js} +4 -2
- package/test/filter.test.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# barnard59-base
|
|
2
|
+
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e0b6f85: Added an operation to read standard input
|
|
8
|
+
|
|
9
|
+
## 2.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 5327ff0: Filter: bind filter callback function to pipeline context
|
|
2
14
|
|
|
3
15
|
## 2.0.1
|
|
4
16
|
|
package/filter.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { obj } from 'through2'
|
|
2
2
|
|
|
3
3
|
function filter(func) {
|
|
4
|
-
return obj(
|
|
4
|
+
return obj((chunk, encoding, callback) => {
|
|
5
5
|
Promise.resolve().then(() => {
|
|
6
|
-
return func(chunk, encoding)
|
|
6
|
+
return func.call(this, chunk, encoding)
|
|
7
7
|
}).then(result => {
|
|
8
8
|
if (result) {
|
|
9
|
-
|
|
9
|
+
return callback(null, chunk)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
callback()
|
|
12
|
+
return callback()
|
|
13
13
|
}).catch(callback)
|
|
14
14
|
})
|
|
15
15
|
}
|
package/index.js
CHANGED
|
@@ -8,5 +8,5 @@ export { default as limit } from './limit.js'
|
|
|
8
8
|
export { default as map } from './map.js'
|
|
9
9
|
export { default as nul } from './nul.js'
|
|
10
10
|
export { default as offset } from './offset.js'
|
|
11
|
-
export
|
|
11
|
+
export * from './process.js'
|
|
12
12
|
export { default as toString } from './toString.js'
|
package/manifest.ttl
CHANGED
|
@@ -98,7 +98,14 @@
|
|
|
98
98
|
rdfs:label "stdout";
|
|
99
99
|
rdfs:comment "Writes the incoming data to stdout and also forwards the data to the stream output.";
|
|
100
100
|
code:implementedBy [ a code:EcmaScriptModule;
|
|
101
|
-
code:link <node:barnard59-base/
|
|
101
|
+
code:link <node:barnard59-base/process.js#stdout>
|
|
102
|
+
].
|
|
103
|
+
|
|
104
|
+
<stdin> a p:Operation, p:Writable, p:Readable;
|
|
105
|
+
rdfs:label "stdin";
|
|
106
|
+
rdfs:comment "Reads from standard input";
|
|
107
|
+
code:implementedBy [ a code:EcmaScriptModule;
|
|
108
|
+
code:link <node:barnard59-base/process.js#stdin>
|
|
102
109
|
].
|
|
103
110
|
|
|
104
111
|
<toString> a p:Operation, p:WritableObjectMode, p:Readable;
|
package/package.json
CHANGED
package/{stdout.js → process.js}
RENAMED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { deepStrictEqual } from 'assert'
|
|
2
|
+
import { array } from 'get-stream'
|
|
3
|
+
import { Readable } from 'readable-stream'
|
|
4
|
+
import filter from '../filter.js'
|
|
5
|
+
|
|
6
|
+
describe('filter', () => {
|
|
7
|
+
it('should pass pipeline context to callback function', async () => {
|
|
8
|
+
const input = new Readable({
|
|
9
|
+
objectMode: true,
|
|
10
|
+
read: () => {
|
|
11
|
+
input.push('a')
|
|
12
|
+
input.push('b')
|
|
13
|
+
input.push(null)
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
const context = {
|
|
17
|
+
variable: new Map().set('condition', 'a'),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const outStream = input.pipe(filter.call(context, function (chunk) {
|
|
21
|
+
return this.variable.get('condition') === chunk
|
|
22
|
+
}))
|
|
23
|
+
const output = await array(outStream)
|
|
24
|
+
|
|
25
|
+
deepStrictEqual(output, ['a'])
|
|
26
|
+
})
|
|
27
|
+
})
|