Rework module structure

This commit is contained in:
Sami Turcotte 2018-11-28 23:59:24 -05:00
parent 41c9ce7dca
commit 9694ee88e4
6 changed files with 35 additions and 33 deletions

View File

@ -14,25 +14,27 @@ The following snippet demonstrates most of Mhysa's current features without much
will come!
```js
const { sleep, once, delay, stream } = require("mhysa");
const {
utils: { sleep, delay, once },
...Mhysa
} = require("mhysa");
async function main() {
const collector = stream
.concat(
stream.fromArray(["a\n", "b\n", "c\n"]),
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
const collector = Mhysa.concat(
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
)
.pipe(stream.split("\n"))
.pipe(Mhysa.split("\n"))
.pipe(
stream.flatMap(async s => {
Mhysa.flatMap(async s => {
await sleep(100);
return delay([s, s.toUpperCase()], 100);
}),
)
.pipe(stream.collect({ objectMode: true }));
.pipe(Mhysa.collect({ objectMode: true }));
const collected = await once(collector, "data");
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 12 * 100 ms)
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)
}
main();
```
@ -118,7 +120,7 @@ export declare function concat(
): NodeJS.ReadableStream;
```
### mhysa
### { utils }
```ts
/**

View File

@ -35,7 +35,7 @@
"@types/node": "^10.12.10",
"ava": "^1.0.0-rc.2",
"chai": "^4.2.0",
"mhysa": ".",
"mhysa": "./",
"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("mhysa");
const Mhysa = require("mhysa");
const sourceFile1 = path.join(process.cwd(), "package.json");
const sourceFile2 = path.join(process.cwd(), "README.md");
@ -12,10 +12,8 @@ if (!fs.existsSync(outputDir)) {
}
// Concat two source files together into one
stream
.concat(
Mhysa.concat(
fs.createReadStream(sourceFile1),
stream.fromArray(["\n"]),
Mhysa.fromArray(["\n"]),
fs.createReadStream(sourceFile2),
)
.pipe(fs.createWriteStream(outputFile));
).pipe(fs.createWriteStream(outputFile));

View File

@ -1,19 +1,21 @@
const { sleep, once, delay, stream } = require("mhysa");
const {
utils: { sleep, delay, once },
...Mhysa
} = require("mhysa");
async function main() {
const collector = stream
.concat(
stream.fromArray(["a\n", "b\n", "c\n"]),
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
const collector = Mhysa.concat(
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
)
.pipe(stream.split("\n"))
.pipe(Mhysa.split("\n"))
.pipe(
stream.flatMap(async s => {
Mhysa.flatMap(async s => {
await sleep(100);
return delay([s, s.toUpperCase()], 100);
}),
)
.pipe(stream.collect({ objectMode: true }));
.pipe(Mhysa.collect({ objectMode: true }));
const collected = await once(collector, "data");
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)

View File

@ -1,6 +1,6 @@
import * as utils from "./utils";
import * as stream from "./stream";
export = {
...utils,
stream,
utils,
...stream,
};

View File

@ -2066,8 +2066,8 @@ meow@^5.0.0:
trim-newlines "^2.0.0"
yargs-parser "^10.0.0"
mhysa@.:
version "0.4.1"
mhysa@./:
version "0.5.0-beta.0"
micromatch@^3.1.10, micromatch@^3.1.4:
version "3.1.10"