4.3.65 • Published 2 years ago

@zitterorg/nihil-autem v4.3.65

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@zitterorg/nihil-autem

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/nihil-autem")

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/nihil-autem")([options,] fn)

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


var Tx = require("@zitterorg/nihil-autem").ctor([options,] fn)

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


require("@zitterorg/nihil-autem").obj([options,] fn)

Create a @zitterorg/nihil-autem instance that defaults to objectMode: true.


require("@zitterorg/nihil-autem").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

redactbyteLengthbinariesformstoStringTag3dweaksetextendpolyfillES5debuggerhookformthreepackage.jsonoptionposeenvfunctionalstreamsarraysECMAScript 2022es-shim APIcall-bindes-shimsbinds3String.prototype.matchAlltypeofarrayeslintconfigshrinkwrap.gitignoreasyncObject.valuesconfigurableglobalstypescriptsuperagentCSSqsECMAScript 3iteratorsymbolschemaglob.envsearchdynamodbnegative zero_.extendObservableschineserestredirectdefineartflatMapsymbolsjson-schema-validatorjapanesejQueryclassesmatchrdssettingsqueueutilityworkflowReactiveXassertsconstslotcallconsumezeroselfJSONlinkcompiler$.extenduser-streamsdeepcopyboundrmdirvestemristanbulpuredeep-clonehas-ownmake dircharacterslocationmatchesessubprocessa11ypackageArray.prototype.containseventsreversehelpersastES7deleteECMAScript 2018cloudwatchcore-jsspawnassertionapieslintpluginIteratortelephone0WeakSetArraydataviewdatafindLastIndexECMAScript 6cloneurlcodesidsharedjsdomUnderscoretoArraywarningmulti-packagebyteasciiebsjshintbintestingacornfetchautoprefixerfeeddirsortedvpcecmascriptavabufferprettyroute53descriptorobjtrimLefttesterglobalThisletPromiseharmonysomeslicejsdiffes8dependency managertypesafecolumnformcloudsearchexpressES2016mrunegativenameargsfastcopytswidthisConcatSpreadableownstyled-componentsdependenciesimportsource mapshebangstringelectrondataViewcorekeyses2016varautoscalingInt16ArrayStyleSheetfpstableloggerESnextdateinvariantgraphqlinstrumentationapolloconcattyped arraypropimportexportjsonstyletrimEndelasticacheindicatorfpsspinnerunicodedeterministicgetterdragWebSocketsqsbuffersJSON-Schemautil.inspectawstapefficientreact-hook-formawesomesauceECMAScript 2016typedarraydifftoobjectoffsetStreamsprivate dataeffect-tses-abstractnpmignoreenvironmentsformatelbponyfillonceworkerReflect.getPrototypeOfhooksmkdiridentifiersECMAScript 2023popmotiontslibregexrm -frpluginlastframeworkcolumnscloudfrontemitPushES8endercliRegExp#flagsfromObject.fromEntriesjavascriptregexpvalues
4.3.65

2 years ago

4.3.64

2 years ago

4.3.63

2 years ago

4.3.62

2 years ago

4.3.61

2 years ago

3.3.59

2 years ago

3.3.60

2 years ago

4.3.60

2 years ago

3.3.57

2 years ago

3.3.58

2 years ago

3.3.56

2 years ago

3.3.53

2 years ago

3.3.54

2 years ago

3.3.55

2 years ago

3.2.53

2 years ago

1.0.18

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.2.41

2 years ago

1.1.30

2 years ago

1.2.42

2 years ago

1.2.40

2 years ago

1.2.45

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.2.43

2 years ago

1.1.32

2 years ago

1.2.44

2 years ago

1.1.31

2 years ago

1.1.35

2 years ago

3.2.48

2 years ago

3.2.49

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

3.2.51

2 years ago

3.2.50

2 years ago

3.2.52

2 years ago

2.2.48

2 years ago

2.2.46

2 years ago

2.2.47

2 years ago

2.2.45

2 years ago

1.1.23

2 years ago

1.2.35

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.2.38

2 years ago

1.1.27

2 years ago

1.2.39

2 years ago

1.1.26

2 years ago

1.2.36

2 years ago

1.1.25

2 years ago

1.2.37

2 years ago

1.1.24

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago