4.3.65 • Published 1 year ago

@zitterorg/nihil-autem v4.3.65

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

4.3.64

1 year ago

4.3.63

1 year ago

4.3.62

1 year ago

4.3.61

1 year ago

3.3.59

1 year ago

3.3.60

1 year ago

4.3.60

1 year ago

3.3.57

1 year ago

3.3.58

1 year ago

3.3.56

1 year ago

3.3.53

1 year ago

3.3.54

1 year ago

3.3.55

1 year ago

3.2.53

1 year ago

1.0.18

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.2.41

1 year ago

1.1.30

1 year ago

1.2.42

1 year ago

1.2.40

1 year ago

1.2.45

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.2.43

1 year ago

1.1.32

1 year ago

1.2.44

1 year ago

1.1.31

1 year ago

1.1.35

1 year ago

3.2.48

1 year ago

3.2.49

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

3.2.51

1 year ago

3.2.50

1 year ago

3.2.52

1 year ago

2.2.48

1 year ago

2.2.46

1 year ago

2.2.47

1 year ago

2.2.45

1 year ago

1.1.23

1 year ago

1.2.35

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.2.38

1 year ago

1.1.27

1 year ago

1.2.39

1 year ago

1.1.26

1 year ago

1.2.36

1 year ago

1.1.25

1 year ago

1.2.37

1 year ago

1.1.24

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.9

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