esoftplay 0.0.140-t → 0.0.140-u
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/modules/lib/object.ts +39 -15
- package/package.json +1 -1
package/modules/lib/object.ts
CHANGED
|
@@ -23,32 +23,42 @@ export default class m {
|
|
|
23
23
|
cursorBuilder(command: string, array: any, value: any, ...values: any[]): (cursor?: string | number | FilterByItem, ...cursors: (string | number | FilterByItem)[]) => this {
|
|
24
24
|
return (cursor?: string | number | FilterByItem, ...cursors: (string | number | FilterByItem)[]) => {
|
|
25
25
|
let _value = array
|
|
26
|
-
|
|
26
|
+
let cCursor = [cursor, ...cursors]
|
|
27
|
+
let spec = {}
|
|
28
|
+
let hasError = false
|
|
29
|
+
|
|
30
|
+
cCursor = [cursor, ...cursors].map((item) => {
|
|
27
31
|
if (typeof item == 'string') {
|
|
28
32
|
_value = _value[item]
|
|
29
33
|
return item
|
|
30
34
|
} else if (typeof item == 'function') {
|
|
31
35
|
if (Array.isArray(_value)) {
|
|
32
36
|
const idx = _value.findIndex(item)
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
if (idx > -1) {
|
|
38
|
+
_value = _value[idx]
|
|
39
|
+
return idx
|
|
40
|
+
} else {
|
|
41
|
+
hasError = true
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
35
44
|
} else {
|
|
36
|
-
|
|
45
|
+
hasError = true
|
|
46
|
+
return undefined
|
|
47
|
+
// new Error("LibObject : CursorByFilter must be executed at array")
|
|
37
48
|
}
|
|
38
|
-
} else {
|
|
39
|
-
return item
|
|
40
49
|
}
|
|
41
50
|
});
|
|
42
51
|
|
|
43
52
|
let pathToUpdate = cCursor.filter(x => x != undefined).join('.')
|
|
44
|
-
// let pathToUpdate = [cursor, ...cursors].filter(x => x != undefined).join('.')
|
|
45
53
|
let allValues = [value, ...values].filter(x => x != undefined)
|
|
46
|
-
let spec = {}
|
|
47
54
|
if (pathToUpdate != '')
|
|
48
55
|
spec = { [pathToUpdate]: [command, ...allValues] }
|
|
49
56
|
else
|
|
50
57
|
spec = [command, ...allValues]
|
|
51
|
-
|
|
58
|
+
if (hasError)
|
|
59
|
+
this.#value = array
|
|
60
|
+
else
|
|
61
|
+
this.#value = update(array, spec)
|
|
52
62
|
return this
|
|
53
63
|
}
|
|
54
64
|
}
|
|
@@ -126,29 +136,43 @@ export default class m {
|
|
|
126
136
|
function cursorBuilder(command: string, array: any, value: any, ...values: any[]): (cursor?: string | number | FilterByItem, ...cursors: (string | number | FilterByItem)[]) => any {
|
|
127
137
|
return function (cursor?: string | number | FilterByItem, ...cursors: (string | number | FilterByItem)[]) {
|
|
128
138
|
let _value = array
|
|
129
|
-
|
|
139
|
+
let cCursor = [cursor, ...cursors]
|
|
140
|
+
let spec = {}
|
|
141
|
+
let hasError = false
|
|
142
|
+
|
|
143
|
+
cCursor = [cursor, ...cursors].map((item) => {
|
|
130
144
|
if (typeof item == 'string') {
|
|
131
145
|
_value = _value[item]
|
|
132
146
|
return item
|
|
133
147
|
} else if (typeof item == 'function') {
|
|
134
148
|
if (Array.isArray(_value)) {
|
|
135
149
|
const idx = _value.findIndex(item)
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
if (idx > -1) {
|
|
151
|
+
_value = _value[idx]
|
|
152
|
+
return idx
|
|
153
|
+
} else {
|
|
154
|
+
hasError = true
|
|
155
|
+
return undefined
|
|
156
|
+
}
|
|
138
157
|
} else {
|
|
139
|
-
|
|
158
|
+
hasError = true
|
|
159
|
+
return undefined
|
|
160
|
+
// new Error("LibObject : CursorByFilter must be executed at array")
|
|
140
161
|
}
|
|
141
162
|
}
|
|
142
163
|
});
|
|
143
164
|
|
|
144
165
|
let pathToUpdate = cCursor.filter(x => x != undefined).join('.')
|
|
145
166
|
let allValues = [value, ...values].filter(x => x != undefined)
|
|
146
|
-
let spec = {}
|
|
147
167
|
if (pathToUpdate != '')
|
|
148
168
|
spec = { [pathToUpdate]: [command, ...allValues] }
|
|
149
169
|
else
|
|
150
170
|
spec = [command, ...allValues]
|
|
151
|
-
|
|
171
|
+
|
|
172
|
+
if (hasError)
|
|
173
|
+
return array
|
|
174
|
+
else
|
|
175
|
+
return update(array, spec)
|
|
152
176
|
}
|
|
153
177
|
}
|
|
154
178
|
|