@peter.naydenov/walk-async 3.0.4 → 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
@@ -1,6 +1,17 @@
1
1
  # Release History
2
2
 
3
3
 
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
+
10
+ ### 3.0.5 (2026-05-05)
11
+ - [x] Dependencies updates. Ask-for-promise to version 3.1.1;
12
+
13
+
14
+
4
15
  ### 3.0.4 (2025-10-28)
5
16
  - [x] Dependencies updates. Ask-for-promise to version 3.1.0;
6
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peter.naydenov/walk-async",
3
- "version": "3.0.4",
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",
@@ -28,17 +28,21 @@
28
28
  "author": "Peter Naydenov",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "ask-for-promise": "3.1.0"
31
+ "ask-for-promise": "^3.1.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^28.0.9",
34
+ "@rollup/plugin-commonjs": "^29.0.3",
35
35
  "@rollup/plugin-node-resolve": "^16.0.3",
36
- "@rollup/plugin-terser": "^0.4.4",
37
- "c8": "^10.1.3",
38
- "chai": "^6.2.0",
39
- "mocha": "^11.7.4",
40
- "rollup": "^4.52.5",
41
- "typescript": "^5.9.3"
36
+ "@rollup/plugin-terser": "^1.0.0",
37
+ "c8": "^11.0.0",
38
+ "chai": "^6.2.2",
39
+ "mocha": "^11.7.6",
40
+ "rollup": "^4.62.2",
41
+ "typescript": "^6.0.3"
42
+ },
43
+ "overrides": {
44
+ "diff": "^8.0.2",
45
+ "serialize-javascript": "^7.0.0"
42
46
  },
43
47
  "c8": {
44
48
  "include": [
@@ -54,5 +58,8 @@
54
58
  "text-summary"
55
59
  ]
56
60
  },
57
- "browserslist": "> 2%, not dead"
61
+ "browserslist": "> 2%, not dead",
62
+ "allowScripts": {
63
+ "fsevents@2.3.3": true
64
+ }
58
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
 
package/tsconfig.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "allowJs": true,
5
5
  "declaration": true,
6
6
  "emitDeclarationOnly": true,
7
+ "rootDir": "./src",
7
8
  "outDir": "types",
8
9
  "declarationMap": true
9
10
  }
package/types/main.d.ts CHANGED
@@ -3,7 +3,7 @@ export type Options = {
3
3
  /**
4
4
  * - The data structure to be copied.
5
5
  */
6
- data: any;
6
+ data: Object;
7
7
  /**
8
8
  * - A function called for every object in the data structure.
9
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.js"],"names":[],"mappings":";;;;;;;;;oBAqBc,WAAS,IAAI;;;;iBACb,WAAS,IAAI;;AAJ3B;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,qEARW,OAAO,WAIJ,GAAG,EAAA,gBAmChB"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.js"],"names":[],"mappings":";;;;;UAoBc,MAAM;;;;oBACN,WAAS,IAAI;;;;iBACb,WAAS,IAAI;;AAJ3B;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,qEARW,OAAO,WAIJ,GAAG,EAAA,gBAmChB"}
@@ -0,0 +1,35 @@
1
+ export default walk;
2
+ export type Options = {
3
+ /**
4
+ * - The data structure to be copied.
5
+ */
6
+ data: Object;
7
+ /**
8
+ * - A function called for every object in the data structure.
9
+ */
10
+ objectCallback: Function | null;
11
+ /**
12
+ * - A function called for every property in the data structure.
13
+ */
14
+ keyCallback: Function | null;
15
+ };
16
+ /**
17
+ * @typedef {Object} Options
18
+ * @property {Object} data - The data structure to be copied.
19
+ * @property {Function|null} objectCallback - A function called for every object in the data structure.
20
+ * @property {Function|null} keyCallback - A function called for every property in the data structure.
21
+ */
22
+ /**
23
+ * Walk-async is a deep copy function that executes callback functions on every object and property.
24
+ * Callbacks are async functions.
25
+ *
26
+ * @param {Options} options - Object with following properties:
27
+ * - data - The data structure to be copied.
28
+ * - objectCallback - A function that will be called for every object in the data structure.
29
+ * - keyCallback - A function that will be called for every property in the data structure.
30
+ * @param {...any} args - Any additional arguments will be passed to the callback functions.
31
+ *
32
+ * @returns {Promise} - A promise that resolves to the immutable copy of the data structure.
33
+ */
34
+ declare function walk({ data: origin, objectCallback, keyCallback }: Options, ...args: any[]): Promise<any>;
35
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.js"],"names":[],"mappings":";;;;;UAoBc,MAAM;;;;oBACN,WAAS,IAAI;;;;iBACb,WAAS,IAAI;;AAJ3B;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,qEARW,OAAO,WAIJ,GAAG,EAAA,gBAmChB"}