Add samples
This commit is contained in:
5
samples/collect.js
Normal file
5
samples/collect.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
Mhysa.fromArray(["a", "b", "c"])
|
||||
.pipe(Mhysa.collect({ objectMode: true }))
|
||||
.on("data", object => console.log(object));
|
||||
@@ -1,19 +1,15 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Readable } = require("stream");
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
const sourceFile1 = path.join(process.cwd(), "package.json");
|
||||
const sourceFile2 = path.join(process.cwd(), "README.md");
|
||||
const outputDir = path.join(process.cwd(), "sample_output");
|
||||
const outputFile = path.join(outputDir, "concat_files.txt");
|
||||
const source1 = new Readable();
|
||||
const source2 = new Readable();
|
||||
const expectedElements = ["a", "b", "c", "d"];
|
||||
let i = 0;
|
||||
Mhysa.concat(source1, source2).pipe(process.stdout);
|
||||
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Concat two source files together into one
|
||||
Mhysa.concat(
|
||||
fs.createReadStream(sourceFile1),
|
||||
Mhysa.fromArray(["\n"]),
|
||||
fs.createReadStream(sourceFile2),
|
||||
).pipe(process.stdout);
|
||||
source1.push("a");
|
||||
source2.push("c");
|
||||
source1.push("b");
|
||||
source2.push("d");
|
||||
source1.push(null);
|
||||
source2.push(null);
|
||||
|
||||
5
samples/duplex.js
Normal file
5
samples/duplex.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const Mhysa = require("mhysa");
|
||||
const catProcess = require("child_process").exec("grep -o ab");
|
||||
Mhysa.fromArray(["a", "b", "c"])
|
||||
.pipe(Mhysa.duplex(catProcess.stdin, catProcess.stdout))
|
||||
.pipe(process.stdout);
|
||||
7
samples/last.js
Normal file
7
samples/last.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
let f = async () => {
|
||||
const source = Mhysa.fromArray(["a", "b", "c"]);
|
||||
console.log(await Mhysa.last(source));
|
||||
};
|
||||
f();
|
||||
12
samples/merge.js
Normal file
12
samples/merge.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const { Readable } = require("stream");
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
const source1 = new Readable({ read() {} });
|
||||
const source2 = new Readable({ read() {} });
|
||||
Mhysa.merge(source1, source2).pipe(process.stdout);
|
||||
source1.push("a1 ");
|
||||
setTimeout(() => source2.push("c3 "), 10);
|
||||
setTimeout(() => source1.push("b2 "), 20);
|
||||
setTimeout(() => source2.push("d4 "), 30);
|
||||
setTimeout(() => source1.push(null), 40);
|
||||
setTimeout(() => source2.push(null), 50);
|
||||
5
samples/parse.js
Normal file
5
samples/parse.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
Mhysa.fromArray(['{ "a": "b" }'])
|
||||
.pipe(Mhysa.parse())
|
||||
.on("data", object => console.log(object));
|
||||
5
samples/replace.js
Normal file
5
samples/replace.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
Mhysa.fromArray(["a1", "b22", "c333"])
|
||||
.pipe(Mhysa.replace(/b\d+/, "B"))
|
||||
.pipe(process.stdout);
|
||||
5
samples/stringify.js
Normal file
5
samples/stringify.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const Mhysa = require("mhysa");
|
||||
|
||||
Mhysa.fromArray([{ a: "b" }])
|
||||
.pipe(Mhysa.stringify())
|
||||
.pipe(process.stdout);
|
||||
Reference in New Issue
Block a user