p-transform
Advanced tools
Comparing version
@@ -7,10 +7,10 @@ /// <reference types="node" resolution-mode="require"/> | ||
export { pipeline }; | ||
export declare const transform: <ChunkType = any>(transform: TransformMethod<ChunkType>) => DuplexWithDebug; | ||
export declare const transform: <ChunkType = any>(transform: TransformMethod<ChunkType>, end?: () => void | Promise<void>) => DuplexWithDebug; | ||
/** | ||
* Shortcut to create a passthrough with spy. | ||
*/ | ||
export declare const passthrough: <ChunkType = any>(spy?: ((chunk: ChunkType) => Promise<void> | void) | undefined) => DuplexWithDebug; | ||
export declare const passthrough: <ChunkType = any>(spy?: ((chunk: ChunkType) => Promise<void> | void) | undefined, end?: () => void | Promise<void>) => DuplexWithDebug; | ||
/** | ||
* Create a filter stream. | ||
*/ | ||
export declare const filter: <ChunkType = any>(filter: (chunk: ChunkType) => boolean | Promise<boolean>) => DuplexWithDebug; | ||
export declare const filter: <ChunkType = any>(filter: (chunk: ChunkType) => boolean | Promise<boolean>, end?: () => void) => DuplexWithDebug; |
@@ -6,4 +6,4 @@ import { Stream } from 'readable-stream'; | ||
export { pipeline }; | ||
export const transform = (transform) => { | ||
return new OutOfOrder(transform).duplex(); | ||
export const transform = (transform, end) => { | ||
return new OutOfOrder(transform).duplex(end); | ||
}; | ||
@@ -13,12 +13,12 @@ /** | ||
*/ | ||
export const passthrough = (spy) => transform(async (chunk) => { | ||
export const passthrough = (spy, end) => transform(async (chunk) => { | ||
await spy?.(chunk); | ||
return chunk; | ||
}); | ||
}, end); | ||
/** | ||
* Create a filter stream. | ||
*/ | ||
export const filter = (filter) => transform(async function (chunk) { | ||
export const filter = (filter, end) => transform(async function (chunk) { | ||
const result = await filter(chunk); | ||
return result ? chunk : undefined; | ||
}); | ||
}, end); |
@@ -19,3 +19,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
push(chunk: ChunkType): void; | ||
duplex(): DuplexWithDebug; | ||
duplex(end?: () => void | Promise<void>): DuplexWithDebug; | ||
/** | ||
@@ -22,0 +22,0 @@ * Queue chunk to be emitted. |
@@ -79,3 +79,3 @@ import { Readable as _Readable, Duplex as _Duplex } from 'readable-stream'; | ||
} | ||
duplex() { | ||
duplex(end) { | ||
const transform = Duplex.from({ | ||
@@ -87,2 +87,3 @@ readable: Readable.from(this), | ||
} | ||
await end?.call?.(this); | ||
await this.close(); | ||
@@ -89,0 +90,0 @@ }), |
{ | ||
"name": "p-transform", | ||
"version": "4.0.5", | ||
"version": "4.1.0", | ||
"bugs": "https://github.com/mshima/p-transform/issues", | ||
@@ -35,10 +35,10 @@ "repository": { | ||
"devDependencies": { | ||
"@vitest/coverage-c8": "^0.31.2", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"jsdoc-to-markdown": "^8.0.0", | ||
"prettier": "^2.8.0", | ||
"prettier": "^3.0.3", | ||
"prettier-plugin-packagejson": "^2.3.0", | ||
"sinon": "^15.0.0", | ||
"sinon": "^16.0.0", | ||
"typescript": "^5.0.4", | ||
"vitest": "^0.31.2", | ||
"xo": "^0.54.2" | ||
"vitest": "^0.34.6", | ||
"xo": "^0.56.0" | ||
}, | ||
@@ -45,0 +45,0 @@ "engines": { |
23234
0.82%191
0.53%