Rework module structure
This commit is contained in:
parent
41c9ce7dca
commit
9694ee88e4
22
README.md
22
README.md
@ -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
|
||||
/**
|
||||
|
@ -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",
|
||||
|
@ -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));
|
||||
|
@ -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)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as utils from "./utils";
|
||||
import * as stream from "./stream";
|
||||
export = {
|
||||
...utils,
|
||||
stream,
|
||||
utils,
|
||||
...stream,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user