@peter.naydenov/walk-async 1.0.1 → 1.0.3
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 +12 -0
- package/dist/walk-async.min.js +1 -1
- package/package.json +7 -7
- package/src/main.js +10 -3
- package/test/01-deepCopy.test.js +10 -0
package/Changelog.md
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 1.0.1 ( 2022-09-19)
|
|
4
|
+
- [x] Fix: Deep copy process is losing object properties that are equal to 'null';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### 1.0.1 ( 2022-09-19)
|
|
9
|
+
- [x] Fix: Deep copy is not working.
|
|
10
|
+
- [ ] Bug: Deep copy process is losing object properties that are equal to 'null';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
### 1.0.0 (2022-09-18)
|
|
4
15
|
- [x] Initial code;
|
|
5
16
|
- [x] Test package;
|
|
6
17
|
- [x] Documentation;
|
|
18
|
+
- [ ] Bug: Deep copy is not working.
|
|
7
19
|
|
|
8
20
|
|
package/dist/walk-async.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var walk;(()=>{var e={406:e=>{"use strict";function n(){let e,n;const t=new Promise(((o,t)=>{e=o,n=t}));return{promise:t,done:e,cancel:n,onComplete:o(t)}}function o(e){return function(n){e.then((e=>n(e)))}}e.exports=function(e){let t,r=!1;return e?(t=function(e){let t=e.map((e=>n())),r=t.map((e=>e.promise));return t.promises=r,t.onComplete=o(Promise.all(r)),t}(e),r=!0):t=n(),t.timeout=function(e,n){let t;return t=e?Promise.all(n.promises):n.promise,function(e,r){let s
|
|
1
|
+
var walk;(()=>{var e={406:e=>{"use strict";function n(){let e,n;const t=new Promise(((o,t)=>{e=o,n=t}));return{promise:t,done:e,cancel:n,onComplete:o(t)}}function o(e){return function(n){e.then((e=>n(e)))}}e.exports=function(e){let t,r=!1;return e?(t=function(e){let t=e.map((e=>n())),r=t.map((e=>e.promise));return t.promises=r,t.onComplete=o(Promise.all(r)),t}(e),r=!0):t=n(),t.timeout=function(e,n){let t;return t=e?Promise.all(n.promises):n.promise,function(e,r){let l,s=new Promise(((n,o)=>{l=setTimeout((()=>{n(r),Promise.resolve(t)}),e)}));return t.then((()=>clearTimeout(l))),n.onComplete=o(Promise.race([t,s])),n}}(r,t),t}},880:(e,n,o)=>{const t=o(406);async function r(e,n,o){for await(const n of e)await n.next();o.done(n)}function l(e){return null==e||"boolean"==typeof e?"simple":e instanceof Array?"array":"object"==typeof e?"object":"simple"}async function*s(e,n,o,t,r){yield await a(e,n,o,t,r)}function a(e,n,o,r,a){let[i,c]=r,u=Object.keys(e),p=t(u),m=t();return u.forEach(((u,m)=>{let f=l(e[u]),d=e[u],$="simple"!==f&&null!=c,y=t(),b=t(),v=t(),h="array"===l(n),k=!isNaN(u);$?c({resolve:y.done,reject:()=>y.done(null),value:d,key:u,breadcrumbs:`${a}/${u}`}):y.done("$$cancel"),y.onComplete((e=>{if("$$cancel"!==e||null!=d)if("$$cancel"!==e&&(d=e,f=l(d)),null!=d)if("simple"===f){if(!i)return void b.done("$$noUpdates");i({resolve:b.done,reject:()=>b.done(null),value:d,key:u,breadcrumbs:`${a}/${u}`})}else b.done("$$cancel");else p[m].done();else b.done("$$noUpdates")})),b.onComplete((e=>{if(null!=e)if("$$cancel"!==e){if("$$noUpdates"!==e&&(d=e,f=l(d)),"simple"===f){const e=function(e,n){return n instanceof Array&&!isNaN(e)}(u,n);return e?n.push(d):n[u]=d,void p[m].done("key")}v.done()}else v.done();else p[m].done("nulls")})),v.onComplete((()=>{if("object"===f){const e={};h&&k?n.push(e):n[u]=e,o.push(s(d,e,o,r,`${a}/${u}`)),p[m].done("object")}if("array"===f){const e=[];h&&k?n.push(e):n[u]=e,o.push(s(d,e,o,r,`${a}/${u}`)),p[m].done("array")}}))})),p.onComplete((e=>m.done())),m.promise}e.exports=function(e){let n,{data:o,objectCallback:s=null,keyCallback:i=null}=e,c=l(o),u=[],p="root",m=[i,s],f=t();switch(c){case"array":n=[],a(o,n,u,m,p).then((()=>r(u,n,f)));break;case"object":n={},a(o,n,u,m,p).then((()=>{r(u,n,f)}));break;case"simple":f.done(o)}return f.promise}}},n={},o=function o(t){var r=n[t];if(void 0!==r)return r.exports;var l=n[t]={exports:{}};return e[t](l,l.exports,o),l.exports}(880);walk=o})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/walk-async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Deep copy with fine control during the process. Can be used also as a deep forEach function",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"ask-for-promise": "1.3.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@babel/core": "^7.
|
|
22
|
-
"@babel/preset-env": "^7.
|
|
23
|
-
"babel-loader": "^
|
|
24
|
-
"chai": "^4.3.
|
|
25
|
-
"mocha": "^10.
|
|
21
|
+
"@babel/core": "^7.20.2",
|
|
22
|
+
"@babel/preset-env": "^7.20.2",
|
|
23
|
+
"babel-loader": "^9.1.0",
|
|
24
|
+
"chai": "^4.3.7",
|
|
25
|
+
"mocha": "^10.1.0",
|
|
26
26
|
"nyc": "^15.1.0",
|
|
27
|
-
"webpack": "^5.
|
|
27
|
+
"webpack": "^5.75.0",
|
|
28
28
|
"webpack-cli": "^4.10.0"
|
|
29
29
|
},
|
|
30
30
|
"nyc": {
|
package/src/main.js
CHANGED
|
@@ -62,8 +62,10 @@ async function goNext ( extend, result, end ) {
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
function findType ( x ) {
|
|
65
|
-
if ( x
|
|
66
|
-
if ( typeof x === '
|
|
65
|
+
if ( x == null ) return 'simple'
|
|
66
|
+
if ( typeof x === 'boolean' ) return 'simple'
|
|
67
|
+
if ( x instanceof Array ) return 'array'
|
|
68
|
+
if ( typeof x === 'object' ) return 'object'
|
|
67
69
|
return 'simple'
|
|
68
70
|
} // findType func.
|
|
69
71
|
|
|
@@ -91,6 +93,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs ) {
|
|
|
91
93
|
, executeCallback = askForPromise ( keys )
|
|
92
94
|
, finish = askForPromise ()
|
|
93
95
|
;
|
|
96
|
+
|
|
94
97
|
keys.forEach ( (k,i) => {
|
|
95
98
|
let
|
|
96
99
|
type = findType(origin[k])
|
|
@@ -117,6 +120,10 @@ function copyObject ( origin, result, extend, cb, breadcrumbs ) {
|
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
objectCallbackTask.onComplete ( res => {
|
|
123
|
+
if ( res === '$$cancel' && item == null ) { // deep copy, no callbacks
|
|
124
|
+
keyCallbackTask.done ( '$$noUpdates' )
|
|
125
|
+
return
|
|
126
|
+
}
|
|
120
127
|
if ( res !== '$$cancel' ) {
|
|
121
128
|
item = res
|
|
122
129
|
type = findType ( item )
|
|
@@ -128,7 +135,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs ) {
|
|
|
128
135
|
if ( type === 'simple' ) {
|
|
129
136
|
if ( !keyCallback ) {
|
|
130
137
|
keyCallbackTask.done ( '$$noUpdates' )
|
|
131
|
-
|
|
138
|
+
return
|
|
132
139
|
}
|
|
133
140
|
keyCallback ({
|
|
134
141
|
resolve : keyCallbackTask.done
|
package/test/01-deepCopy.test.js
CHANGED
|
@@ -73,6 +73,16 @@ describe ( 'Walk-async -> Deep copy', () => {
|
|
|
73
73
|
expect ( r.props ).to.not.have.property ( 'test' )
|
|
74
74
|
})
|
|
75
75
|
}) // it Copy a mixed structure
|
|
76
|
+
|
|
77
|
+
it ( 'Data property has value "null"', done => {
|
|
78
|
+
// Fix: Deep copy process is losing object properties that are equal to 'null'
|
|
79
|
+
const x = { name : null };
|
|
80
|
+
walk ({data:x}).then ( r => {
|
|
81
|
+
expect ( r ).to.have.property ( 'name' )
|
|
82
|
+
expect ( r.name ).to.be.equal ( null )
|
|
83
|
+
done ()
|
|
84
|
+
})
|
|
85
|
+
}) // it Data property has value null
|
|
76
86
|
|
|
77
87
|
}) // describe
|
|
78
88
|
|