lodash-walk-object 13.1.44 → 13.1.45
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/assets/shared/shared_folder_info.txt +1 -1
- package/browser/README.md +24 -24
- package/browser/esm2020/lib/index.mjs +337 -337
- package/browser/esm2020/lib/models.mjs +3 -3
- package/browser/esm2020/lodash-walk-object.mjs +4 -4
- package/browser/esm2020/public-api.mjs +1 -1
- package/browser/fesm2015/lodash-walk-object.mjs +336 -336
- package/browser/fesm2020/lodash-walk-object.mjs +336 -336
- package/browser/lib/index.d.ts +26 -26
- package/browser/lib/models.d.ts +43 -43
- package/browser/lodash-walk-object.d.ts +4 -4
- package/client/README.md +24 -24
- package/client/esm2020/lib/index.mjs +337 -337
- package/client/esm2020/lib/models.mjs +3 -3
- package/client/esm2020/lodash-walk-object.mjs +4 -4
- package/client/esm2020/public-api.mjs +1 -1
- package/client/fesm2015/lodash-walk-object.mjs +336 -336
- package/client/fesm2020/lodash-walk-object.mjs +336 -336
- package/client/lib/index.d.ts +26 -26
- package/client/lib/models.d.ts +43 -43
- package/client/lodash-walk-object.d.ts +4 -4
- package/client/package.json +33 -31
- package/index.d.ts +1 -1
- package/index.js.map +1 -1
- package/lib/index.d.ts +27 -27
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +44 -44
- package/lib/models.js.map +1 -1
- package/package.json +3 -3
- package/package.json_devDependencies.json +224 -224
- package/package.json_tnp.json5 +40 -40
- package/tmp-environment.json +37 -35
- package/websql/README.md +24 -24
- package/websql/esm2020/lib/index.mjs +337 -337
- package/websql/esm2020/lib/models.mjs +3 -3
- package/websql/esm2020/lodash-walk-object.mjs +4 -4
- package/websql/esm2020/public-api.mjs +1 -1
- package/websql/fesm2015/lodash-walk-object.mjs +336 -336
- package/websql/fesm2020/lodash-walk-object.mjs +336 -336
- package/websql/lib/index.d.ts +26 -26
- package/websql/lib/models.d.ts +43 -43
- package/websql/lodash-walk-object.d.ts +4 -4
|
@@ -1,346 +1,346 @@
|
|
|
1
1
|
import { _ } from 'tnp-core/browser';
|
|
2
2
|
import { CLASS } from 'typescript-class-helpers/browser';
|
|
3
3
|
|
|
4
|
-
;
|
|
4
|
+
;
|
|
5
5
|
({}); // @--end-of-file-for-module=lodash-walk-object lib/models.ts
|
|
6
6
|
|
|
7
|
-
function findChildren(ver, lp, walkGetters) {
|
|
8
|
-
const obj = ver.v;
|
|
9
|
-
if (_.isArray(obj)) {
|
|
10
|
-
return obj.map((v, i) => {
|
|
11
|
-
return { v, p: `${lp}[${i}]`, parent: ver, isGetter: false };
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
else if (_.isObject(obj)) {
|
|
15
|
-
const allKeys = !walkGetters ? [] : Object.getOwnPropertyNames(obj);
|
|
16
|
-
const children = [];
|
|
17
|
-
for (const key in obj) {
|
|
18
|
-
if (_.isObject(obj) && _.isFunction(obj.hasOwnProperty) && obj.hasOwnProperty(key)) {
|
|
19
|
-
_.pull(allKeys, key);
|
|
20
|
-
children.push({ v: obj[key], p: `${(lp === '') ? '' : `${lp}.`}${key}`, parent: ver, isGetter: false });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (walkGetters) {
|
|
24
|
-
for (let index = 0; index < allKeys.length; index++) {
|
|
25
|
-
if (_.isObject(obj)) {
|
|
26
|
-
const key = allKeys[index];
|
|
27
|
-
children.push({ v: obj[key], p: `${(lp === '') ? '' : `${lp}.`}${key}`, parent: ver, isGetter: true });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return children;
|
|
32
|
-
}
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
class Helpers {
|
|
36
|
-
static get Walk() {
|
|
37
|
-
const self = this;
|
|
38
|
-
return {
|
|
39
|
-
Object(json, iterator, optionsOrWalkGettersValue) {
|
|
40
|
-
if (_.isUndefined(optionsOrWalkGettersValue)) {
|
|
41
|
-
optionsOrWalkGettersValue = {};
|
|
42
|
-
}
|
|
43
|
-
optionsOrWalkGettersValue.hasIterator = _.isFunction(iterator);
|
|
44
|
-
if (_.isUndefined(optionsOrWalkGettersValue.breadthWalk)) {
|
|
45
|
-
optionsOrWalkGettersValue.breadthWalk = false;
|
|
46
|
-
}
|
|
47
|
-
let { circural } = self._walk(json, json, iterator, void 0, optionsOrWalkGettersValue);
|
|
48
|
-
return { circs: circural };
|
|
49
|
-
},
|
|
50
|
-
ObjectBy(property, inContext, iterator, options) {
|
|
51
|
-
if (_.isFunction(iterator)) {
|
|
52
|
-
iterator(inContext, '', self._changeValue(inContext, property, true)); // TODO Add optoins
|
|
53
|
-
}
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
const json = inContext[property];
|
|
56
|
-
return self.Walk.Object(json, iterator, options);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
static _changeValue(json, lodahPath, simpleChange = false, options) {
|
|
61
|
-
var { contextPath, property } = this._prepareParams(lodahPath);
|
|
62
|
-
var context = _.get(json, contextPath);
|
|
63
|
-
return (newValue) => {
|
|
64
|
-
if (contextPath === '') {
|
|
65
|
-
simpleChange = true;
|
|
66
|
-
}
|
|
67
|
-
if (simpleChange) {
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
json[property] = newValue;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
if (context) {
|
|
73
|
-
context[property] = newValue;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (options) {
|
|
77
|
-
options._valueChanged = true;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
static _prepareParams(lodashPath) {
|
|
82
|
-
const contextPath = this._Helpers.Path.getContextPath(lodashPath);
|
|
83
|
-
let property = this._Helpers.Path.getPropertyPath(lodashPath, contextPath);
|
|
84
|
-
if (_.isString(property) && property.trim() !== '' && !_.isNaN(Number(property))) {
|
|
85
|
-
property = Number(property);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
contextPath, property
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
static get _Helpers() {
|
|
92
|
-
return {
|
|
93
|
-
get Path() {
|
|
94
|
-
return {
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
getPropertyPath(lodahPath, contetPath) {
|
|
97
|
-
return (lodahPath
|
|
98
|
-
.replace(contetPath, '')
|
|
99
|
-
.replace(/^\./, '')
|
|
100
|
-
.replace(/\[/, '')
|
|
101
|
-
.replace(/\]/, ''));
|
|
102
|
-
},
|
|
103
|
-
getContextPath(p) {
|
|
104
|
-
let res;
|
|
105
|
-
if (p.endsWith(']')) {
|
|
106
|
-
res = p.replace(/\[(\"|\')?[0-9]+(\"|\')?\]$/, '');
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
res = p.replace(/\.([a-zA-Z0-9]|\$|\_|\@|\-|\/|\:)+$/, '');
|
|
110
|
-
}
|
|
111
|
-
return res === p ? '' : res;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
static _shoudlReturn(include = [], exclude = [], lodashPath) {
|
|
118
|
-
let res = false;
|
|
119
|
-
if (lodashPath.replace(/^\[(\'|\")?[0-9]*(\'|\")?\]/, '').trim() !== '') {
|
|
120
|
-
lodashPath = lodashPath.replace(/^\[(\'|\")?[0-9]*(\'|\")?\]\./, '');
|
|
121
|
-
res = ((_.isArray(include) && include.length > 0
|
|
122
|
-
&& !include.find(p => lodashPath.startsWith(p)))
|
|
123
|
-
||
|
|
124
|
-
(_.isArray(exclude) && exclude.length > 0
|
|
125
|
-
&& !!exclude.find(p => lodashPath.startsWith(p))));
|
|
126
|
-
}
|
|
127
|
-
return res;
|
|
128
|
-
}
|
|
129
|
-
// @ts-ignore
|
|
130
|
-
static prepareOptions(options, obj, lodashPath) {
|
|
131
|
-
if (options._exit) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (_.isUndefined(options.walkGetters)) {
|
|
135
|
-
options.walkGetters = true;
|
|
136
|
-
}
|
|
137
|
-
if (_.isUndefined(options.checkCircural)) {
|
|
138
|
-
options.checkCircural = false;
|
|
139
|
-
}
|
|
140
|
-
if (_.isUndefined(options.isGetter)) {
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
options.isGetter = false;
|
|
143
|
-
}
|
|
144
|
-
if (_.isUndefined(options._valueChanged)) {
|
|
145
|
-
options._valueChanged = false;
|
|
146
|
-
}
|
|
147
|
-
if (_.isUndefined(options._exit)) {
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
options._exit = false;
|
|
150
|
-
}
|
|
151
|
-
if (_.isUndefined(options.exit)) {
|
|
152
|
-
options.exit = () => {
|
|
153
|
-
options._exit = true;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (_.isUndefined(options._skip)) {
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
options._skip = false;
|
|
159
|
-
}
|
|
160
|
-
if (_.isUndefined(options.skipObject)) {
|
|
161
|
-
options.skipObject = () => {
|
|
162
|
-
options._skip = true;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if (options.checkCircural) {
|
|
166
|
-
if (_.isUndefined(options.db)) {
|
|
167
|
-
options.db = {};
|
|
168
|
-
}
|
|
169
|
-
if (_.isUndefined(options.stack)) {
|
|
170
|
-
options.stack = [];
|
|
171
|
-
}
|
|
172
|
-
if (_.isUndefined(options.circural)) {
|
|
173
|
-
options.circural = [];
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const { db, stack } = options;
|
|
177
|
-
options.isCircural = false;
|
|
178
|
-
if (options.checkCircural && _.isObject(obj)) {
|
|
179
|
-
let indexValue = CLASS.OBJECT(obj).indexValue;
|
|
180
|
-
if (CLASS.OBJECT(obj).isClassObject && !_.isUndefined(indexValue)) {
|
|
181
|
-
let className = CLASS.getNameFromObject(obj);
|
|
182
|
-
let p = `${className}.id_${indexValue}`;
|
|
183
|
-
const inDB = _.get(db, p);
|
|
184
|
-
if (inDB && CLASS.OBJECT(inDB.target).isEqual(obj)) {
|
|
185
|
-
const circ = {
|
|
186
|
-
pathToObj: lodashPath,
|
|
187
|
-
circuralTargetPath: inDB.path
|
|
188
|
-
};
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
options.circural.push(circ);
|
|
191
|
-
options.isCircural = true;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
_.set(db, p, {
|
|
195
|
-
path: lodashPath,
|
|
196
|
-
target: obj
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// @ts-ignore
|
|
202
|
-
const inStack = stack.find((c) => c.target == obj);
|
|
203
|
-
if (!_.isUndefined(inStack)) {
|
|
204
|
-
const circ = {
|
|
205
|
-
pathToObj: lodashPath,
|
|
206
|
-
circuralTargetPath: inStack.path
|
|
207
|
-
};
|
|
208
|
-
// @ts-ignore
|
|
209
|
-
options.circural.push(circ);
|
|
210
|
-
options.isCircural = true;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
stack.push({
|
|
215
|
-
path: lodashPath,
|
|
216
|
-
target: obj
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return options;
|
|
222
|
-
}
|
|
223
|
-
static _walk(json, obj, iterator, lodashPath = '', options, depthLevel = 0) {
|
|
224
|
-
if (!options) {
|
|
225
|
-
options = {};
|
|
226
|
-
}
|
|
227
|
-
// @ts-ignore
|
|
228
|
-
if (!options.breadthWalk) {
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
options = this.prepareOptions(options, obj, lodashPath);
|
|
231
|
-
// @ts-ignore
|
|
232
|
-
if (this._shoudlReturn(options.include, options.exclude, lodashPath)) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
if (options.hasIterator && lodashPath !== '') {
|
|
237
|
-
iterator(obj, lodashPath, this._changeValue(json, lodashPath, false, options), options);
|
|
238
|
-
}
|
|
239
|
-
// @ts-ignore
|
|
240
|
-
if (options._valueChanged) {
|
|
241
|
-
obj = _.get(json, lodashPath);
|
|
242
|
-
}
|
|
243
|
-
options._valueChanged = false;
|
|
244
|
-
if (options.isCircural) {
|
|
245
|
-
options._skip = true;
|
|
246
|
-
}
|
|
247
|
-
if (options._skip) {
|
|
248
|
-
// @ts-ignore
|
|
249
|
-
options._skip = false;
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
if (options.breadthWalk) {
|
|
254
|
-
let queue = [{ v: json, p: lodashPath, parent: void 0 }];
|
|
255
|
-
while (queue.length > 0) {
|
|
256
|
-
const ver = queue.shift();
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
if (this._shoudlReturn(options.include, options.exclude, ver.p)) {
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
// @ts-ignore
|
|
262
|
-
let { v, p } = ver;
|
|
263
|
-
// @ts-ignore
|
|
264
|
-
options = this.prepareOptions(options, v, p);
|
|
265
|
-
if (options._exit) {
|
|
266
|
-
console.log('EXIT');
|
|
267
|
-
return options;
|
|
268
|
-
}
|
|
269
|
-
if (options.hasIterator && p !== '') {
|
|
270
|
-
iterator(v, p, this._changeValue(json, p, false, options), options);
|
|
271
|
-
}
|
|
272
|
-
// @ts-ignore
|
|
273
|
-
if (options._valueChanged) {
|
|
274
|
-
ver.v = _.get(json, p);
|
|
275
|
-
}
|
|
276
|
-
options._valueChanged = false;
|
|
277
|
-
if (options.isCircural) {
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
if (options._skip) {
|
|
281
|
-
// @ts-ignore
|
|
282
|
-
options._skip = false;
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
if (_.isArray(v)) {
|
|
286
|
-
// @ts-ignore
|
|
287
|
-
queue = queue.concat(findChildren(ver, p, options.walkGetters));
|
|
288
|
-
}
|
|
289
|
-
else if (_.isObject(v)) {
|
|
290
|
-
// @ts-ignore
|
|
291
|
-
queue = queue.concat(findChildren(ver, p, options.walkGetters));
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
// @ts-ignore
|
|
297
|
-
const { walkGetters } = options;
|
|
298
|
-
if (Array.isArray(obj)) {
|
|
299
|
-
obj.forEach((o, i) => {
|
|
300
|
-
// @ts-ignore
|
|
301
|
-
this._walk(json, obj[i], iterator, `${lodashPath}[${i}]`, options, depthLevel + 1);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
else if (_.isObject(obj)) {
|
|
305
|
-
const allKeys = !walkGetters ? [] : Object.getOwnPropertyNames(obj);
|
|
306
|
-
for (const key in obj) {
|
|
307
|
-
if (_.isObject(obj) && obj.hasOwnProperty(key)) {
|
|
308
|
-
_.pull(allKeys, key);
|
|
309
|
-
// @ts-ignore
|
|
310
|
-
options.isGetter = false;
|
|
311
|
-
// @ts-ignore
|
|
312
|
-
this._walk(json, obj[key], iterator, `${(lodashPath === '') ? '' : `${lodashPath}.`}${key}`, options, depthLevel + 1);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (walkGetters) {
|
|
316
|
-
for (let index = 0; index < allKeys.length; index++) {
|
|
317
|
-
if (_.isObject(obj)) {
|
|
318
|
-
const key = allKeys[index];
|
|
319
|
-
// @ts-ignore
|
|
320
|
-
options.isGetter = true;
|
|
321
|
-
// @ts-ignore
|
|
322
|
-
this._walk(json, obj[key], iterator, `${(lodashPath === '') ? '' : `${lodashPath}.`}${key}`, options, depthLevel + 1);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
// @ts-ignore
|
|
328
|
-
if (options._exit && json === obj) {
|
|
329
|
-
// @ts-ignore
|
|
330
|
-
options._exit = false;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return options;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
const walk = {
|
|
337
|
-
Object: Helpers.Walk.Object,
|
|
338
|
-
ObjectBy: Helpers.Walk.ObjectBy
|
|
339
|
-
};
|
|
7
|
+
function findChildren(ver, lp, walkGetters) {
|
|
8
|
+
const obj = ver.v;
|
|
9
|
+
if (_.isArray(obj)) {
|
|
10
|
+
return obj.map((v, i) => {
|
|
11
|
+
return { v, p: `${lp}[${i}]`, parent: ver, isGetter: false };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
else if (_.isObject(obj)) {
|
|
15
|
+
const allKeys = !walkGetters ? [] : Object.getOwnPropertyNames(obj);
|
|
16
|
+
const children = [];
|
|
17
|
+
for (const key in obj) {
|
|
18
|
+
if (_.isObject(obj) && _.isFunction(obj.hasOwnProperty) && obj.hasOwnProperty(key)) {
|
|
19
|
+
_.pull(allKeys, key);
|
|
20
|
+
children.push({ v: obj[key], p: `${(lp === '') ? '' : `${lp}.`}${key}`, parent: ver, isGetter: false });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (walkGetters) {
|
|
24
|
+
for (let index = 0; index < allKeys.length; index++) {
|
|
25
|
+
if (_.isObject(obj)) {
|
|
26
|
+
const key = allKeys[index];
|
|
27
|
+
children.push({ v: obj[key], p: `${(lp === '') ? '' : `${lp}.`}${key}`, parent: ver, isGetter: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return children;
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
class Helpers {
|
|
36
|
+
static get Walk() {
|
|
37
|
+
const self = this;
|
|
38
|
+
return {
|
|
39
|
+
Object(json, iterator, optionsOrWalkGettersValue) {
|
|
40
|
+
if (_.isUndefined(optionsOrWalkGettersValue)) {
|
|
41
|
+
optionsOrWalkGettersValue = {};
|
|
42
|
+
}
|
|
43
|
+
optionsOrWalkGettersValue.hasIterator = _.isFunction(iterator);
|
|
44
|
+
if (_.isUndefined(optionsOrWalkGettersValue.breadthWalk)) {
|
|
45
|
+
optionsOrWalkGettersValue.breadthWalk = false;
|
|
46
|
+
}
|
|
47
|
+
let { circural } = self._walk(json, json, iterator, void 0, optionsOrWalkGettersValue);
|
|
48
|
+
return { circs: circural };
|
|
49
|
+
},
|
|
50
|
+
ObjectBy(property, inContext, iterator, options) {
|
|
51
|
+
if (_.isFunction(iterator)) {
|
|
52
|
+
iterator(inContext, '', self._changeValue(inContext, property, true)); // TODO Add optoins
|
|
53
|
+
}
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
const json = inContext[property];
|
|
56
|
+
return self.Walk.Object(json, iterator, options);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
static _changeValue(json, lodahPath, simpleChange = false, options) {
|
|
61
|
+
var { contextPath, property } = this._prepareParams(lodahPath);
|
|
62
|
+
var context = _.get(json, contextPath);
|
|
63
|
+
return (newValue) => {
|
|
64
|
+
if (contextPath === '') {
|
|
65
|
+
simpleChange = true;
|
|
66
|
+
}
|
|
67
|
+
if (simpleChange) {
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
json[property] = newValue;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (context) {
|
|
73
|
+
context[property] = newValue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (options) {
|
|
77
|
+
options._valueChanged = true;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
static _prepareParams(lodashPath) {
|
|
82
|
+
const contextPath = this._Helpers.Path.getContextPath(lodashPath);
|
|
83
|
+
let property = this._Helpers.Path.getPropertyPath(lodashPath, contextPath);
|
|
84
|
+
if (_.isString(property) && property.trim() !== '' && !_.isNaN(Number(property))) {
|
|
85
|
+
property = Number(property);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
contextPath, property
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
static get _Helpers() {
|
|
92
|
+
return {
|
|
93
|
+
get Path() {
|
|
94
|
+
return {
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
getPropertyPath(lodahPath, contetPath) {
|
|
97
|
+
return (lodahPath
|
|
98
|
+
.replace(contetPath, '')
|
|
99
|
+
.replace(/^\./, '')
|
|
100
|
+
.replace(/\[/, '')
|
|
101
|
+
.replace(/\]/, ''));
|
|
102
|
+
},
|
|
103
|
+
getContextPath(p) {
|
|
104
|
+
let res;
|
|
105
|
+
if (p.endsWith(']')) {
|
|
106
|
+
res = p.replace(/\[(\"|\')?[0-9]+(\"|\')?\]$/, '');
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
res = p.replace(/\.([a-zA-Z0-9]|\$|\_|\@|\-|\/|\:)+$/, '');
|
|
110
|
+
}
|
|
111
|
+
return res === p ? '' : res;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
static _shoudlReturn(include = [], exclude = [], lodashPath) {
|
|
118
|
+
let res = false;
|
|
119
|
+
if (lodashPath.replace(/^\[(\'|\")?[0-9]*(\'|\")?\]/, '').trim() !== '') {
|
|
120
|
+
lodashPath = lodashPath.replace(/^\[(\'|\")?[0-9]*(\'|\")?\]\./, '');
|
|
121
|
+
res = ((_.isArray(include) && include.length > 0
|
|
122
|
+
&& !include.find(p => lodashPath.startsWith(p)))
|
|
123
|
+
||
|
|
124
|
+
(_.isArray(exclude) && exclude.length > 0
|
|
125
|
+
&& !!exclude.find(p => lodashPath.startsWith(p))));
|
|
126
|
+
}
|
|
127
|
+
return res;
|
|
128
|
+
}
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
static prepareOptions(options, obj, lodashPath) {
|
|
131
|
+
if (options._exit) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (_.isUndefined(options.walkGetters)) {
|
|
135
|
+
options.walkGetters = true;
|
|
136
|
+
}
|
|
137
|
+
if (_.isUndefined(options.checkCircural)) {
|
|
138
|
+
options.checkCircural = false;
|
|
139
|
+
}
|
|
140
|
+
if (_.isUndefined(options.isGetter)) {
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
options.isGetter = false;
|
|
143
|
+
}
|
|
144
|
+
if (_.isUndefined(options._valueChanged)) {
|
|
145
|
+
options._valueChanged = false;
|
|
146
|
+
}
|
|
147
|
+
if (_.isUndefined(options._exit)) {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
options._exit = false;
|
|
150
|
+
}
|
|
151
|
+
if (_.isUndefined(options.exit)) {
|
|
152
|
+
options.exit = () => {
|
|
153
|
+
options._exit = true;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (_.isUndefined(options._skip)) {
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
options._skip = false;
|
|
159
|
+
}
|
|
160
|
+
if (_.isUndefined(options.skipObject)) {
|
|
161
|
+
options.skipObject = () => {
|
|
162
|
+
options._skip = true;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (options.checkCircural) {
|
|
166
|
+
if (_.isUndefined(options.db)) {
|
|
167
|
+
options.db = {};
|
|
168
|
+
}
|
|
169
|
+
if (_.isUndefined(options.stack)) {
|
|
170
|
+
options.stack = [];
|
|
171
|
+
}
|
|
172
|
+
if (_.isUndefined(options.circural)) {
|
|
173
|
+
options.circural = [];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const { db, stack } = options;
|
|
177
|
+
options.isCircural = false;
|
|
178
|
+
if (options.checkCircural && _.isObject(obj)) {
|
|
179
|
+
let indexValue = CLASS.OBJECT(obj).indexValue;
|
|
180
|
+
if (CLASS.OBJECT(obj).isClassObject && !_.isUndefined(indexValue)) {
|
|
181
|
+
let className = CLASS.getNameFromObject(obj);
|
|
182
|
+
let p = `${className}.id_${indexValue}`;
|
|
183
|
+
const inDB = _.get(db, p);
|
|
184
|
+
if (inDB && CLASS.OBJECT(inDB.target).isEqual(obj)) {
|
|
185
|
+
const circ = {
|
|
186
|
+
pathToObj: lodashPath,
|
|
187
|
+
circuralTargetPath: inDB.path
|
|
188
|
+
};
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
options.circural.push(circ);
|
|
191
|
+
options.isCircural = true;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
_.set(db, p, {
|
|
195
|
+
path: lodashPath,
|
|
196
|
+
target: obj
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
const inStack = stack.find((c) => c.target == obj);
|
|
203
|
+
if (!_.isUndefined(inStack)) {
|
|
204
|
+
const circ = {
|
|
205
|
+
pathToObj: lodashPath,
|
|
206
|
+
circuralTargetPath: inStack.path
|
|
207
|
+
};
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
options.circural.push(circ);
|
|
210
|
+
options.isCircural = true;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
stack.push({
|
|
215
|
+
path: lodashPath,
|
|
216
|
+
target: obj
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return options;
|
|
222
|
+
}
|
|
223
|
+
static _walk(json, obj, iterator, lodashPath = '', options, depthLevel = 0) {
|
|
224
|
+
if (!options) {
|
|
225
|
+
options = {};
|
|
226
|
+
}
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
if (!options.breadthWalk) {
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
options = this.prepareOptions(options, obj, lodashPath);
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
if (this._shoudlReturn(options.include, options.exclude, lodashPath)) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
if (options.hasIterator && lodashPath !== '') {
|
|
237
|
+
iterator(obj, lodashPath, this._changeValue(json, lodashPath, false, options), options);
|
|
238
|
+
}
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
if (options._valueChanged) {
|
|
241
|
+
obj = _.get(json, lodashPath);
|
|
242
|
+
}
|
|
243
|
+
options._valueChanged = false;
|
|
244
|
+
if (options.isCircural) {
|
|
245
|
+
options._skip = true;
|
|
246
|
+
}
|
|
247
|
+
if (options._skip) {
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
options._skip = false;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (options.breadthWalk) {
|
|
254
|
+
let queue = [{ v: json, p: lodashPath, parent: void 0 }];
|
|
255
|
+
while (queue.length > 0) {
|
|
256
|
+
const ver = queue.shift();
|
|
257
|
+
// @ts-ignore
|
|
258
|
+
if (this._shoudlReturn(options.include, options.exclude, ver.p)) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
let { v, p } = ver;
|
|
263
|
+
// @ts-ignore
|
|
264
|
+
options = this.prepareOptions(options, v, p);
|
|
265
|
+
if (options._exit) {
|
|
266
|
+
console.log('EXIT');
|
|
267
|
+
return options;
|
|
268
|
+
}
|
|
269
|
+
if (options.hasIterator && p !== '') {
|
|
270
|
+
iterator(v, p, this._changeValue(json, p, false, options), options);
|
|
271
|
+
}
|
|
272
|
+
// @ts-ignore
|
|
273
|
+
if (options._valueChanged) {
|
|
274
|
+
ver.v = _.get(json, p);
|
|
275
|
+
}
|
|
276
|
+
options._valueChanged = false;
|
|
277
|
+
if (options.isCircural) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (options._skip) {
|
|
281
|
+
// @ts-ignore
|
|
282
|
+
options._skip = false;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (_.isArray(v)) {
|
|
286
|
+
// @ts-ignore
|
|
287
|
+
queue = queue.concat(findChildren(ver, p, options.walkGetters));
|
|
288
|
+
}
|
|
289
|
+
else if (_.isObject(v)) {
|
|
290
|
+
// @ts-ignore
|
|
291
|
+
queue = queue.concat(findChildren(ver, p, options.walkGetters));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// @ts-ignore
|
|
297
|
+
const { walkGetters } = options;
|
|
298
|
+
if (Array.isArray(obj)) {
|
|
299
|
+
obj.forEach((o, i) => {
|
|
300
|
+
// @ts-ignore
|
|
301
|
+
this._walk(json, obj[i], iterator, `${lodashPath}[${i}]`, options, depthLevel + 1);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else if (_.isObject(obj)) {
|
|
305
|
+
const allKeys = !walkGetters ? [] : Object.getOwnPropertyNames(obj);
|
|
306
|
+
for (const key in obj) {
|
|
307
|
+
if (_.isObject(obj) && obj.hasOwnProperty(key)) {
|
|
308
|
+
_.pull(allKeys, key);
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
options.isGetter = false;
|
|
311
|
+
// @ts-ignore
|
|
312
|
+
this._walk(json, obj[key], iterator, `${(lodashPath === '') ? '' : `${lodashPath}.`}${key}`, options, depthLevel + 1);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (walkGetters) {
|
|
316
|
+
for (let index = 0; index < allKeys.length; index++) {
|
|
317
|
+
if (_.isObject(obj)) {
|
|
318
|
+
const key = allKeys[index];
|
|
319
|
+
// @ts-ignore
|
|
320
|
+
options.isGetter = true;
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
this._walk(json, obj[key], iterator, `${(lodashPath === '') ? '' : `${lodashPath}.`}${key}`, options, depthLevel + 1);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// @ts-ignore
|
|
328
|
+
if (options._exit && json === obj) {
|
|
329
|
+
// @ts-ignore
|
|
330
|
+
options._exit = false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return options;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const walk = {
|
|
337
|
+
Object: Helpers.Walk.Object,
|
|
338
|
+
ObjectBy: Helpers.Walk.ObjectBy
|
|
339
|
+
};
|
|
340
340
|
({}); // @--end-of-file-for-module=lodash-walk-object lib/index.ts
|
|
341
341
|
|
|
342
|
-
/**
|
|
343
|
-
* Generated bundle index. Do not edit.
|
|
342
|
+
/**
|
|
343
|
+
* Generated bundle index. Do not edit.
|
|
344
344
|
*/
|
|
345
345
|
|
|
346
346
|
export { Helpers, walk };
|