Gathering detailed insights and metrics for @hoangcung1804npm/assumenda-officiis-repellat
Gathering detailed insights and metrics for @hoangcung1804npm/assumenda-officiis-repellat
Gathering detailed insights and metrics for @hoangcung1804npm/assumenda-officiis-repellat
Gathering detailed insights and metrics for @hoangcung1804npm/assumenda-officiis-repellat
npm install @hoangcung1804npm/assumenda-officiis-repellat
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,487 Commits
1 Branches
1 Contributors
Updated on Jul 14, 2025
Latest Version
1.0.0
Package Id
@hoangcung1804npm/assumenda-officiis-repellat@1.0.0
Unpacked Size
18.61 kB
Size
6.51 kB
File Count
8
NPM Version
10.5.0
Node Version
20.12.2
Published on
May 04, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
Traverse and manipulate JSON objects.
1const jt = require('@hoangcung1804npm/assumenda-officiis-repellat'); 2 3const callbacks = { 4 processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => { 5 /* your logic here */ 6 }, 7 enterLevel: (level, path) => { 8 /* your logic here */ 9 }, 10 exitLevel: (level, path) => { 11 /* your logic here */ 12 } 13}; 14 15var obj = { /* your JSON object */ }; 16 17jt.traverse(obj, callbacks);
1var simpleObj = { 2 MyValue: 'test', 3 OtherValue: 'zzz', 4 NumberValue: 311, 5 MyArray: [1, 2, 3, 50, 60, 70] 6}; 7 8const callbacks = { 9 processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => { 10 console.log(level + ' ' + (path.length > 0 ? (path.join('.') + '.') : '') + key + ' = ' + value); 11 } 12}; 13 14const jt = require('@hoangcung1804npm/assumenda-officiis-repellat'); 15 16jt.traverse(simpleObj, callbacks); 17// 0 MyValue = test 18// 0 OtherValue = xxx 19// 0 NumberValue = 311 20// 0 MyArray._0 = 1 21// 0 MyArray._1 = 2 22// 0 MyArray._2 = 3 23// 0 MyArray._3 = 50 24// 0 MyArray._4 = 60 25// 0 MyArray._5 = 70 26 27// flat array-mode: flattenArray = true (arrays are treated as one value) 28jt.traverse(simpleObj, callbacks, true); 29// 0 MyValue = test 30// 0 OtherValue = xxx 31// 0 NumberValue = 311 32// 0 MyArray = 1,2,3,50,60,70
1var simpleObj = { 2 MyValue: 'test', 3 OtherValue: 'zzz', 4 NumberValue: 311, 5 MyArray: [1, 2, 3, 50, 60, 70] 6}; 7 8const callbacks = { 9 processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => { 10 // change values of properties starting with 'My' and 11 // multiply all numeric array values greater then 50 by 100 12 if (key.startsWith('My')) { 13 cbSetValue('MyNew-' + value); 14 } 15 if (isArrayElement && parseInt(value) > 50) { 16 cbSetValue(100 * parseInt(value)); 17 } 18 } 19}; 20 21const jt = require('@hoangcung1804npm/assumenda-officiis-repellat'); 22 23jt.traverse(simpleObj, callbacks); 24 25// { 26// MyValue : "MyNew-test", 27// OtherValue: "xxx", 28// NumberValue: 311, 29// MyArray: [ 1, 2, 3, 50, 6000, 7000 ] 30// }
1var htmlObj = { 2 MyArray: [0, 0], 3 ArrayInArray: [0, 1, ['two', 'three', [4, 5, 6]]], 4 MyNumber: 123, 5 MyString: 'test', 6 Child: { 7 ChildVal: 1, 8 SubChild: { 9 SubChildVal: 777 10 }, 11 ChildArray: [1, 2, 66, 9, 900] 12 }, 13 TrailingValue: 'testtesttest' 14} 15 16const callbacksHtmlList = { 17 processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => { 18 if (isObjectRoot) { 19 console.log((' ').repeat(level) + ' <li class=\"caret\">Key: ' + key + '</li>') 20 } 21 else { 22 console.log((' ').repeat(level) + ' <li>Key: ' + key + ', Value: ' + value + '</li>') 23 }; 24 }, 25 enterLevel: (level, path) => { 26 if (level == 0) { 27 console.log('<ul>'); 28 } 29 else { 30 console.log((' ').repeat(level) + '<ul class=\"nested\">'); 31 }; 32 }, 33 exitLevel: (level, path) => { console.log((' ').repeat(level) + '</ul>'); } 34}; 35 36const jt = require('@hoangcung1804npm/assumenda-officiis-repellat'); 37 38jt.traverse(htmlObj, callbacksHtmlList, true); 39 40// <ul> 41// <li>Key: MyArray, Value: 0,0</li> 42// <li>Key: ArrayInArray, Value: 0,1,two,three,4,5,6</li> 43// <li>Key: MyNumber, Value: 123</li> 44// <li>Key: MyString, Value: test</li> 45// <li class="caret">Key: Child</li> 46// <ul class="nested"> 47// <li>Key: ChildVal, Value: 1</li> 48// <li class="caret">Key: SubChild</li> 49// <ul class="nested"> 50// <li>Key: SubChildVal, Value: 777</li> 51// </ul> 52// <li>Key: ChildArray, Value: 1,2,66,9,900</li> 53// </ul> 54// <li>Key: TrailingValue, Value: testtesttest</li> 55// </ul> 56
processValue
: processing a traversed valueenterLevel
: entering a new nesting levelexitLevel
: leaving nesting levelisObjectRoot
flag to indicate if it's an object root (root of a nested object)isArrayElement
flag to indicate if it's an array itemcbSetValue
function to change any value in-place (directly in the traversed object)Traverse the obj
and apply the defined callbacks while traversing.
Type: Object
The object to be traversed.
Type: Object
Default: null
An Object containing the callback functions that should be applied while traversing obj
. Every callback is optional. The expected form is:
1callbacks = { 2 processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => { 3 /* your logic here */ 4 }, 5 enterLevel: (level, path) => { 6 /* your logic here */ 7 }, 8 exitLevel: (level, path) => { 9 /* your logic here */ 10 } 11};
Defined callback function that is executed on each value when traversing the object. Receives the following input parameters:
Type: String
The key of the current value that is processed. If an array is deep-inspected the key for each processed item is _ + Index
(_0
, _1
, _2
,...).
Type: String
The actual value for key
.
Type: Number
The nesting level. 0
indicates the first level.
Type: Array
An array containing all keys that where passed to reach the current key/value pair. Example:
1{ 2 child: { 3 subchild: { 4 myvalue: 123; 5 } 6 } 7}
When processing the value 123
with key myvalue
, path would be ['child', 'subchild' ]
.
For deep-inspected arrays the path would contain the name of the array itself whereas the key would be the index of the processed value. Example:
1{ 2 child: { 3 subchild: { 4 myvalues: [1, 2, 3] 5 } 6 } 7}
When processing the array the keys would be _0
, _1
and _2
and the path would always be ['child', 'subchild', 'myvalues']
.
Type: Boolean
true
if the currently processed key is the root of another sub-object. In our example:
1{ 2 child: { 3 subchild: { 4 myvalue: 123; 5 } 6 } 7}
isObjectRoot
would be true
for the keys child
and subchild
.
Type: Boolean
true
if the currently processed key is an item of an array.
Type: Function
Callback function receiving the newValue
that should replace the currently traversed value
.
Note: Setting a new value directly changes the traversed object! So if you need the original later on be sure to create a copy of the object first.
Defined callback function that is executed on entering a new nesting level when traversing the object. Receives the following input parameters:
Type: Number
0-based index of the nesting level that is entered.
Type: Array
An array containing all keys that where passed to reach the current level that is entered.
Defined callback function that is executed on leaving a nesting level when traversing the object. Receives the following input parameters:
Type: Number
0-based index of the nesting level that is exited.
Type: Array
An array containing all keys that where passed to reach the current level that is exited.
Type: Boolean
Default: false
If set to true
arrays will not be iterated but treated as one single value. The default is false
, where arrays are iterated and each entry is processed separately including deep-inspection, e.g. if the entry is an object or another array.
No vulnerabilities found.
No security vulnerabilities found.