@peter.naydenov/walk-async 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Changelog.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
 
4
4
 
5
+ ### 3.0.6 (2026-07-07)
6
+ - [x] Fix: Top-level property named 'root' was flattened into the result or dropped;
7
+
8
+
9
+
5
10
  ### 3.0.5 (2026-05-05)
6
11
  - [x] Dependencies updates. Ask-for-promise to version 3.1.1;
7
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peter.naydenov/walk-async",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Deep copy with fine control during the process. Can be used also as a deep forEach function",
5
5
  "main": ".dist/walk-async.umd.js",
6
6
  "type": "module",
@@ -31,13 +31,13 @@
31
31
  "ask-for-promise": "^3.1.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^29.0.2",
34
+ "@rollup/plugin-commonjs": "^29.0.3",
35
35
  "@rollup/plugin-node-resolve": "^16.0.3",
36
36
  "@rollup/plugin-terser": "^1.0.0",
37
37
  "c8": "^11.0.0",
38
38
  "chai": "^6.2.2",
39
- "mocha": "^11.7.5",
40
- "rollup": "^4.60.3",
39
+ "mocha": "^11.7.6",
40
+ "rollup": "^4.62.2",
41
41
  "typescript": "^6.0.3"
42
42
  },
43
43
  "overrides": {
@@ -58,5 +58,8 @@
58
58
  "text-summary"
59
59
  ]
60
60
  },
61
- "browserslist": "> 2%, not dead"
61
+ "browserslist": "> 2%, not dead",
62
+ "allowScripts": {
63
+ "fsevents@2.3.3": true
64
+ }
62
65
  }
package/src/main.js CHANGED
@@ -55,12 +55,12 @@ function walk ({
55
55
  switch ( type ) {
56
56
  case 'array' :
57
57
  result = []
58
- copyObject ( {root:origin}, result, extend, cb, breadcrumbs, ...args )
58
+ copyObject ( {root:origin}, result, extend, cb, breadcrumbs, true, ...args )
59
59
  .then ( () => goNext ( extend, result, end ))
60
60
  break
61
61
  case 'object' :
62
62
  result = {}
63
- copyObject ( {root:origin}, result, extend, cb, breadcrumbs, ...args )
63
+ copyObject ( {root:origin}, result, extend, cb, breadcrumbs, true, ...args )
64
64
  .then ( () => {
65
65
  goNext ( extend, result, end )
66
66
  })
@@ -93,7 +93,7 @@ function findType ( x ) {
93
93
 
94
94
 
95
95
  async function* generateList ( data, location, ex, cb, breadcrumbs, args ) {
96
- yield await copyObject ( data , location, ex, cb, breadcrumbs, ...args )
96
+ yield await copyObject ( data , location, ex, cb, breadcrumbs, false, ...args )
97
97
  } // generateList func.
98
98
 
99
99
 
@@ -107,7 +107,10 @@ function validateForInsertion ( k, result ) {
107
107
 
108
108
 
109
109
 
110
- function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
110
+ // 'isWrapper' is true only for the call from 'walk' where 'origin' is the
111
+ // synthetic {root:origin} wrapper. Detecting the wrapper by its position in the
112
+ // call chain (instead of by key name) keeps data keys named 'root' safe.
113
+ function copyObject ( origin, result, extend, cb, breadcrumbs, isWrapper, ...args ) {
111
114
  let
112
115
  [ keyCallback, objectCallback ] = cb
113
116
  , keys = Object.keys ( origin )
@@ -126,7 +129,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
126
129
  , resultIsArray = (findType (result) === 'array')
127
130
  , keyNumber = !isNaN ( k )
128
131
  , IGNORE = Symbol ( 'ignore___' )
129
- , isRoot = (breadcrumbs === 'root' && k === 'root' )
132
+ , isRoot = isWrapper // The wrapper has exactly one key: 'root'
130
133
  , br = isRoot ? 'root' : `${breadcrumbs}/${k}`
131
134
  ;
132
135