1.2.1 • Published 13 days ago

@libtommy2024/rerum-expedita-voluptates-quasi v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
13 days ago

@libtommy2024/rerum-expedita-voluptates-quasi

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("@libtommy2024/rerum-expedita-voluptates-quasi")

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("@libtommy2024/rerum-expedita-voluptates-quasi")([options,] fn)

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


var Tx = require("@libtommy2024/rerum-expedita-voluptates-quasi").ctor([options,] fn)

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


require("@libtommy2024/rerum-expedita-voluptates-quasi").obj([options,] fn)

Create a @libtommy2024/rerum-expedita-voluptates-quasi instance that defaults to objectMode: true.


require("@libtommy2024/rerum-expedita-voluptates-quasi").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

urlsstarter.envvalidate-0xhrjson-schemacompile lesstacitlibphonenumberequalSymbolspeeddescriptoraccessorcolourtrimLeftbundlertypedarrayssuperagentscheme-validationsyntaxerroremojiconcatMapajaxdeep-copyES7entriesjson-schema-validatorURLsignalsetterwhatwgparentspipeextendsymbolsjestlookcolumnPushgraphqlInt8ArrayqsECMAScript 2020querystringerror-handlingstylesheetflatvalidbatchwatchFilespinnersdefinePropertymochacollection.es6valueperformantflatMapWebSocketsintrinsicES2018extensiona11ygesturesUint32Arrayreact posejapanesetypeofcomputed-typesspecconcatcompareECMAScript 3puredependenciesposevalidatorcolorexecmovenamesecmascriptio-tspluginrangeerrorString.prototype.matchAllbyteLengthisConcatSpreadablespinnerparsetypesafesetImmediateobjectcryptomimejoijasminelesscssObject.getPrototypeOfObservableshelljavascriptpropertyECMAScript 2016hookformeslintprotobufdeterministic6to5electronrequestreduxruntimeoffsetbootstrap cssECMAScript 2019progressstartbcryptdebugsham256eslint-pluginInt32Arraydotenvl10nreact animationenderfolderexpressionES2016calleslintpluginpnpm9limitedIteratoroutputstringifierbootstrap lessiteratees-shimsquotecss nestingregular expressionbyteOffsetregexpUint8ArrayoptimizerefficientstringbufferBigUint64ArraydataviewweakmapBigInt64Arrayomitsortedremovethroatstringifyeventswordwrapreal-timetddargparsetypescriptcallbindrequirehandlersWeakSetES2020middlewarepushrecursiveless.jsgetintrinsiccommand-lineObject.entriesponyfillwaitmatchesfindLastthreeSymbol.toStringTagfixed-widthfetchtypeerrorwalkinguser-streamsinternalmergecoerciblenodemkdirsfromvaluesjson-schema-validationMicrosoftsymlinklogpasswordcommandtaketrimarraybufferlook-upargvfastpreprocessordataES2022rmTypeBoxxdg-openiterationpackage.jsonRxArray.prototype.includescensorxssfast-clonequeuepackagescss-in-jsauthObjectmatchreact-hook-formvarfindLastIndexutilemitsymbolreducetaskclassnamespersistentkarmamaptrimRighttranspilecallboundCSSStyleDeclarationsharedarraybufferestreematchAllisuuidframerinstallirqweaksetdirflagArray.prototype.flatpackage managergroupBysyntaxlruprefixformsObject.fromEntriesObject.keysArrayBuffer.prototype.sliceautoprefixersigtermexpresstostringtagtoobjectkoreanpromisesconfigschemestyled-componentsInt16ArraymkdirAsyncIterator@@toStringTagStreamscommanderArray.prototype.containsdomJSON-Schematypednegative zerodom-testing-libraryastargumentupgetOwnPropertyDescriptorvisualglobdiffsanitizeurlwarningdirectorysortdeepclonereadablestreamhelperscloneES2021appMapbdduninstallStyleSheetduplexstructuredCloneeditoropenertesttyped arrayECMAScript 2015optimistmakees2015wgetslotansijsxcallbackpositiveHyBii18nqueryyupReactiveExtensionssliceSetes2017es8variables in cssvestloadingshareddayjswatcherObject.definePropertyUnderscoreECMAScript 7settingstypedarraylinkbabeloptionstreamspawnfastclonetoolkitECMAScript 6esttynumberfile systemUint16Arrayclassesfindcurlresolvewindowscore-jses2018minimaltoStringTagbytetrimStart3dimmerdebuggernopemruregular expressionsbusyinstallerpoint-freemonoreporeducerjsonpathRFC-6455springArrayBuffer#sliceidlanguagehashenves6postcssArray.prototype.filtersuperstructtestingRegExp.prototype.flagsObject.valuesdefaultstylesTypeScriptmulti-packagestablevariableschromebannerdroplazyes2016packagetrimEndencryptionpruneregexECMAScript 2022toSortedES2017polyfillArray.prototype.findLastIndexexecutablefullsignalsES2023awaitReflect.getPrototypeOftimekeylintshebangcodescacheUint8ClampedArraytouchexeObject.isrm -frnodejsrobustreadbrowserwatchjsonschematapees-shim APIpropertiesfind-upflattenregularhookscharactersargsiefast-deep-clonejwtsameValueZeronested cssarktypeprivate dataratelimitinterruptsbundlinggetPrototypeOftoArrayutilitiesinputstatusterminalchairamdanativehigher-orderbuffersarraysstatelessECMAScript 2017assertionwaapiECMAScript 5ECMAScript 2023functionsperformanceflagsFunction.prototype.namegetoptbluebirdtoolsmobilefastcopydeep-cloneReactiveXredux-toolkitletStreamprototypedefineutil.inspectWebSocketbabel-corecreatechinesemacosimportartrgbreactexiteventEmittercircularjsdiffshimObservablesdescriptorscopymimetypescliguidform-validationcryptclientcurriedESnextharmonyshrinkwrapmomentURLSearchParamsenumerableserializerreadableimmutablepathwritableArray.prototype.flatMapgenerics__proto__testergradients css3ArrayBufferprotocol-buffersstyleguidefilterxterm_.extendformatstyleECMAScript 2021consoledeepcopyerroreveryreact-hooksmodulewhichworkerrfc4122react-testing-libraryeast-asian-widthpropdescriptionlaunchformattingasciiES5characteropendependency managerutilitypopmotioncss lessfullwidthfunctionaldeleteObject.assignratecall-boundlengthaccessibilityprettywordbreaktextcompilerconfigurableunicodeapilockfilecmdnamemime-dbenvironmentassertschemathrottleeventDispatcherArray.prototype.findLastparentfantasy-landcode pointsgetterkeyscall-bindmkdirpstreams2boundfpmodulesfseventsforEachextraTypedArrayprocessinternal slotfindupWeakMaplimitwebsiteiteratorsigintECMAScript 2018writeoperating-systemsequencetapequalityRxJSpyyamltermwidthES3channeljsonfull-widthFloat64Arraypostcss-plugints0patchassign$.extendqueueMicrotaskhttplastlistenersescapelinewrapcorsfsjQuerytypanionloggerFloat32ArrayES2019String.prototype.trimincludesstylingopensfilefigletform[[Prototype]]setserializepromisestreamsindicatorYAMLJSONless mixinsArray.prototype.flattenbreakconcurrencyES6privatesomewalklinuxajvcheckmake dirparsertelephoneairbnbinspecttc39colorsauthenticationeslintconfigsetPrototypeOfzodviewtypetranspilerchromiumwraphasOwnbrowserslistprotoworkspace:*browserlisthardlinksrm -rfapolloyamlloggingobjfast-copymetadatamixinszerormdires5fastifyargumentscontainschildes7exit-codeawesomesaucees-abstractES8functioncoregroupnegative
1.2.0

13 days ago

1.2.1

13 days ago

1.0.0

1 month ago