promise-readable
Advanced tools
Comparing version 4.2.0 to 4.2.1
# Changelog | ||
## v4.2.1 2019-06-04 | ||
- Minor tweaks in README. | ||
- Added source map to the package. | ||
## v4.2.0 2019-05-09 | ||
@@ -4,0 +9,0 @@ |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./lib/promise-readable') | ||
module.exports = require("./lib/promise-readable") |
@@ -18,5 +18,5 @@ /// <reference types="node" /> | ||
destroy(): void; | ||
once(event: 'close' | 'end' | 'error'): Promise<void>; | ||
once(event: 'open'): Promise<number>; | ||
once(event: "close" | "end" | "error"): Promise<void>; | ||
once(event: "open"): Promise<number>; | ||
} | ||
export default PromiseReadable; |
@@ -11,3 +11,3 @@ "use strict"; | ||
}; | ||
stream.on('error', this.errorHandler); | ||
stream.on("error", this.errorHandler); | ||
} | ||
@@ -49,11 +49,11 @@ static [Symbol.hasInstance](instance) { | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler); | ||
stream.removeListener('error', errorHandler); | ||
stream.removeListener('end', endHandler); | ||
stream.removeListener('readable', readableHandler); | ||
stream.removeListener("close", closeHandler); | ||
stream.removeListener("error", errorHandler); | ||
stream.removeListener("end", endHandler); | ||
stream.removeListener("readable", readableHandler); | ||
}; | ||
stream.on('close', closeHandler); | ||
stream.on('end', endHandler); | ||
stream.on('error', errorHandler); | ||
stream.on('readable', readableHandler); | ||
stream.on("close", closeHandler); | ||
stream.on("end", endHandler); | ||
stream.on("error", errorHandler); | ||
stream.on("readable", readableHandler); | ||
readableHandler(); | ||
@@ -65,3 +65,3 @@ }); | ||
const bufferArray = []; | ||
let content = ''; | ||
let content = ""; | ||
return new Promise((resolve, reject) => { | ||
@@ -77,3 +77,3 @@ if (this._errored) { | ||
const dataHandler = (chunk) => { | ||
if (typeof chunk === 'string') { | ||
if (typeof chunk === "string") { | ||
content += chunk; | ||
@@ -104,11 +104,11 @@ } | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler); | ||
stream.removeListener('data', dataHandler); | ||
stream.removeListener('error', errorHandler); | ||
stream.removeListener('end', endHandler); | ||
stream.removeListener("close", closeHandler); | ||
stream.removeListener("data", dataHandler); | ||
stream.removeListener("error", errorHandler); | ||
stream.removeListener("end", endHandler); | ||
}; | ||
stream.on('close', closeHandler); | ||
stream.on('data', dataHandler); | ||
stream.on('end', endHandler); | ||
stream.on('error', errorHandler); | ||
stream.on("close", closeHandler); | ||
stream.on("data", dataHandler); | ||
stream.on("end", endHandler); | ||
stream.on("error", errorHandler); | ||
stream.resume(); | ||
@@ -124,5 +124,5 @@ }); | ||
if (this.errorHandler) { | ||
this.stream.removeListener('error', this.errorHandler); | ||
this.stream.removeListener("error", this.errorHandler); | ||
} | ||
if (typeof this.stream.destroy === 'function') { | ||
if (typeof this.stream.destroy === "function") { | ||
this.stream.destroy(); | ||
@@ -141,3 +141,3 @@ } | ||
if (stream.closed) { | ||
if (event === 'close') { | ||
if (event === "close") { | ||
return resolve(); | ||
@@ -150,3 +150,3 @@ } | ||
else if (stream.destroyed) { | ||
if (event === 'close' || event === 'end') { | ||
if (event === "close" || event === "end") { | ||
return resolve(); | ||
@@ -162,3 +162,3 @@ } | ||
}; | ||
const eventHandler = event !== 'close' && event !== 'end' && event !== 'error' | ||
const eventHandler = event !== "close" && event !== "end" && event !== "error" | ||
? (argument) => { | ||
@@ -169,3 +169,3 @@ removeListeners(); | ||
: undefined; | ||
const endHandler = event !== 'close' | ||
const endHandler = event !== "close" | ||
? () => { | ||
@@ -185,7 +185,7 @@ removeListeners(); | ||
} | ||
stream.removeListener('error', errorHandler); | ||
stream.removeListener("error", errorHandler); | ||
if (endHandler) { | ||
stream.removeListener('end', endHandler); | ||
stream.removeListener("end", endHandler); | ||
} | ||
stream.removeListener('error', errorHandler); | ||
stream.removeListener("error", errorHandler); | ||
}; | ||
@@ -195,7 +195,7 @@ if (eventHandler) { | ||
} | ||
stream.on('close', closeHandler); | ||
stream.on("close", closeHandler); | ||
if (endHandler) { | ||
stream.on('end', endHandler); | ||
stream.on("end", endHandler); | ||
} | ||
stream.on('error', errorHandler); | ||
stream.on("error", errorHandler); | ||
}); | ||
@@ -206,1 +206,2 @@ } | ||
exports.default = PromiseReadable; | ||
//# sourceMappingURL=promise-readable.js.map |
{ | ||
"name": "promise-readable", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "Return promise for readable stream", | ||
@@ -28,43 +28,38 @@ "main": "lib/promise-readable.js", | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^12.0.0", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.0.4", | ||
"@types/semver": "^6.0.0", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.3", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.2.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-node": "^9.0.1", | ||
"markdownlint-cli": "^0.15.0", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint-plugin-node": "^9.1.0", | ||
"markdownlint-cli": "^0.16.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.0", | ||
"prettier": "^1.17.0", | ||
"semver": "^6.0.0", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.17.1", | ||
"semver": "^6.1.1", | ||
"shx": "^0.3.2", | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"ts-node": "^8.2.0", | ||
"tslint": "^5.17.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.4.5" | ||
"typescript": "^3.5.1" | ||
}, | ||
"scripts": { | ||
"build": "npm run compile", | ||
"compile": "tsc --pretty", | ||
"clean": "shx rm -rf lib", | ||
"compile": "tsc --pretty --project .", | ||
"clean": "npm run clean:compile && npm run clean:coverage", | ||
"clean:compile": "shx rm -rf lib", | ||
"clean:coverage": "shx rm -rf coverage .nyc_output", | ||
"lint": "npm run compile && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && prettier --ignore-path .gitignore --list-different '**/*.{js,json,md,ts,yml}' && markdownlint \"*.md\"", | ||
"postpublish": "git tag v$npm_package_version -a -m \"Release v$npm_package_version\" && git push --tags", | ||
"prepublishOnly": "npm run build", | ||
"pretest": "npm run build && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && prettier --ignore-path .gitignore --list-different '**/*.js' '**/*.json' '**/*.ts' '**/*.yml' && markdownlint \"*.md\"", | ||
"prepack": "npm run compile", | ||
"prepublishOnly": "npm run test", | ||
"pretest": "npm run lint", | ||
"test": "npm run test:spec", | ||
"test:spec": "npm run ts-mocha -- \"test/*.ts\"", | ||
"test:coverage": "nyc --reporter json npm run test:spec && nyc report", | ||
"ts-mocha": "mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"exclude": [ | ||
".*.js", | ||
"**/*.d.ts" | ||
] | ||
"test:coverage": "npm run clean:coverage && cross-env NYC=\"nyc --no-clean --reporter=lcov\" npm run test:spec && nyc report --reporter=text-summary --color", | ||
"ts-mocha": "$NYC mocha --use_strict --throw-deprecation --require source-map-support/register --require ts-node/register --timeout 90000" | ||
} | ||
} |
@@ -38,2 +38,14 @@ # promise-readable | ||
```js | ||
const {PromiseReadable} = require("promise-readable") | ||
``` | ||
_Typescript_: | ||
```ts | ||
import PromiseReadable from "promise-readable" | ||
// or | ||
import {PromiseReadable} from "promise-readable" | ||
``` | ||
### constructor | ||
@@ -50,6 +62,6 @@ | ||
```js | ||
const fs = require('fs') | ||
const {PromiseReadable} = require('promise-readable') | ||
const fs = require("fs") | ||
const {PromiseReadable} = require("promise-readable") | ||
const stream = fs.createReadStream('/etc/hosts') | ||
const stream = fs.createReadStream("/etc/hosts") | ||
const promiseReadable = new PromiseReadable(stream) | ||
@@ -61,6 +73,6 @@ ``` | ||
```ts | ||
import fs from 'fs' | ||
import PromiseReadable from 'promise-readable' | ||
import fs from "fs" | ||
import PromiseReadable from "promise-readable" | ||
const stream = fs.createReadStream('/etc/hosts') | ||
const stream = fs.createReadStream("/etc/hosts") | ||
const promiseReadable = new PromiseReadable(stream) | ||
@@ -108,3 +120,3 @@ ``` | ||
} | ||
console.log('stream is ended') | ||
console.log("stream is ended") | ||
``` | ||
@@ -143,3 +155,3 @@ | ||
promiseReadable.setEncoding('utf8') | ||
promiseReadable.setEncoding("utf8") | ||
const asString = await promiseReadable.read() | ||
@@ -163,11 +175,11 @@ ``` | ||
```js | ||
const fd = await promiseReadable.once('open') | ||
const fd = await promiseReadable.once("open") | ||
promiseReadable.stream.pipe(process.stdout) | ||
await promiseReadable.once('close') | ||
await promiseReadable.once("close") | ||
promiseReadable.stream.on('data', chunk => console.log(chunk.length)) | ||
await promiseReadable.once('end') | ||
promiseReadable.stream.on("data", chunk => console.log(chunk.length)) | ||
await promiseReadable.once("end") | ||
await promiseReadable.once('error') // throws error, undefined if ended | ||
await promiseReadable.once("error") // throws error, undefined if ended | ||
``` | ||
@@ -174,0 +186,0 @@ |
@@ -26,3 +26,3 @@ /// <reference types="node" /> | ||
stream.on('error', this.errorHandler) | ||
stream.on("error", this.errorHandler) | ||
} | ||
@@ -70,12 +70,12 @@ | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener('readable', readableHandler) | ||
stream.removeListener("close", closeHandler) | ||
stream.removeListener("error", errorHandler) | ||
stream.removeListener("end", endHandler) | ||
stream.removeListener("readable", readableHandler) | ||
} | ||
stream.on('close', closeHandler) | ||
stream.on('end', endHandler) | ||
stream.on('error', errorHandler) | ||
stream.on('readable', readableHandler) | ||
stream.on("close", closeHandler) | ||
stream.on("end", endHandler) | ||
stream.on("error", errorHandler) | ||
stream.on("readable", readableHandler) | ||
@@ -89,3 +89,3 @@ readableHandler() | ||
const bufferArray: Buffer[] = [] | ||
let content = '' | ||
let content = "" | ||
@@ -104,3 +104,3 @@ return new Promise((resolve, reject) => { | ||
const dataHandler = (chunk: Buffer | string) => { | ||
if (typeof chunk === 'string') { | ||
if (typeof chunk === "string") { | ||
content += chunk | ||
@@ -134,12 +134,12 @@ } else { | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('data', dataHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener("close", closeHandler) | ||
stream.removeListener("data", dataHandler) | ||
stream.removeListener("error", errorHandler) | ||
stream.removeListener("end", endHandler) | ||
} | ||
stream.on('close', closeHandler) | ||
stream.on('data', dataHandler) | ||
stream.on('end', endHandler) | ||
stream.on('error', errorHandler) | ||
stream.on("close", closeHandler) | ||
stream.on("data", dataHandler) | ||
stream.on("end", endHandler) | ||
stream.on("error", errorHandler) | ||
@@ -158,5 +158,5 @@ stream.resume() | ||
if (this.errorHandler) { | ||
this.stream.removeListener('error', this.errorHandler) | ||
this.stream.removeListener("error", this.errorHandler) | ||
} | ||
if (typeof this.stream.destroy === 'function') { | ||
if (typeof this.stream.destroy === "function") { | ||
this.stream.destroy() | ||
@@ -167,4 +167,4 @@ } | ||
once(event: 'close' | 'end' | 'error'): Promise<void> | ||
once(event: 'open'): Promise<number> | ||
once(event: "close" | "end" | "error"): Promise<void> | ||
once(event: "open"): Promise<number> | ||
@@ -182,3 +182,3 @@ once(event: string): Promise<void | number> { | ||
if (stream.closed) { | ||
if (event === 'close') { | ||
if (event === "close") { | ||
return resolve() | ||
@@ -189,3 +189,3 @@ } else { | ||
} else if (stream.destroyed) { | ||
if (event === 'close' || event === 'end') { | ||
if (event === "close" || event === "end") { | ||
return resolve() | ||
@@ -203,3 +203,3 @@ } else { | ||
const eventHandler = | ||
event !== 'close' && event !== 'end' && event !== 'error' | ||
event !== "close" && event !== "end" && event !== "error" | ||
? (argument: any) => { | ||
@@ -212,3 +212,3 @@ removeListeners() | ||
const endHandler = | ||
event !== 'close' | ||
event !== "close" | ||
? () => { | ||
@@ -231,9 +231,9 @@ removeListeners() | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener("error", errorHandler) | ||
if (endHandler) { | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener("end", endHandler) | ||
} | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener("error", errorHandler) | ||
} | ||
@@ -245,9 +245,9 @@ | ||
stream.on('close', closeHandler) | ||
stream.on("close", closeHandler) | ||
if (endHandler) { | ||
stream.on('end', endHandler) | ||
stream.on("end", endHandler) | ||
} | ||
stream.on('error', errorHandler) | ||
stream.on("error", errorHandler) | ||
}) | ||
@@ -254,0 +254,0 @@ } |
@@ -13,4 +13,5 @@ { | ||
"outDir": "./lib", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es6", | ||
"strict": true, | ||
"typeRoots": ["node_modules/@types"] | ||
@@ -17,0 +18,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30343
10
429
201
21