Quick rename

This commit is contained in:
Lewis Diamond 2020-07-04 00:08:31 -04:00
parent db783805ad
commit ca6f36d19a
19 changed files with 96 additions and 102 deletions

View File

@ -1,15 +1,13 @@
# Mhysa # Strom
**Dependency-free stream utils for Node.js** **Dependency-free stream utils for Node.js**
<sub>Released under the [MIT](https://github.com/Wenzil/Mhysa/blob/master/LICENSE) license.</sub> <sub>Released under the [MIT](https://git.lewis.id/strom/blob/master/LICENSE) license.</sub>
```sh ```sh
yarn add mhysa yarn add @jogogo/strom
``` ```
<sub>Tested with Node.js versions 8+</sub>
## fromArray(array) ## fromArray(array)
Convert an array into a `Readable` stream of its elements Convert an array into a `Readable` stream of its elements
@ -18,7 +16,7 @@ Convert an array into a `Readable` stream of its elements
| `array` | `T[]` | Array of elements to stream | | `array` | `T[]` | Array of elements to stream |
```js ```js
Mhysa.fromArray(["a", "b"]) strom.fromArray(["a", "b"])
.pipe(process.stdout); .pipe(process.stdout);
// ab is printed out // ab is printed out
``` ```
@ -35,8 +33,8 @@ Return a `ReadWrite` stream that maps streamed chunks
| `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects | | `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects |
```js ```js
Mhysa.fromArray(["a", "b"]) strom.fromArray(["a", "b"])
.pipe(Mhysa.map(s => s.toUpperCase())) .pipe(strom.map(s => s.toUpperCase()))
.pipe(process.stdout); .pipe(process.stdout);
// AB is printed out // AB is printed out
``` ```
@ -53,8 +51,8 @@ Return a `ReadWrite` stream that flat maps streamed chunks
| `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects | | `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects |
```js ```js
Mhysa.fromArray(["a", "AA"]) strom.fromArray(["a", "AA"])
.pipe(Mhysa.flatMap(s => new Array(s.length).fill(s))) .pipe(strom.flatMap(s => new Array(s.length).fill(s)))
.pipe(process.stdout); .pipe(process.stdout);
// aAAAA is printed out // aAAAA is printed out
``` ```
@ -70,8 +68,8 @@ Return a `ReadWrite` stream that filters out streamed chunks for which the predi
| `options.objectMode` | `boolean` | `boolean` | Whether this stream should behave as a stream of objects | | `options.objectMode` | `boolean` | `boolean` | Whether this stream should behave as a stream of objects |
```js ```js
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.filter(s => s !== "b")) .pipe(strom.filter(s => s !== "b"))
.pipe(process.stdout); .pipe(process.stdout);
// ac is printed out // ac is printed out
``` ```
@ -90,9 +88,9 @@ value
| `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects | | `options.writableObjectMode` | `boolean` | Whether this stream should behave as a writable stream of objects |
```js ```js
Mhysa.fromArray(["a", "b", "cc"]) strom.fromArray(["a", "b", "cc"])
.pipe(Mhysa.reduce((acc, s) => ({ ...acc, [s]: s.length }), {})) .pipe(strom.reduce((acc, s) => ({ ...acc, [s]: s.length }), {}))
.pipe(Mhysa.stringify()) .pipe(strom.stringify())
.pipe(process.stdout); .pipe(process.stdout);
// {"a":1,"b":1","c":2} is printed out // {"a":1,"b":1","c":2} is printed out
``` ```
@ -108,9 +106,9 @@ Return a `ReadWrite` stream that splits streamed chunks using the given separato
| `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8 | `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8
```js ```js
Mhysa.fromArray(["a,b", "c,d"]) strom.fromArray(["a,b", "c,d"])
.pipe(Mhysa.split(",")) .pipe(strom.split(","))
.pipe(Mhysa.join("|")) .pipe(strom.join("|"))
.pipe(process.stdout); .pipe(process.stdout);
// a|bc|d is printed out // a|bc|d is printed out
``` ```
@ -126,8 +124,8 @@ Return a `ReadWrite` stream that joins streamed chunks using the given separator
| `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8 | `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8
```js ```js
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);
// a,b,c is printed out // a,b,c is printed out
``` ```
@ -145,8 +143,8 @@ the streamed chunks with the specified replacement string
| `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8 | `options.encoding` | `string` | Character encoding to use for decoding chunks. Defaults to utf8
```js ```js
Mhysa.fromArray(["a1", "b22", "c333"]) strom.fromArray(["a1", "b22", "c333"])
.pipe(Mhysa.replace(/b\d+/, "B")) .pipe(strom.replace(/b\d+/, "B"))
.pipe(process.stdout); .pipe(process.stdout);
// a1Bc333 is printed out // a1Bc333 is printed out
``` ```
@ -156,8 +154,8 @@ Mhysa.fromArray(["a1", "b22", "c333"])
Return a `ReadWrite` stream that parses the streamed chunks as JSON Return a `ReadWrite` stream that parses the streamed chunks as JSON
```js ```js
Mhysa.fromArray(['{ "a": "b" }']) strom.fromArray(['{ "a": "b" }'])
.pipe(Mhysa.parse()) .pipe(strom.parse())
.once("data", object => console.log(object)); .once("data", object => console.log(object));
// { a: 'b' } is printed out // { a: 'b' } is printed out
``` ```
@ -167,8 +165,8 @@ Mhysa.fromArray(['{ "a": "b" }'])
Return a `ReadWrite` stream that stringifies the streamed chunks to JSON Return a `ReadWrite` stream that stringifies the streamed chunks to JSON
```js ```js
Mhysa.fromArray([{ a: "b" }]) strom.fromArray([{ a: "b" }])
.pipe(Mhysa.stringify()) .pipe(strom.stringify())
.pipe(process.stdout); .pipe(process.stdout);
// {"a":"b"} is printed out // {"a":"b"} is printed out
``` ```
@ -183,8 +181,8 @@ Return a `ReadWrite` stream that collects streamed chunks into an array or buffe
| `options.objectMode` | `boolean` | Whether this stream should behave as a stream of objects | | `options.objectMode` | `boolean` | Whether this stream should behave as a stream of objects |
```js ```js
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.collect({ objectMode: true })) .pipe(strom.collect({ objectMode: true }))
.once("data", object => console.log(object)); .once("data", object => console.log(object));
// [ 'a', 'b', 'c' ] is printed out // [ 'a', 'b', 'c' ] is printed out
``` ```
@ -200,7 +198,7 @@ Return a `Readable` stream of readable streams concatenated together
```js ```js
const source1 = new Readable(); const source1 = new Readable();
const source2 = new Readable(); const source2 = new Readable();
Mhysa.concat(source1, source2).pipe(process.stdout) strom.concat(source1, source2).pipe(process.stdout)
source1.push("a1 "); source1.push("a1 ");
source2.push("c3 "); source2.push("c3 ");
source1.push("b2 "); source1.push("b2 ");
@ -221,7 +219,7 @@ Return a `Readable` stream of readable streams merged together in chunk arrival
```js ```js
const source1 = new Readable({ read() {} }); const source1 = new Readable({ read() {} });
const source2 = new Readable({ read() {} }); const source2 = new Readable({ read() {} });
Mhysa.merge(source1, source2).pipe(process.stdout); strom.merge(source1, source2).pipe(process.stdout);
source1.push("a1 "); source1.push("a1 ");
setTimeout(() => source2.push("c3 "), 10); setTimeout(() => source2.push("c3 "), 10);
setTimeout(() => source1.push("b2 "), 20); setTimeout(() => source1.push("b2 "), 20);
@ -243,8 +241,8 @@ cause the given readable stream to yield chunks
```js ```js
const catProcess = require("child_process").exec("grep -o ab"); const catProcess = require("child_process").exec("grep -o ab");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.duplex(catProcess.stdin, catProcess.stdout)) .pipe(strom.duplex(catProcess.stdin, catProcess.stdout))
.pipe(process.stdout); .pipe(process.stdout);
// ab is printed out // ab is printed out
``` ```
@ -259,8 +257,8 @@ Return a `Duplex` stream from a child process' stdin and stdout
```js ```js
const catProcess = require("child_process").exec("grep -o ab"); const catProcess = require("child_process").exec("grep -o ab");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.child(catProcess)) .pipe(strom.child(catProcess))
.pipe(process.stdout); .pipe(process.stdout);
// ab is printed out // ab is printed out
``` ```
@ -276,8 +274,8 @@ ended
```js ```js
let f = async () => { let f = async () => {
const source = Mhysa.fromArray(["a", "b", "c"]); const source = strom.fromArray(["a", "b", "c"]);
console.log(await Mhysa.last(source)); console.log(await strom.last(source));
}; };
f(); f();
// c is printed out // c is printed out

