-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert the library to typescript (#27)
MAJOR changed the push type signature to return boolean, a breaking change but makes it more correct
- Loading branch information
Showing
34 changed files
with
3,646 additions
and
3,141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package-lock.json | ||
.nvmrc | ||
test | ||
.babelrc | ||
.gitignore | ||
.travis.yml | ||
lib | ||
.vscode | ||
tsconfig.json | ||
tslint.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ITransformStreamOptions, TransformStream } from './transform' | ||
|
||
export type filterFunc = (data: any, encoding?: string) => boolean | Promise<boolean> | ||
|
||
export class FilterStream extends TransformStream { | ||
private filterFunction: filterFunc | ||
|
||
constructor (opts: ITransformStreamOptions | filterFunc, filterFunction?: filterFunc) { | ||
if (typeof opts === 'function') { | ||
filterFunction = opts | ||
opts = {} | ||
} | ||
super(opts) | ||
this.filterFunction = filterFunction | ||
} | ||
|
||
public async _transform (data, encoding) { | ||
const keep = await Promise.resolve(this.filterFunction(data, encoding)) | ||
if (keep) { | ||
await this.push(data) | ||
} | ||
} | ||
} | ||
|
||
export const filter = (opts: ITransformStreamOptions | filterFunc, fn?: filterFunc) => new FilterStream(opts, fn) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { collect } from './collect' | ||
import { filter, FilterStream } from './filter' | ||
import { pipe } from './pipe' | ||
import { IReadableStreamOptions, read, readFunction, ReadStream } from './read' | ||
import { readAsync } from './readAsync' | ||
import { reduce, reduceFunction, ReduceStream } from './reduce' | ||
import { ITransformStreamOptions, map, transform, transformFunction, TransformStream } from './transform' | ||
import { wait } from './utils' | ||
import { IWritableStreamOptions, write, writeFunction, WriteStream } from './write' | ||
|
||
// types | ||
export { IBluestream } from './interfaces' | ||
export { | ||
IReadableStreamOptions, | ||
IWritableStreamOptions, | ||
ITransformStreamOptions, | ||
transformFunction, | ||
readFunction, | ||
reduceFunction, | ||
writeFunction, | ||
} | ||
|
||
// methods | ||
export { | ||
FilterStream, | ||
ReadStream, | ||
ReduceStream, | ||
TransformStream, | ||
WriteStream, | ||
collect, | ||
filter, | ||
map, | ||
pipe, | ||
read, | ||
readAsync, | ||
reduce, | ||
transform, | ||
wait, | ||
write, | ||
} | ||
|
||
export default { | ||
FilterStream, | ||
ReadStream, | ||
ReduceStream, | ||
TransformStream, | ||
WriteStream, | ||
collect, | ||
filter, | ||
map, | ||
pipe, | ||
read, | ||
readAsync, | ||
reduce, | ||
transform, | ||
wait, | ||
write, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Readable, Stream } from 'stream' | ||
|
||
export interface IBluestream extends Stream { | ||
promise (): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.