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
```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
/**

View File

@ -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",

View File

@ -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");

View File

@ -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<T>(
emitter: NodeJS.EventEmitter,
event: string,
): Promise<T> {
return new Promise(resolve => {
emitter.once(event, result => {
resolve(result);
});
});
}
import * as utils from "./utils";
import * as stream from "./stream";
export = {
...utils,
stream,
};

View File

@ -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);

View File

@ -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;

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"
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"