6.6.79 • Published 1 year ago

@zitterorg/reiciendis-ex-fuga v6.6.79

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@zitterorg/reiciendis-ex-fuga

NPM

This is a super thin wrapper around through2 that works like Array.prototype.map but for streams.

For when through2 is just too verbose :wink:

Note you will NOT be able to skip chunks. This is intended for modification only. If you want filter the stream content, use either through2 or through2-filter. This transform also does not have a flush function.

IMPORTANT: If you return null from your function, the stream will end there.

var map = require("@zitterorg/reiciendis-ex-fuga")

var truncate = map(function (chunk) {
  return chunk.slice(0, 10)
})

// vs. with through2:
var truncate = through2(function (chunk, encoding, callback) {
  this.push(chunk.slice(0, 10))
  return callback()
})

// Then use your map:
source.pipe(truncate).pipe(sink)

// Additionally accepts `wantStrings` argument to convert buffers into strings
var stripTags = map({wantStrings: true}, function (str) {
  // OMG don't actually use this
  return str.replace(/<.*?>/g, "")
})

// Works like `Array.prototype.map` meaning you can specify a function that
// takes up to two* arguments: fn(chunk, index)
var spaceout = map({wantStrings: true}, function (chunk, index) {
  return (index % 2 == 0) ? chunk + "\n\n" : chunk
})

// vs. with through2:
var spaceout = through2(function (chunk, encoding, callback) {
  if (this.index == undefined) this.index = 0
  var buf = (this.index++ % 2 == 0) ? Buffer.concat(chunk, new Buffer("\n\n")) : chunk
  this.push(buf)
  return callback()
})

*Differences from Array.prototype.map:

  • Cannot insert null elements into the stream without aborting.
  • No third array callback argument. That would require realizing the entire stream, which is generally counter-productive to stream operations.
  • Array.prototype.map doesn't modify the source Array, which is somewhat nonsensical when applied to streams.

API

require("@zitterorg/reiciendis-ex-fuga")([options,] fn)

Create a stream.Transform instance that will call fn(chunk, index) on each stream segment.


var Tx = require("@zitterorg/reiciendis-ex-fuga").ctor([options,] fn)

Create a reusable stream.Transform TYPE that can be called via new Tx or Tx() to create an instance.


require("@zitterorg/reiciendis-ex-fuga").obj([options,] fn)

Create a @zitterorg/reiciendis-ex-fuga instance that defaults to objectMode: true.


require("@zitterorg/reiciendis-ex-fuga").objCtor([options,] fn)

Just like ctor, but with objectMode: true defaulting to true.

Options

  • wantStrings: Automatically call chunk.toString() for the super lazy.
  • all other through2 options

LICENSE

MIT

6.6.79

1 year ago

6.5.76

1 year ago

6.6.77

1 year ago

6.6.78

1 year ago

6.6.76

1 year ago

6.5.73

1 year ago

6.5.75

1 year ago

6.5.74

1 year ago

6.5.71

1 year ago

6.5.70

1 year ago

6.5.72

1 year ago

6.5.66

1 year ago

6.5.68

1 year ago

6.5.67

1 year ago

6.5.69

1 year ago

6.5.57

1 year ago

6.5.56

1 year ago

6.5.59

1 year ago

6.5.58

1 year ago

4.4.50

1 year ago

4.4.54

1 year ago

4.4.53

1 year ago

4.4.52

1 year ago

4.4.51

1 year ago

4.4.55

1 year ago

4.4.43

1 year ago

4.4.42

1 year ago

4.4.41

1 year ago

4.4.40

1 year ago

4.4.47

1 year ago

4.4.46

1 year ago

4.4.45

1 year ago

4.4.44

1 year ago

5.4.56

1 year ago

4.4.49

1 year ago

4.4.48

1 year ago

5.4.55

1 year ago

6.5.65

1 year ago

4.4.32

1 year ago

4.4.31

1 year ago

6.5.60

1 year ago

4.4.30

1 year ago

6.5.62

1 year ago

4.4.36

1 year ago

6.5.61

1 year ago

4.4.35

1 year ago

6.5.64

1 year ago

4.4.34

1 year ago

6.5.63

1 year ago

4.4.33

1 year ago

4.4.39

1 year ago

4.4.38

1 year ago

4.4.37

1 year ago

5.5.56

1 year ago

4.3.30

1 year ago

4.3.28

1 year ago

4.3.27

1 year ago

4.3.26

1 year ago

4.3.29

1 year ago

3.2.26

1 year ago

3.2.25

1 year ago

4.2.26

1 year ago

3.2.24

1 year ago

3.2.23

1 year ago

3.1.14

1 year ago

3.1.15

1 year ago

3.2.20

1 year ago

3.2.22

1 year ago

3.2.21

1 year ago

3.2.15

1 year ago

3.2.17

1 year ago

3.2.16

1 year ago

3.2.19

1 year ago

3.2.18

1 year ago

3.1.13

1 year ago

3.1.12

1 year ago

2.1.9

1 year ago

2.1.12

1 year ago

2.1.10

1 year ago

2.1.11

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago