1.0.0 • Published 1 year ago

@odczynflnpm/tenetur-corporis-accusamus v1.0.0

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

@odczynflnpm/tenetur-corporis-accusamus Version Badge

github actions coverage License Downloads

npm badge

Traverse and transform objects by visiting every node on a recursive walk.

examples

transform negative numbers in-place

negative.js

var @odczynflnpm/tenetur-corporis-accusamus = require('@odczynflnpm/tenetur-corporis-accusamus');
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];

@odczynflnpm/tenetur-corporis-accusamus(obj).forEach(function (x) {
    if (x < 0) this.update(x + 128);
});

console.dir(obj);

Output:

[ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ]

collect leaf nodes

leaves.js

var @odczynflnpm/tenetur-corporis-accusamus = require('@odczynflnpm/tenetur-corporis-accusamus');

var obj = {
    a : [1,2,3],
    b : 4,
    c : [5,6],
    d : { e : [7,8], f : 9 },
};

var leaves = @odczynflnpm/tenetur-corporis-accusamus(obj).reduce(function (acc, x) {
    if (this.isLeaf) acc.push(x);
    return acc;
}, []);

console.dir(leaves);

Output:

[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

scrub circular references

scrub.js:

var @odczynflnpm/tenetur-corporis-accusamus = require('@odczynflnpm/tenetur-corporis-accusamus');

var obj = { a : 1, b : 2, c : [ 3, 4 ] };
obj.c.push(obj);

var scrubbed = @odczynflnpm/tenetur-corporis-accusamus(obj).map(function (x) {
    if (this.circular) this.remove()
});
console.dir(scrubbed);

output:

{ a: 1, b: 2, c: [ 3, 4 ] }

methods

Each method that takes an fn uses the context documented below in the context section.

.map(fn)

Execute fn for each node in the object and return a new object with the results of the walk. To update nodes in the result use this.update(value).

.forEach(fn)

Execute fn for each node in the object but unlike .map(), when this.update() is called it updates the object in-place.

.reduce(fn, acc)

For each node in the object, perform a left-fold with the return value of fn(acc, node).

If acc isn't specified, acc is set to the root object for the first step and the root element is skipped.

.paths()

Return an Array of every possible non-cyclic path in the object. Paths are Arrays of string keys.

.nodes()

Return an Array of every node in the object.

.clone()

Create a deep clone of the object.

.get(path)

Get the element at the array path.

.set(path, value)

Set the element at the array path to value.

.has(path)

Return whether the element at the array path exists.

context

Each method that takes a callback has a context (its this object) with these attributes:

this.node

The present node on the recursive walk

this.path

An array of string keys from the root to the present node

this.parent

The context of the node's parent. This is undefined for the root node.

this.key

The name of the key of the present node in its parent. This is undefined for the root node.

this.isRoot, this.notRoot

Whether the present node is the root node

this.isLeaf, this.notLeaf

Whether or not the present node is a leaf node (has no children)

this.level

Depth of the node within the traversal

this.circular

If the node equals one of its parents, the circular attribute is set to the context of that parent and the traversal progresses no deeper.

this.update(value, stopHere=false)

Set a new value for the present node.

All the elements in value will be recursively @odczynflnpm/tenetur-corporis-accusamusd unless stopHere is true.

this.remove(stopHere=false)

Remove the current element from the output. If the node is in an Array it will be spliced off. Otherwise it will be deleted from its parent.

this.delete(stopHere=false)

Delete the current element from its parent in the output. Calls delete even on Arrays.

this.before(fn)

Call this function before any of the children are @odczynflnpm/tenetur-corporis-accusamusd.

You can assign into this.keys here to @odczynflnpm/tenetur-corporis-accusamus in a custom order.

this.after(fn)

Call this function after any of the children are @odczynflnpm/tenetur-corporis-accusamusd.

this.pre(fn)

Call this function before each of the children are @odczynflnpm/tenetur-corporis-accusamusd.

this.post(fn)

Call this function after each of the children are @odczynflnpm/tenetur-corporis-accusamusd.

install

Using npm do:

$ npm install @odczynflnpm/tenetur-corporis-accusamus

license

MIT

trimObject.entriesasciibindoncemulti-packageclassnamesl10nuuidparsesetImmediaterandompatchcorenumberJSON-Schemasyntaxes6Mappostcss-pluginrm -frinternal slotString.prototype.matchAllECMAScript 2021streams2higher-ordertakelinewrapsuperstructpackage.jsonclientutilflatMapreduxwhatwgrm -rfmakepropertyES8zerogradients csssomeshimcss variableTypeBoxESnextprivatecachedependency managerstringifysharedfetchWeakMapparsingcontainslookprunepicomatchinternalstdlibcssdescriptorsnamesidleroute__proto__mimetypesmapworkspace:*groupBydirpromisecodesdescriptionarraybuffernativeshrinkwrapscheme-validationutilityprivate dataopenspeedURLfssliceArray.prototype.flattenECMAScript 2020listenersiteratorYAMLpathjscircularamazondefinePropertydefineclassnameredirecttypesbundlingstyled-componentslengthsymlinkvalueartqueueMicrotaskclisettingsaccessibilityvpcreact-hook-formtypedRegExp.prototype.flagsurlcurlconfigvalidateFloat64ArrayeventEmittermapreducebreakpluginelectronratelimitjQueryinputcallboundtypanionBigInt64Arraydatetimefast-deep-cloneObject.getPrototypeOfloadbalancingFunction.prototype.namefastcomputed-typescompilerkarmaloadingECMAScript 2019encryptiontsfullwidthiamecmascriptUnderscoreprototypeweaksetshebangcss lessjoiprefixwatchingconfigurablegenericstc39nested cssextendfpsflagsschemedeep-copyObject.isduplexargumentbddfunctionalES2017createArrayBuffer#slicedom-testing-libraryelasticacheassignTypedArraymatchAllrangeerrorcolumnstypeerrorjsdiffcolumnflattenUint32Arrayreact-testing-libraryvalidisConcatSpreadablegradients css3Array.prototype.includesoutputstreamssymbolfastcloneparentsbrowserslisthasOwnPropertyregular expressionslanguagees-shimsObject.valuesPushsharedarraybufferstarterless compilerrfc4122fastcopyES7whichdataviewlimittoolsomitECMAScript 2018cryptobcryptcommandcollectionstatelessvestchannelequalityagentregexpolyfillJSONebsawsreducerassertiontypelessapollogdpr.envArray.prototype.findLastECMAScript 2017getPrototypeOftrimRightwritableexpressionreal-timeargsMicrosoftES2022sortcharactercjkpropertiesrapidform-validationboundcallbindsymbolsfixed-widthreuseroutingiecorsperformancebuffersdeepcopyarraysfile systemparserimportlibphonenumberenderec2testshellworkflowjavascriptkeysdayjsqueuehas-owndescriptorES2023awaitstructuredClonetermECMAScript 2022stylesheetproxytrimStartequal256i18napicode pointsprotocol-bufferses5copytoStringTagSymboltaskreactclass-validatortoArraypnpm9visualfindLastsafeInt32Arrayhookschairecursiveprogressesredux-toolkittraversemetadataES6argparsecloudtrailAsyncIteratorinstallertapdropdynamodbincludesObject.definePropertypromisesminimalmochaclassespreprocessorredactTypeScriptpipehasdotenvstringxtermimportexportcloudfrontPromiseenvfullstablejwtclonekinesisbufferEShashsqsimmutableansiserialize[[Prototype]]es8callwaitcoercibleasyncterminalES2021lockfileruntimeobjcss-in-jsenvironmenttypedarrayslasttoobjecteslintajaxweakmaplocationoptionairbnbwebchromesyntaxerrormomentswfinspectfind-upES3removemiddlewarechromiumless mixinsio-tssearchtddURLSearchParamspredictableserializationgetpersistentes7lazyroute53japanesemobileWeakSetmodulesECMAScript 5censorlook-upglobvariables in cssArray.prototype.containsemrflatfilterescapedeepstylingfromownawesomesauceestreeextrafindLastIndexReactiveXreducehookformFloat32Arrayparentmergebusy_.extendassertsttyjsdomfseventspropformpasswordcollection.es6nameregular expressionnegative zeroES2018preserve-symlinksRFC-6455guidwritequoteUint8ClampedArrayauthenticationprotobuffull-widthslotdeterministicmixinsdataViewsetterthroatbatchfast-deep-copy0koreanES2019loggingrobusteventsargvArrayBuffer.prototype.sliceconcatMapelmbeanstalkStreambluebirdeventDispatcherECMAScript 3Setidarktypeinstalles2016Symbol.toStringTagforEachmime-dbendpointrateglacierconsumeObservablesfindlinkes2015bootstrap cssStyleSheetcore-jsviewtoolkitArrayBufferdiffpositivepostcssa11ytostringtagtrimLeftefficientArray.prototype.filtercall-boundArray.prototype.findLastIndexdebuggerstyleguidematchtypescriptautoprefixerdependenciesnpmformattingless.jsStreamsECMAScript 2015CSSStyleDeclarationoptimistflagspecdomObject.fromEntriespackageArray.prototype.flatrequirereadspinnersdatastructureObject.assigncommanderjsxCSSdeep-cloneaccessorgetoptwalkingcloudsearchbyteLengthECMAScript 2023helperssymlinkssameValueZeroassertcharactersRxtapestyleInt16ArraytestingsetPrototypeOfArray.prototype.flatMapdebugES5es2018querystringconnectfindupwatcherkeyworkerString.prototype.trimprettytelephonergbArraytouchpackage managereslint-pluginsideinferencevalidationthrottlecompile lessRxJSwordbreakinvarianteveryarraysetfunctionswarningES2016loggerwidthlogsequenceeslintconfiglruECMAScript 6indicatortyped arrayemojiwafiterationmonorepoextensionconcurrencyBigUint64ArraymrucryptsnsRegExp#flagsjestjasminenodehardlinkszodUint16ArrayES2020authgetintrinsicvaluesES2015httpscolorwordwrapstringifierbootstrap lessdeleteexpressemittypedarraybannerfastifytesterReflect.getPrototypeOfspinnerconsoleliveECMAScript 2016yupmake dirgraphqlWebSocketenumerableimmertypeofreadablefast-copyutilitiesconcatcloudwatchlintcallbackoptimizersuperagenthttpajvwatchmodulegetOwnPropertyDescriptorelbReactiveExtensionsnopeiteratees2017rdstslibtoSortedrequestcloudformationjsonpathjsonpushWebSocketss3checkdeepcloneObjectentriesutil.inspectstoragegatewayunicodebrowserlistformses-abstractmkdirpeast-asian-widtherrorbyteOffsetlimitedprotoframeworkIteratoreslintpluginvariables@@toStringTagECMAScript 7mkdirscommand-linermdiravafilewrapless cssregexpnodejsponyfillxhrUint8ArrayastlesscssresolveObject.keysfolderstreamqsstatemimeInt8Arrayhotfluxcss nestingsesphonebytematchesreact-hooksgetterespreechinesewgetises-shim APIintrinsicquery
1.0.0

1 year ago