Fix export structure

This commit is contained in:
Sami Turcotte 2018-11-25 20:24:35 -05:00
parent 2d3c1eee82
commit 0df74cb48f
8 changed files with 46 additions and 41 deletions

View File

@ -11,8 +11,7 @@ yarn add mysah
## Basic Usage ## Basic Usage
```js ```js
const stream = require("mysah/stream"); const { once, sleep, stream } = require("mysah");
const { once, sleep } = require("mysah");
async function main() { async function main() {
const collector = stream const collector = stream
@ -31,7 +30,7 @@ main();
## API ## API
### mysah/stream ### { stream }
```ts ```ts
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "mysah", "name": "mysah",
"version": "0.3.1", "version": "0.3.3",
"description": "Promise, Stream and EventEmitter utils for Node.js", "description": "Promise, Stream and EventEmitter utils for Node.js",
"keywords": [ "keywords": [
"promise", "promise",
@ -13,8 +13,8 @@
"email": "samiturcotte@gmail.com" "email": "samiturcotte@gmail.com"
}, },
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "index.js",
"types": "dist/**/*.d.ts", "types": "**/*.d.ts",
"files": [ "files": [
"dist" "dist"
], ],
@ -34,7 +34,7 @@
"@types/node": "^10.12.10", "@types/node": "^10.12.10",
"ava": "^1.0.0-rc.2", "ava": "^1.0.0-rc.2",
"chai": "^4.2.0", "chai": "^4.2.0",
"mysah": "^0.3.0", "mysah": "^0.3.1",
"prettier": "^1.14.3", "prettier": "^1.14.3",
"ts-node": "^7.0.1", "ts-node": "^7.0.1",
"tslint": "^5.11.0", "tslint": "^5.11.0",

View File

@ -1,6 +1,6 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const stream = require("mysah/stream"); const { stream } = require("mysah");
const sourceFile1 = path.join(process.cwd(), "package.json"); const sourceFile1 = path.join(process.cwd(), "package.json");
const sourceFile2 = path.join(process.cwd(), "README.md"); const sourceFile2 = path.join(process.cwd(), "README.md");

View File

@ -1,27 +1,6 @@
/** import * as utils from "./utils";
* Resolve after the given delay in milliseconds import * as stream from "./stream";
* export = {
* @param ms - The number of milliseconds to wait ...utils,
*/ stream,
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<T>(
emitter: NodeJS.EventEmitter,
event: string,
): Promise<T> {
return new Promise(resolve => {
emitter.once(event, result => {
resolve(result);
});
});
}

View File

@ -1,7 +1,7 @@
import test from "ava"; import test from "ava";
import { expect } from "chai"; import { expect } from "chai";
import { fromArray, collect, concat } from "./stream";
import { Readable } from "stream"; import { Readable } from "stream";
import { fromArray, collect, concat } from "./stream";
test.cb("fromArray() streams array elements in flowing mode", t => { test.cb("fromArray() streams array elements in flowing mode", t => {
t.plan(3); t.plan(3);

View File

@ -1,7 +1,7 @@
import test from "ava"; import test from "ava";
import { expect } from "chai"; import { expect } from "chai";
import { once, sleep } from "./";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { once, sleep } from "./utils";
const TimingErrorMarginMs = 50; const TimingErrorMarginMs = 50;

27
src/utils.ts Normal file
View File

@ -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<T>(
emitter: NodeJS.EventEmitter,
event: string,
): Promise<T> {
return new Promise(resolve => {
emitter.once(event, result => {
resolve(result);
});
});
}

View File

@ -2158,10 +2158,10 @@ multimatch@^2.1.0:
arrify "^1.0.0" arrify "^1.0.0"
minimatch "^3.0.0" minimatch "^3.0.0"
mysah@^0.3.0: mysah@^0.3.1:
version "0.3.0" version "0.3.1"
resolved "https://registry.yarnpkg.com/mysah/-/mysah-0.3.0.tgz#68be788a33597ade0bec6ef8a523709fdba09ca1" resolved "https://registry.yarnpkg.com/mysah/-/mysah-0.3.1.tgz#82fa28b246ebfc0379e7eb5b3a39c3614a0dc06e"
integrity sha512-u2Z5CDuRTeK12sOcJEHDGzIHE1i2FaPb3dxWxqWIJfm63uGX2HFfGCPsuF0WeIhFdsqE4xIy94kpaxDaQZ7sMg== integrity sha512-by0XUl7R19ToMzMnzmn4lTr9shs0I6HIY6mgBfS1k/k0mhumnKcQUzii3zUIlwQJ+ANf8GrbwC/y6U6nTf61VA==
nan@^2.9.2: nan@^2.9.2:
version "2.11.1" version "2.11.1"