Skip to content

Commit b78fdfa

Browse files
committed
Added js-check.
1 parent 4e6c579 commit b78fdfa

5 files changed

Lines changed: 55 additions & 32 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
npm run build --if-present
3636
npm test
3737
npm run ts-check --if-present
38+
npm run js-check --if-present

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"test:seq:bun": "bun run `tape6-seq --self` --flags FO",
2121
"test:seq:deno": "deno run -A `tape6-seq --self` --flags FO",
2222
"ts-check": "tsc --noEmit",
23+
"js-check": "tsc --project tsconfig.check.json",
2324
"ts-test": "tape6 --flags FO 'tests/test-*.*ts'",
2425
"ts-test:bun": "tape6-bun --flags FO 'tests/test-*.*ts'",
2526
"ts-test:deno": "tape6-deno --flags FO 'tests/test-*.*ts'",

src/index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ const groupFunctions = (output, fn, index, fns) => {
101101
const produceStreams = item => {
102102
if (Array.isArray(item)) {
103103
if (!item.length) return null;
104-
if (item.length == 1) return item[0] && chain.asStream(item[0]);
105-
return chain.asStream(chain.gen(...item));
104+
if (item.length == 1) return item[0] && /** @type {any} */ (chain).asStream(item[0]);
105+
return /** @type {any} */ (chain).asStream(/** @type {any} */ (chain).gen(...item));
106106
}
107107
return item;
108108
};
@@ -124,7 +124,7 @@ const wrapFunctions = (fn, index, fns) => {
124124
if (index === fns.length - 1 && isWritableWebStream(fn)) {
125125
return Writable.fromWeb(fn, {objectMode: true});
126126
}
127-
if (typeof fn == 'function') return chain.asStream(fn); // a function
127+
if (typeof fn == 'function') return /** @type {any} */ (chain).asStream(fn); // a function
128128
throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');
129129
};
130130

@@ -193,16 +193,18 @@ const chain = (fns, options) => {
193193
output.on('finish', () => stream.push(null));
194194
}
195195

196-
stream = new Duplex({
197-
writableObjectMode: true,
198-
readableObjectMode: true,
199-
...options,
200-
readable: isReadableNodeStream(output),
201-
writable: isWritableNodeStream(input),
202-
write: writeMethod,
203-
final: finalMethod,
204-
read: readMethod
205-
});
196+
stream = /** @type {Duplex & {streams: any[], input: any, output: any}} */ (
197+
new Duplex({
198+
writableObjectMode: true,
199+
readableObjectMode: true,
200+
...options,
201+
readable: isReadableNodeStream(output),
202+
writable: isWritableNodeStream(input),
203+
write: writeMethod,
204+
final: finalMethod,
205+
read: readMethod
206+
})
207+
);
206208
stream.streams = streams;
207209
stream.input = input;
208210
stream.output = output;

src/utils/reduceStream.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const {Writable} = require('node:stream');
66

77
const defaultInitial = 0;
8-
const defaultReducer = (acc, value) => value;
8+
const defaultReducer = (_acc, value) => value;
99

1010
const reduceStream = (options, initial) => {
1111
if (!options || !options.reducer) {
@@ -18,25 +18,28 @@ const reduceStream = (options, initial) => {
1818
'reducer' in options && (reducer = options.reducer);
1919
}
2020

21-
const stream = new Writable({
22-
objectMode: true,
23-
...options,
24-
write(chunk, _, callback) {
25-
const result = reducer.call(this, this.accumulator, chunk);
26-
if (result && typeof result.then == 'function') {
27-
result.then(
28-
value => {
29-
this.accumulator = value;
30-
callback(null);
31-
},
32-
error => callback(error)
33-
);
34-
} else {
35-
this.accumulator = result;
36-
callback(null);
21+
const stream = /** @type {import('node:stream').Writable & {accumulator: any}} */ (
22+
new Writable({
23+
objectMode: true,
24+
...options,
25+
/** @this {import('node:stream').Writable & {accumulator: any}} */
26+
write(chunk, _, callback) {
27+
const result = reducer.call(this, this.accumulator, chunk);
28+
if (result && typeof result.then == 'function') {
29+
result.then(
30+
value => {
31+
this.accumulator = value;
32+
callback(null);
33+
},
34+
error => callback(error)
35+
);
36+
} else {
37+
this.accumulator = result;
38+
callback(null);
39+
}
3740
}
38-
}
39-
});
41+
})
42+
);
4043
stream.accumulator = accumulator;
4144

4245
return stream;

tsconfig.check.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"include": ["src/**/*.js"],
3+
"compilerOptions": {
4+
"target": "ES2022",
5+
"module": "Node16",
6+
"moduleResolution": "Node16",
7+
"noEmit": true,
8+
"allowJs": true,
9+
"checkJs": true,
10+
"noUnusedLocals": true,
11+
"noUnusedParameters": true,
12+
"strict": false,
13+
"skipLibCheck": true,
14+
"types": ["node"]
15+
}
16+
}

0 commit comments

Comments
 (0)