Rework module structure
This commit is contained in:
parent
41c9ce7dca
commit
9694ee88e4
24
README.md
24
README.md
@ -14,25 +14,27 @@ The following snippet demonstrates most of Mhysa's current features without much
|
|||||||
will come!
|
will come!
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { sleep, once, delay, stream } = require("mhysa");
|
const {
|
||||||
|
utils: { sleep, delay, once },
|
||||||
|
...Mhysa
|
||||||
|
} = require("mhysa");
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const collector = stream
|
const collector = Mhysa.concat(
|
||||||
.concat(
|
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
|
||||||
stream.fromArray(["a\n", "b\n", "c\n"]),
|
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
|
||||||
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
|
)
|
||||||
)
|
.pipe(Mhysa.split("\n"))
|
||||||
.pipe(stream.split("\n"))
|
|
||||||
.pipe(
|
.pipe(
|
||||||
stream.flatMap(async s => {
|
Mhysa.flatMap(async s => {
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
return delay([s, s.toUpperCase()], 100);
|
return delay([s, s.toUpperCase()], 100);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.pipe(stream.collect({ objectMode: true }));
|
.pipe(Mhysa.collect({ objectMode: true }));
|
||||||
|
|
||||||
const collected = await once(collector, "data");
|
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();
|
main();
|
||||||
```
|
```
|
||||||
@ -118,7 +120,7 @@ export declare function concat(
|
|||||||
): NodeJS.ReadableStream;
|
): NodeJS.ReadableStream;
|
||||||
```
|
```
|
||||||
|
|
||||||
### mhysa
|
### { utils }
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,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",
|
||||||
"mhysa": ".",
|
"mhysa": "./",
|
||||||
"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",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { stream } = require("mhysa");
|
const Mhysa = require("mhysa");
|
||||||
|
|
||||||
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");
|
||||||
@ -12,10 +12,8 @@ if (!fs.existsSync(outputDir)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Concat two source files together into one
|
// Concat two source files together into one
|
||||||
stream
|
Mhysa.concat(
|
||||||
.concat(
|
fs.createReadStream(sourceFile1),
|
||||||
fs.createReadStream(sourceFile1),
|
Mhysa.fromArray(["\n"]),
|
||||||
stream.fromArray(["\n"]),
|
fs.createReadStream(sourceFile2),
|
||||||
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() {
|
async function main() {
|
||||||
const collector = stream
|
const collector = Mhysa.concat(
|
||||||
.concat(
|
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
|
||||||
stream.fromArray(["a\n", "b\n", "c\n"]),
|
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
|
||||||
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
|
)
|
||||||
)
|
.pipe(Mhysa.split("\n"))
|
||||||
.pipe(stream.split("\n"))
|
|
||||||
.pipe(
|
.pipe(
|
||||||
stream.flatMap(async s => {
|
Mhysa.flatMap(async s => {
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
return delay([s, s.toUpperCase()], 100);
|
return delay([s, s.toUpperCase()], 100);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.pipe(stream.collect({ objectMode: true }));
|
.pipe(Mhysa.collect({ objectMode: true }));
|
||||||
|
|
||||||
const collected = await once(collector, "data");
|
const collected = await once(collector, "data");
|
||||||
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)
|
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 utils from "./utils";
|
||||||
import * as stream from "./stream";
|
import * as stream from "./stream";
|
||||||
export = {
|
export = {
|
||||||
...utils,
|
utils,
|
||||||
stream,
|
...stream,
|
||||||
};
|
};
|
||||||
|
@ -2066,8 +2066,8 @@ meow@^5.0.0:
|
|||||||
trim-newlines "^2.0.0"
|
trim-newlines "^2.0.0"
|
||||||
yargs-parser "^10.0.0"
|
yargs-parser "^10.0.0"
|
||||||
|
|
||||||
mhysa@.:
|
mhysa@./:
|
||||||
version "0.4.1"
|
version "0.5.0-beta.0"
|
||||||
|
|
||||||
micromatch@^3.1.10, micromatch@^3.1.4:
|
micromatch@^3.1.10, micromatch@^3.1.4:
|
||||||
version "3.1.10"
|
version "3.1.10"
|
||||||
|
Loading…
Reference in New Issue
Block a user