diff --git a/README.md b/README.md index a58c48f..ac808c3 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ yarn add mysah ## Basic Usage ```js -const stream = require("mysah/stream"); -const { once, sleep } = require("mysah"); +const { once, sleep, stream } = require("mysah"); async function main() { const collector = stream @@ -31,7 +30,7 @@ main(); ## API -### mysah/stream +### { stream } ```ts /** diff --git a/package.json b/package.json index 7bf84f6..50d1503 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mysah", - "version": "0.3.1", + "version": "0.3.3", "description": "Promise, Stream and EventEmitter utils for Node.js", "keywords": [ "promise", @@ -13,8 +13,8 @@ "email": "samiturcotte@gmail.com" }, "license": "MIT", - "main": "dist/index.js", - "types": "dist/**/*.d.ts", + "main": "index.js", + "types": "**/*.d.ts", "files": [ "dist" ], @@ -34,7 +34,7 @@ "@types/node": "^10.12.10", "ava": "^1.0.0-rc.2", "chai": "^4.2.0", - "mysah": "^0.3.0", + "mysah": "^0.3.1", "prettier": "^1.14.3", "ts-node": "^7.0.1", "tslint": "^5.11.0", diff --git a/samples/concat_files.js b/samples/concat_files.js index bd75eee..a6f738c 100644 --- a/samples/concat_files.js +++ b/samples/concat_files.js @@ -1,6 +1,6 @@ const fs = require("fs"); const path = require("path"); -const stream = require("mysah/stream"); +const { stream } = require("mysah"); const sourceFile1 = path.join(process.cwd(), "package.json"); const sourceFile2 = path.join(process.cwd(), "README.md"); diff --git a/src/index.ts b/src/index.ts index 7745e86..0fa8b50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,27 +1,6 @@ -/** - * Resolve after the given delay in milliseconds - * - * @param ms - The number of milliseconds to wait - */ -export function sleep(ms: number) { - return new Promise(resolve => { - setTimeout(resolve, ms); - }); -} - -/** - * Resolve once the given event emitter emits the specified event - * - * @param emitter - The event emitter to watch - * @param event - The event to watch - */ -export function once( - emitter: NodeJS.EventEmitter, - event: string, -): Promise { - return new Promise(resolve => { - emitter.once(event, result => { - resolve(result); - }); - }); -} +import * as utils from "./utils"; +import * as stream from "./stream"; +export = { + ...utils, + stream, +}; diff --git a/src/stream.spec.ts b/src/stream.spec.ts index 92d2572..a17445d 100644 --- a/src/stream.spec.ts +++ b/src/stream.spec.ts @@ -1,7 +1,7 @@ import test from "ava"; import { expect } from "chai"; -import { fromArray, collect, concat } from "./stream"; import { Readable } from "stream"; +import { fromArray, collect, concat } from "./stream"; test.cb("fromArray() streams array elements in flowing mode", t => { t.plan(3); diff --git a/src/index.spec.ts b/src/utils.spec.ts similarity index 95% rename from src/index.spec.ts rename to src/utils.spec.ts index 9c67b4e..5bd6bea 100644 --- a/src/index.spec.ts +++ b/src/utils.spec.ts @@ -1,7 +1,7 @@ import test from "ava"; import { expect } from "chai"; -import { once, sleep } from "./"; import { EventEmitter } from "events"; +import { once, sleep } from "./utils"; const TimingErrorMarginMs = 50; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..7745e86 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,27 @@ +/** + * Resolve after the given delay in milliseconds + * + * @param ms - The number of milliseconds to wait + */ +export function sleep(ms: number) { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +} + +/** + * Resolve once the given event emitter emits the specified event + * + * @param emitter - The event emitter to watch + * @param event - The event to watch + */ +export function once( + emitter: NodeJS.EventEmitter, + event: string, +): Promise { + return new Promise(resolve => { + emitter.once(event, result => { + resolve(result); + }); + }); +} diff --git a/yarn.lock b/yarn.lock index d44f8b9..13fc38e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2158,10 +2158,10 @@ multimatch@^2.1.0: arrify "^1.0.0" minimatch "^3.0.0" -mysah@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/mysah/-/mysah-0.3.0.tgz#68be788a33597ade0bec6ef8a523709fdba09ca1" - integrity sha512-u2Z5CDuRTeK12sOcJEHDGzIHE1i2FaPb3dxWxqWIJfm63uGX2HFfGCPsuF0WeIhFdsqE4xIy94kpaxDaQZ7sMg== +mysah@^0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/mysah/-/mysah-0.3.1.tgz#82fa28b246ebfc0379e7eb5b3a39c3614a0dc06e" + integrity sha512-by0XUl7R19ToMzMnzmn4lTr9shs0I6HIY6mgBfS1k/k0mhumnKcQUzii3zUIlwQJ+ANf8GrbwC/y6U6nTf61VA== nan@^2.9.2: version "2.11.1"