View File

@ -1,17 +1,16 @@
{ {
"name": "@jogogo/mhysa", "name": "strom",
"version": "2.0.0-alpha.4", "version": "2.0.0",
"description": "Streams and event emitter utils for Node.js", "description": "Streams utils for Node.js",
"keywords": [ "keywords": [
"promise", "promise",
"stream", "stream",
"event emitter",
"utils" "utils"
], ],
"author": { "contributors": [
{
"name": "Wenzil" "name": "Wenzil"
}, },
"contributors": [
{ {
"name": "jerry", "name": "jerry",
"email": "jerry@jogogo.co" "email": "jerry@jogogo.co"
@ -27,11 +26,8 @@
"files": [ "files": [
"dist" "dist"
], ],
"publishConfig": {
"registry": "https://npm.dev.jogogo.co/"
},
"repository": { "repository": {
"url": "git@github.com:Jogogoplay/mhysa.git", "url": "git@git.lewis.id:ldiamond/strom.git",
"type": "git" "type": "git"
}, },
"scripts": { "scripts": {

View File

@ -1,8 +1,8 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.map(s => Promise.resolve(s + s))) .pipe(strom.map(s => Promise.resolve(s + s)))
.pipe(Mhysa.flatMap(s => Promise.resolve([s, s.toUpperCase()]))) .pipe(strom.flatMap(s => Promise.resolve([s, s.toUpperCase()])))
.pipe(Mhysa.filter(s => Promise.resolve(s !== "bb"))) .pipe(strom.filter(s => Promise.resolve(s !== "bb")))
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
const catProcess = require("child_process").exec("grep -o ab"); const catProcess = require("child_process").exec("grep -o ab");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.child(catProcess)) .pipe(strom.child(catProcess))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,5 +1,5 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.collect({ objectMode: true })) .pipe(strom.collect({ objectMode: true }))
.on("data", object => console.log(object)); .on("data", object => console.log(object));

View File

@ -1,9 +1,9 @@
const { Readable } = require("stream"); const { Readable } = require("stream");
const Mhysa = require("mhysa"); const strom = require("strom");
const source1 = new Readable(); const source1 = new Readable();
const source2 = new Readable(); const source2 = new Readable();
Mhysa.concat(source1, source2).pipe(process.stdout); strom.concat(source1, source2).pipe(process.stdout);
source1.push("a1 "); source1.push("a1 ");
source2.push("c3 "); source2.push("c3 ");
source1.push("b2 "); source1.push("b2 ");

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
const catProcess = require("child_process").exec("grep -o ab"); const catProcess = require("child_process").exec("grep -o ab");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.duplex(catProcess.stdin, catProcess.stdout)) .pipe(strom.duplex(catProcess.stdin, catProcess.stdout))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.filter(s => s !== "b")) .pipe(strom.filter(s => s !== "b"))
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "AA"]) strom.fromArray(["a", "AA"])
.pipe(Mhysa.flatMap(s => new Array(s.length).fill(s))) .pipe(strom.flatMap(s => new Array(s.length).fill(s)))
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,5 +1,5 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b", "c"]) strom.fromArray(["a", "b", "c"])
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,7 +1,7 @@
const Mhysa = require("mhysa"); const strom = require("strom");
let f = async () => { let f = async () => {
const source = Mhysa.fromArray(["a", "b", "c"]); const source = strom.fromArray(["a", "b", "c"]);
console.log(await Mhysa.last(source)); console.log(await strom.last(source));
}; };
f(); f();

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b"]) strom.fromArray(["a", "b"])
.pipe(Mhysa.map(s => s.toUpperCase())) .pipe(strom.map(s => s.toUpperCase()))
.pipe(Mhysa.join(",")) .pipe(strom.join(","))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,9 +1,9 @@
const { Readable } = require("stream"); const { Readable } = require("stream");
const Mhysa = require("mhysa"); const strom = require("strom");
const source1 = new Readable({ read() {} }); const source1 = new Readable({ read() {} });
const source2 = new Readable({ read() {} }); const source2 = new Readable({ read() {} });
Mhysa.merge(source1, source2).pipe(process.stdout); strom.merge(source1, source2).pipe(process.stdout);
source1.push("a1 "); source1.push("a1 ");
setTimeout(() => source2.push("c3 "), 10); setTimeout(() => source2.push("c3 "), 10);
setTimeout(() => source1.push("b2 "), 20); setTimeout(() => source1.push("b2 "), 20);

View File

@ -1,5 +1,5 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(['{ "a": "b" }']) strom.fromArray(['{ "a": "b" }'])
.pipe(Mhysa.parse()) .pipe(strom.parse())
.on("data", object => console.log(object)); .on("data", object => console.log(object));

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a", "b", "cc"]) strom.fromArray(["a", "b", "cc"])
.pipe(Mhysa.reduce((acc, s) => ({ ...acc, [s]: s.length }), {})) .pipe(strom.reduce((acc, s) => ({ ...acc, [s]: s.length }), {}))
.pipe(Mhysa.stringify()) .pipe(strom.stringify())
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,5 +1,5 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a1", "b22", "c333"]) strom.fromArray(["a1", "b22", "c333"])
.pipe(Mhysa.replace(/b\d+/, "B")) .pipe(strom.replace(/b\d+/, "B"))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,6 +1,6 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray(["a,b", "c,d"]) strom.fromArray(["a,b", "c,d"])
.pipe(Mhysa.split(",")) .pipe(strom.split(","))
.pipe(Mhysa.join("|")) .pipe(strom.join("|"))
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -1,5 +1,5 @@
const Mhysa = require("mhysa"); const strom = require("strom");
Mhysa.fromArray([{ a: "b" }]) strom.fromArray([{ a: "b" }])
.pipe(Mhysa.stringify()) .pipe(strom.stringify())
.pipe(process.stdout); .pipe(process.stdout);

View File

@ -28,7 +28,7 @@ import { unbatch } from "./unbatch";
import { compose } from "./compose"; import { compose } from "./compose";
import { demux } from "./demux"; import { demux } from "./demux";
export default function mhysa(defaultOptions?: TransformOptions) { export default function strom(defaultOptions?: TransformOptions) {
function withDefaultOptions<T extends any[], R>( function withDefaultOptions<T extends any[], R>(
n: number, n: number,
fn: (...args: T) => R, fn: (...args: T) => R,