@peter.naydenov/walk-async 3.0.0 → 3.0.2
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 +11 -0
- package/dist/walk-async.cjs +1 -1
- package/dist/walk-async.esm.mjs +1 -1
- package/dist/walk-async.umd.js +1 -1
- package/package.json +10 -7
- package/src/main.js +30 -9
- package/tsconfig.json +10 -0
- package/types/main.d.ts +35 -0
- package/types/main.d.ts.map +1 -0
package/Changelog.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
### 3.0.2 (2025-01-07)
|
|
6
|
+
- [x] JSDoc was added to the project;
|
|
7
|
+
- [x] Generatated typescript definitions;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 3.0.1 ( 2024-12-18)
|
|
12
|
+
- [x] Dependencies updates. Ask-for-promise to version 3.0.1;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
### 3.0.0 ( 2024-12-04)
|
|
6
17
|
- [x] Object callback will be triggered on 'root' object as well;
|
|
7
18
|
|
package/dist/walk-async.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("ask-for-promise");async function
|
|
1
|
+
"use strict";var e=require("ask-for-promise");async function o(e,o,n){for await(const o of e)await o.next();n.done(o)}function n(e){return null==e||e.nodeType?"simple":e instanceof Array?"array":"object"==typeof e?"object":"simple"}async function*r(e,o,n,r,s,a){yield await t(e,o,n,r,s,...a)}function t(o,t,s,a,i,...c){let[l,d]=a,p=Object.keys(o),u=e(p),f=e();return p.forEach(((p,f)=>{let m=n(o[p]),y=o[p],$="simple"!==m&&null!=d,b=e(),k=e(),h=e(),j="array"===n(t),v=!isNaN(p),C=Symbol("ignore___"),w="root"===i&&"root"===p,N=w?"root":`${i}/${p}`;$?d({resolve:b.done,reject:()=>b.done(C),value:y,key:p,breadcrumbs:N},...c):b.done("$$cancel"),b.onComplete((e=>{if("$$cancel"!==e||l)if("$$cancel"!==e&&(y=e,m=n(y)),y!=C)if("simple"===m){if(!l)return void k.done("$$noUpdates");l({resolve:k.done,reject:()=>k.done(C),value:y,key:p,breadcrumbs:N},...c)}else k.done("$$cancel");else u.promises[f].done("ignore object");else k.done("$$noUpdates")})),k.onComplete((e=>{if(w)return s.push(r(y,t,s,a,"root",c)),void u.promises[f].done("root");if(e!=C)if("$$cancel"!==e){if("$$noUpdates"!==e&&(y=e,m=n(y)),"simple"===m){const e=function(e,o){return o instanceof Array&&!isNaN(e)}(p,t);return e?t.push(y):t[p]=y,void u.promises[f].done("key")}h.done()}else h.done();else u.promises[f].done("ignore key")})),h.onComplete((()=>{if("object"===m){const e={};j&&v?t.push(e):t[p]=e,s.push(r(y,e,s,a,N,c)),u.promises[f].done("object")}if("array"===m){const e=[];j&&v?t.push(e):t[p]=e,s.push(r(y,e,s,a,N,c)),u.promises[f].done("array")}}))})),u.onComplete((e=>f.done())),f.promise}module.exports=function({data:r,objectCallback:s=null,keyCallback:a=null},...i){let c,l=n(r),d=[],p="root",u=[a,s],f=e();switch(l){case"array":c=[],t({root:r},c,d,u,p,...i).then((()=>o(d,c,f)));break;case"object":c={},t({root:r},c,d,u,p,...i).then((()=>{o(d,c,f)}));break;case"simple":f.done(r)}return f.promise};
|
package/dist/walk-async.esm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"ask-for-promise";function o({data:o,objectCallback:t=null,keyCallback:
|
|
1
|
+
import e from"ask-for-promise";function o({data:o,objectCallback:t=null,keyCallback:a=null},...i){let c,l=r(o),p=[],d="root",u=[a,t],f=e();switch(l){case"array":c=[],s({root:o},c,p,u,d,...i).then((()=>n(p,c,f)));break;case"object":c={},s({root:o},c,p,u,d,...i).then((()=>{n(p,c,f)}));break;case"simple":f.done(o)}return f.promise}async function n(e,o,n){for await(const o of e)await o.next();n.done(o)}function r(e){return null==e||e.nodeType?"simple":e instanceof Array?"array":"object"==typeof e?"object":"simple"}async function*t(e,o,n,r,t,a){yield await s(e,o,n,r,t,...a)}function s(o,n,s,a,i,...c){let[l,p]=a,d=Object.keys(o),u=e(d),f=e();return d.forEach(((d,f)=>{let m=r(o[d]),y=o[d],$="simple"!==m&&null!=p,b=e(),k=e(),h=e(),j="array"===r(n),v=!isNaN(d),C=Symbol("ignore___"),w="root"===i&&"root"===d,N=w?"root":`${i}/${d}`;$?p({resolve:b.done,reject:()=>b.done(C),value:y,key:d,breadcrumbs:N},...c):b.done("$$cancel"),b.onComplete((e=>{if("$$cancel"!==e||l)if("$$cancel"!==e&&(y=e,m=r(y)),y!=C)if("simple"===m){if(!l)return void k.done("$$noUpdates");l({resolve:k.done,reject:()=>k.done(C),value:y,key:d,breadcrumbs:N},...c)}else k.done("$$cancel");else u.promises[f].done("ignore object");else k.done("$$noUpdates")})),k.onComplete((e=>{if(w)return s.push(t(y,n,s,a,"root",c)),void u.promises[f].done("root");if(e!=C)if("$$cancel"!==e){if("$$noUpdates"!==e&&(y=e,m=r(y)),"simple"===m){const e=function(e,o){return o instanceof Array&&!isNaN(e)}(d,n);return e?n.push(y):n[d]=y,void u.promises[f].done("key")}h.done()}else h.done();else u.promises[f].done("ignore key")})),h.onComplete((()=>{if("object"===m){const e={};j&&v?n.push(e):n[d]=e,s.push(t(y,e,s,a,N,c)),u.promises[f].done("object")}if("array"===m){const e=[];j&&v?n.push(e):n[d]=e,s.push(t(y,e,s,a,N,c)),u.promises[f].done("array")}}))})),u.onComplete((e=>f.done())),f.promise}export{o as default};
|
package/dist/walk-async.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("ask-for-promise")):"function"==typeof define&&define.amd?define(["ask-for-promise"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).walkAsync=o(e.askForPromise)}(this,(function(e){"use strict";async function o(e,o,n){for await(const o of e)await o.next();n.done(o)}function n(e){return null==e||e.nodeType?"simple":e instanceof Array?"array":"object"==typeof e?"object":"simple"}async function*
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("ask-for-promise")):"function"==typeof define&&define.amd?define(["ask-for-promise"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).walkAsync=o(e.askForPromise)}(this,(function(e){"use strict";async function o(e,o,n){for await(const o of e)await o.next();n.done(o)}function n(e){return null==e||e.nodeType?"simple":e instanceof Array?"array":"object"==typeof e?"object":"simple"}async function*r(e,o,n,r,s,i){yield await t(e,o,n,r,s,...i)}function t(o,t,s,i,a,...c){let[l,d]=i,f=Object.keys(o),p=e(f),u=e();return f.forEach(((f,u)=>{let m=n(o[f]),y=o[f],b="simple"!==m&&null!=d,$=e(),k=e(),h=e(),j="array"===n(t),v=!isNaN(f),C=Symbol("ignore___"),g="root"===a&&"root"===f,w=g?"root":`${a}/${f}`;b?d({resolve:$.done,reject:()=>$.done(C),value:y,key:f,breadcrumbs:w},...c):$.done("$$cancel"),$.onComplete((e=>{if("$$cancel"!==e||l)if("$$cancel"!==e&&(y=e,m=n(y)),y!=C)if("simple"===m){if(!l)return void k.done("$$noUpdates");l({resolve:k.done,reject:()=>k.done(C),value:y,key:f,breadcrumbs:w},...c)}else k.done("$$cancel");else p.promises[u].done("ignore object");else k.done("$$noUpdates")})),k.onComplete((e=>{if(g)return s.push(r(y,t,s,i,"root",c)),void p.promises[u].done("root");if(e!=C)if("$$cancel"!==e){if("$$noUpdates"!==e&&(y=e,m=n(y)),"simple"===m){const e=function(e,o){return o instanceof Array&&!isNaN(e)}(f,t);return e?t.push(y):t[f]=y,void p.promises[u].done("key")}h.done()}else h.done();else p.promises[u].done("ignore key")})),h.onComplete((()=>{if("object"===m){const e={};j&&v?t.push(e):t[f]=e,s.push(r(y,e,s,i,w,c)),p.promises[u].done("object")}if("array"===m){const e=[];j&&v?t.push(e):t[f]=e,s.push(r(y,e,s,i,w,c)),p.promises[u].done("array")}}))})),p.onComplete((e=>u.done())),u.promise}return function({data:r,objectCallback:s=null,keyCallback:i=null},...a){let c,l=n(r),d=[],f="root",p=[i,s],u=e();switch(l){case"array":c=[],t({root:r},c,d,p,f,...a).then((()=>o(d,c,u)));break;case"object":c={},t({root:r},c,d,p,f,...a).then((()=>{o(d,c,u)}));break;case"simple":u.done(r)}return u.promise}}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/walk-async",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|
|
7
|
+
"types": "./types/main.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
10
|
"import": "./.dist/walk-async.esm.mjs",
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
"scripts": {
|
|
18
19
|
"test": "mocha test",
|
|
19
20
|
"cover": "c8 mocha test",
|
|
20
|
-
"build": "rollup -c"
|
|
21
|
+
"build": "rollup -c",
|
|
22
|
+
"postbuild": "tsc -p tsconfig.json"
|
|
21
23
|
},
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
@@ -26,16 +28,17 @@
|
|
|
26
28
|
"author": "Peter Naydenov",
|
|
27
29
|
"license": "MIT",
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"ask-for-promise": "
|
|
31
|
+
"ask-for-promise": "3.0.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
33
|
-
"@rollup/plugin-node-resolve": "^
|
|
34
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
34
36
|
"@rollup/plugin-terser": "^0.4.4",
|
|
35
|
-
"c8": "^10.1.
|
|
37
|
+
"c8": "^10.1.3",
|
|
36
38
|
"chai": "^5.1.2",
|
|
37
39
|
"mocha": "^11.0.1",
|
|
38
|
-
"rollup": "^4.
|
|
40
|
+
"rollup": "^4.30.0",
|
|
41
|
+
"typescript": "^5.7.2"
|
|
39
42
|
},
|
|
40
43
|
"c8": {
|
|
41
44
|
"include": [
|
package/src/main.js
CHANGED
|
@@ -16,8 +16,28 @@
|
|
|
16
16
|
|
|
17
17
|
import askForPromise from "ask-for-promise"
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} Options
|
|
21
|
+
* @property {Object} data - The data structure to be copied.
|
|
22
|
+
* @property {Function|null} objectCallback - A function called for every object in the data structure.
|
|
23
|
+
* @property {Function|null} keyCallback - A function called for every property in the data structure.
|
|
24
|
+
*/
|
|
25
|
+
|
|
19
26
|
|
|
20
27
|
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Walk-async is a deep copy function that executes callback functions on every object and property.
|
|
31
|
+
* Callbacks are async functions.
|
|
32
|
+
*
|
|
33
|
+
* @param {Options} options - Object with following properties:
|
|
34
|
+
* - data - The data structure to be copied.
|
|
35
|
+
* - objectCallback - A function that will be called for every object in the data structure.
|
|
36
|
+
* - keyCallback - A function that will be called for every property in the data structure.
|
|
37
|
+
* @param {...any} args - Any additional arguments will be passed to the callback functions.
|
|
38
|
+
*
|
|
39
|
+
* @returns {Promise} - A promise that resolves to the immutable copy of the data structure.
|
|
40
|
+
*/
|
|
21
41
|
function walk ({
|
|
22
42
|
data:origin
|
|
23
43
|
, objectCallback = null
|
|
@@ -31,7 +51,7 @@ function walk ({
|
|
|
31
51
|
, cb = [ keyCallback, objectCallback ]
|
|
32
52
|
, end = askForPromise ()
|
|
33
53
|
;
|
|
34
|
-
|
|
54
|
+
|
|
35
55
|
switch ( type ) {
|
|
36
56
|
case 'array' :
|
|
37
57
|
result = []
|
|
@@ -124,7 +144,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
objectCallbackTask.onComplete ( res => {
|
|
127
|
-
if ( res === '$$cancel' &&
|
|
147
|
+
if ( res === '$$cancel' && !keyCallback ) { // deep copy, no callbacks
|
|
128
148
|
keyCallbackTask.done ( '$$noUpdates' )
|
|
129
149
|
return
|
|
130
150
|
}
|
|
@@ -133,7 +153,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
133
153
|
type = findType ( item )
|
|
134
154
|
}
|
|
135
155
|
if ( item == IGNORE ) {
|
|
136
|
-
executeCallback[i].done ( 'ignore object' )
|
|
156
|
+
executeCallback.promises[i].done ( 'ignore object' )
|
|
137
157
|
return
|
|
138
158
|
}
|
|
139
159
|
if ( type === 'simple' ) {
|
|
@@ -157,11 +177,11 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
157
177
|
keyCallbackTask.onComplete ( value => {
|
|
158
178
|
if ( isRoot ) {
|
|
159
179
|
extend.push ( generateList ( item, result, extend, cb, 'root', args ) )
|
|
160
|
-
executeCallback[i].done ( 'root' )
|
|
180
|
+
executeCallback.promises[i].done ( 'root' )
|
|
161
181
|
return
|
|
162
182
|
}
|
|
163
183
|
if ( value == IGNORE ) {
|
|
164
|
-
executeCallback[i].done ( 'ignore key' )
|
|
184
|
+
executeCallback.promises[i].done ( 'ignore key' )
|
|
165
185
|
return
|
|
166
186
|
}
|
|
167
187
|
if ( value === '$$cancel' ) {
|
|
@@ -170,15 +190,16 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
170
190
|
}
|
|
171
191
|
if ( value !== '$$noUpdates' ) {
|
|
172
192
|
item = value
|
|
173
|
-
type = findType ( item )
|
|
193
|
+
type = findType ( item )
|
|
174
194
|
}
|
|
175
195
|
if ( type === 'simple' ) {
|
|
176
196
|
const canInsert = validateForInsertion ( k, result )
|
|
177
197
|
if ( canInsert ) result.push ( item )
|
|
178
198
|
else result [k] = item
|
|
179
|
-
executeCallback[i].done ('key')
|
|
199
|
+
executeCallback.promises[i].done ('key')
|
|
180
200
|
return
|
|
181
201
|
}
|
|
202
|
+
|
|
182
203
|
finishWithCallbacks.done ()
|
|
183
204
|
}) // keyCallbackTask complete
|
|
184
205
|
|
|
@@ -188,14 +209,14 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
188
209
|
if ( resultIsArray && keyNumber ) result.push ( newObject )
|
|
189
210
|
else result[k] = newObject
|
|
190
211
|
extend.push ( generateList( item, newObject, extend, cb, br, args ) )
|
|
191
|
-
executeCallback[i].done ('object')
|
|
212
|
+
executeCallback.promises[i].done ('object')
|
|
192
213
|
}
|
|
193
214
|
if ( type === 'array' ) {
|
|
194
215
|
const newArray = [];
|
|
195
216
|
if ( resultIsArray && keyNumber ) result.push ( newArray )
|
|
196
217
|
else result[k] = newArray
|
|
197
218
|
extend.push ( generateList( item, newArray, extend, cb, br, args ) )
|
|
198
|
-
executeCallback[i].done ('array')
|
|
219
|
+
executeCallback.promises[i].done ('array')
|
|
199
220
|
}
|
|
200
221
|
})
|
|
201
222
|
}) // forEach k
|
package/tsconfig.json
ADDED
package/types/main.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default walk;
|
|
2
|
+
export type Options = {
|
|
3
|
+
/**
|
|
4
|
+
* - The data structure to be copied.
|
|
5
|
+
*/
|
|
6
|
+
data: any;
|
|
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":";;;;;;;;;oBAqBc,WAAS,IAAI;;;;iBACb,WAAS,IAAI;;AAJ3B;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,qEARW,OAAO,WAIJ,GAAG,EAAA,gBAmChB"}
|