stream-mock
Advanced tools
Comparing version 2.0.2 to 2.0.3
/// <reference types="node" /> | ||
import { Duplex, DuplexOptions } from 'stream'; | ||
import { ReadableMock } from '../readable'; | ||
import { WritableMock } from '../writable'; | ||
declare class DuplexMock extends Duplex implements WritableMock, ReadableMock { | ||
import { IReadableMock } from '../readable'; | ||
import { IWritableMock } from '../writable'; | ||
declare class DuplexMock extends Duplex implements IWritableMock, IReadableMock { | ||
it: IterableIterator<any>; | ||
objectMode: boolean; | ||
readableObjectMode: boolean; | ||
writableObjectMode: boolean; | ||
readonly readableObjectMode: boolean; | ||
readonly writableObjectMode: boolean; | ||
data: any[]; | ||
flatData: any[] | Buffer; | ||
encoding: string; | ||
encoding: BufferEncoding; | ||
private _readableState; | ||
private _writableState; | ||
constructor(source?: Iterable<any> | ArrayLike<any>, options?: DuplexOptions); | ||
} | ||
export default DuplexMock; |
@@ -10,5 +10,2 @@ "use strict"; | ||
super(options); | ||
this.objectMode = options.objectMode; | ||
this.readableObjectMode = options.objectMode || options.readableObjectMode; | ||
this.writableObjectMode = options.objectMode || options.writableObjectMode; | ||
this.data = []; | ||
@@ -18,3 +15,3 @@ if (source) { | ||
} | ||
else if (this.readableObjectMode === this.writableObjectMode) { | ||
else if (this._readableState.objectMode === this._writableState.objectMode) { | ||
this.it = this.data[Symbol.iterator](); | ||
@@ -21,0 +18,0 @@ } |
/// <reference types="node" /> | ||
export declare const any2Buffer: (value: any, encoding: string) => Buffer; | ||
export declare const any2Buffer: (value: any, encoding: BufferEncoding) => Buffer; |
@@ -9,3 +9,5 @@ "use strict"; | ||
super(options); | ||
this.encoding = options.encoding ? options.encoding : 'utf8'; | ||
this.encoding = options.encoding | ||
? options.encoding | ||
: 'utf8'; | ||
this.it = source[Symbol.iterator](); | ||
@@ -12,0 +14,0 @@ } |
@@ -7,6 +7,6 @@ /// <reference types="node" /> | ||
objectMode: boolean; | ||
readableObjectMode: boolean; | ||
encoding: string; | ||
encoding: BufferEncoding; | ||
private _readableState; | ||
constructor(source: Iterable<any> | ArrayLike<any>, options?: ReadableOptions); | ||
_read(_size: number): void; | ||
} |
@@ -12,4 +12,5 @@ "use strict"; | ||
this.objectMode = options.objectMode; | ||
this.readableObjectMode = options.objectMode; | ||
this.encoding = options.encoding ? options.encoding : 'utf8'; | ||
this.encoding = options.encoding | ||
? options.encoding | ||
: 'utf8'; | ||
this.it = source[Symbol.iterator](); | ||
@@ -22,3 +23,3 @@ } | ||
} | ||
else if (this.objectMode || this.readableObjectMode) { | ||
else if (this._readableState.objectMode) { | ||
this.push(next.value); | ||
@@ -25,0 +26,0 @@ } |
/// <reference types="node" /> | ||
export interface IChunk { | ||
chunk: Buffer | string; | ||
encoding: string; | ||
encoding: BufferEncoding; | ||
} |
@@ -8,8 +8,8 @@ /// <reference types="node" /> | ||
constructor(options?: WritableOptions); | ||
_write(chunk: Buffer | string, encoding: string, callback: (error?: Error | null) => void): void; | ||
_write(chunk: Buffer | string, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; | ||
_writev(chunks: { | ||
chunk: Buffer | string; | ||
encoding: string; | ||
encoding: BufferEncoding; | ||
}[], callback: (error?: Error | null) => void): void; | ||
_final(callback: (error?: Error | null) => void): void; | ||
} |
@@ -9,5 +9,5 @@ /// <reference types="node" /> | ||
constructor(options?: WritableOptions); | ||
_write(chunk: any, _encoding: string, callback: (error?: Error | null) => void): void; | ||
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void; | ||
_writev(chunks: IChunk[], callback: (error?: Error | null) => void): void; | ||
_final(callback: (error?: Error | null) => void): void; | ||
} |
@@ -7,9 +7,9 @@ /// <reference types="node" /> | ||
objectMode: boolean; | ||
writableObjectMode: boolean; | ||
data: any[]; | ||
flatData: any[] | Buffer; | ||
private _writableState; | ||
constructor(options?: WritableOptions); | ||
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; | ||
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; | ||
_writev?(chunks: IChunk[], callback: (error?: Error | null) => void): void; | ||
_final(callback: (error?: Error | null) => void): void; | ||
} |
@@ -11,24 +11,18 @@ "use strict"; | ||
super(options); | ||
this.objectMode = options.objectMode; | ||
this.writableObjectMode = options.objectMode; | ||
this.data = []; | ||
} | ||
_write(chunk, encoding, callback) { | ||
this.data.push(this.objectMode || this.writableObjectMode | ||
? chunk | ||
: helpers_1.chunk2Buffer({ chunk, encoding })); | ||
this.data.push(this._writableState.objectMode ? chunk : helpers_1.chunk2Buffer({ chunk, encoding })); | ||
callback(); | ||
} | ||
_writev(chunks, callback) { | ||
this.data = | ||
this.objectMode || this.writableObjectMode | ||
? this.data.concat(chunks.map(c => c.chunk)) | ||
: this.data.concat(chunks.map(helpers_1.chunk2Buffer)); | ||
this.data = this._writableState.objectMode | ||
? this.data.concat(chunks.map(c => c.chunk)) | ||
: this.data.concat(chunks.map(helpers_1.chunk2Buffer)); | ||
callback(); | ||
} | ||
_final(callback) { | ||
this.flatData = | ||
this.objectMode || this.writableObjectMode | ||
? [].concat(...this.data) | ||
: Buffer.concat(this.data); | ||
this.flatData = this._writableState.objectMode | ||
? [].concat(...this.data) | ||
: Buffer.concat(this.data); | ||
callback(); | ||
@@ -35,0 +29,0 @@ } |
{ | ||
"name": "stream-mock", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Node stream mock module", | ||
@@ -33,5 +33,5 @@ "main": "lib/index.js", | ||
"@types/jest": "^24.0.11", | ||
"@types/node": "^11.13.0", | ||
"@types/node": "^12.0.10", | ||
"@types/sinon": "^7.0.11", | ||
"husky": "^1.3.1", | ||
"husky": "^2.6.0", | ||
"jest": "^24.7.1", | ||
@@ -38,0 +38,0 @@ "lint-staged": "^8.1.5", |
# Stream Mock | ||
[![Build Status](https://travis-ci.org/BastienAr/stream-mock.svg?branch=master)](https://travis-ci.org/BastienAr/stream-mock) | ||
[![Build Status](https://travis-ci.org/b4nst/stream-mock.svg?branch=master)](https://travis-ci.org/BastienAr/stream-mock) | ||
[![Actions Status](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/badge/b4nst/stream-mock)](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/results/b4nst/stream-mock) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/a2f2d69c643398bef333/test_coverage)](https://codeclimate.com/github/BastienAr/stream-mock/test_coverage) | ||
@@ -39,3 +40,5 @@ [![Maintainability](https://api.codeclimate.com/v1/badges/a2f2d69c643398bef333/maintainability)](https://codeclimate.com/github/BastienAr/stream-mock/maintainability) | ||
You are building an awesome brand new [Transform stream](https://nodejs.org/api/stream.html#stream_duplex_and_transform_streams) that rounds all your values. | ||
You are building an awesome brand new | ||
[Transform stream](https://nodejs.org/api/stream.html#stream_duplex_and_transform_streams) | ||
that rounds all your values. | ||
@@ -86,22 +89,2 @@ ```javascript | ||
## Contributing | ||
stream-mock is currently on early stage. | ||
I'm happily receiving new PR or discussing about new features, | ||
improvement or bug report. | ||
If you need something that this module is lacking | ||
(related to Nodejs stream mock obviously), do not hesitate to raise an issue. | ||
### Developper side | ||
To run test : | ||
```shell | ||
yarn run test | ||
``` | ||
Linter is run on commit hook base. | ||
![Thats all folks](https://media.giphy.com/media/lD76yTC5zxZPG/giphy.gif) | ||
---------------- | ||
@@ -108,0 +91,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78
425
32238
93