nv-facutil-stream

nv-facutil-stream ================== - nv-facutil-stream is a simple-wrap of some stream Class - provide cache

Usage no npm install needed!

<script type="module">
  import nvFacutilStream from 'https://cdn.skypack.dev/nv-facutil-stream';
</script>

README

nv-facutil-stream

  • nv-facutil-stream is a simple-wrap of some stream Class
  • provide cache

install

  • npm install nv-facutil-stream

usage

const {Transform,Writable} = require("nv-facutil-stream");

example

WS

    > var {pws} = require("nv-facutil-stream")
    > var [p,ws] = pws()
    > p
    Promise { <pending> }
    > await ws.send('A')
    true
    > await ws.send('B')
    true
    > await ws.send('c')
    true
    > p
    Promise { <pending> }
    > ws.end()


    > p
    Promise { true }
    >
    > ws.writable
    false
    >

Transfrom

const {Transform} = require("nv-facutil-stream");

> var trans$ = new Transform()
undefined
> trans$.set_ondata_handler(
...     (chunk) => {
.....         console.log("data:");
.....         console.log(chunk)
.....     }
... );
undefined
> var my_console = new console.Console({stdout:trans$,colorMode:true});
undefined
>
> var tbl = [
...     { a: 1, b: 2 },
...     { a: 3, b: 7, c: 'y' },
... ]
undefined
>
> my_console.table(tbl)
data:
┌─────────┬───┬───┬─────┐
│ (index) │ a │ b │  c  │
├─────────┼───┼───┼─────┤
│    0    │ 1 │ 2 │     │
│    1    │ 3 │ 7 │ 'y' │
└─────────┴───┴───┴─────┘

undefined
> trans$.cache
<Buffer e2 94 8c e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 80 e2 94 ac e2 94 80 e2 94 80 e2 94 80 e2 94 ac e2 94 80 e2 94 ... 336 more bytes>
> trans$.stringify()
'┌─────────┬───┬───┬─────┐\n' +
  '│ (index) │ a │ b │  c  │\n' +
  '├─────────┼───┼───┼─────┤\n' +
  '│    0    │ \x1B[33m1\x1B[39m │ \x1B[33m2\x1B[39m │     │\n' +
  "│    1    │ \x1B[33m3\x1B[39m │ \x1B[33m7\x1B[39m │ \x1B[32m'y'\x1B[39m │\n" +
  '└─────────┴───┴───┴─────┘\n'
> trans$.clear()
undefined
>
> my_console.log(tbl)
data:
[ { a: 1, b: 2 }, { a: 3, b: 7, c: 'y' } ]

undefined
> trans$.cache
<Buffer 5b 20 7b 20 61 3a 20 1b 5b 33 33 6d 31 1b 5b 33 39 6d 2c 20 62 3a 20 1b 5b 33 33 6d 32 1b 5b 33 39 6d 20 7d 2c 20 7b 20 61 3a 20 1b 5b 33 33 6d 33 1b ... 43 more bytes>
> trans$.stringify()
"[ { a: \x1B[33m1\x1B[39m, b: \x1B[33m2\x1B[39m }, { a: \x1B[33m3\x1B[39m, b: \x1B[33m7\x1B[39m, c: \x1B[32m'y'\x1B[39m } ]\n"
> trans$.clear()
undefined
>

METHODS

writable

w$.cache                  w$.clear
w$.enc                    w$.shift                  w$.stringify

transform

trans$.cache                  trans$.clear                  trans$.enc
trans$.set_ondata_handler     trans$.shift                  trans$.stringify

API

  • fac_stream.Writable
  • fac_stream.Transform

LICENSE

  • ISC