baja-lite 1.0.4 → 1.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/cjs/boot-remote.d.ts +2 -0
- package/cjs/boot-remote.js +35 -0
- package/cjs/boot.d.ts +2 -0
- package/cjs/boot.js +152 -0
- package/cjs/code.d.ts +1 -0
- package/cjs/code.js +359 -1
- package/cjs/convert-xml.d.ts +10 -0
- package/cjs/convert-xml.js +414 -0
- package/cjs/enum.d.ts +10 -0
- package/cjs/enum.js +32 -0
- package/cjs/error.js +1 -1
- package/cjs/fn.js +3 -3
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +3 -0
- package/cjs/list.d.ts +10 -0
- package/cjs/list.js +36 -0
- package/cjs/object.d.ts +7 -1
- package/cjs/object.js +36 -2
- package/cjs/set-ex.d.ts +41 -15
- package/cjs/set-ex.js +68 -52
- package/cjs/sql.d.ts +760 -305
- package/cjs/sql.js +1702 -1041
- package/cjs/sqlite.d.ts +38 -0
- package/cjs/sqlite.js +194 -0
- package/cjs/test-mysql.d.ts +2 -1
- package/cjs/test-mysql.js +85 -63
- package/cjs/test-sqlite.d.ts +1 -1
- package/cjs/test-sqlite.js +3 -1
- package/cjs/test-xml.d.ts +1 -0
- package/cjs/test-xml.js +75 -0
- package/es/boot-remote.d.ts +2 -0
- package/es/boot-remote.js +31 -0
- package/es/boot.d.ts +2 -0
- package/es/boot.js +125 -0
- package/es/code.d.ts +1 -0
- package/es/code.js +355 -2
- package/es/convert-xml.d.ts +10 -0
- package/es/convert-xml.js +410 -0
- package/es/enum.d.ts +10 -0
- package/es/enum.js +28 -0
- package/es/error.js +1 -1
- package/es/index.d.ts +3 -0
- package/es/index.js +3 -0
- package/es/list.d.ts +10 -0
- package/es/list.js +32 -0
- package/es/object.d.ts +7 -1
- package/es/object.js +28 -1
- package/es/set-ex.d.ts +41 -15
- package/es/set-ex.js +68 -52
- package/es/sql.d.ts +760 -305
- package/es/sql.js +1573 -917
- package/es/sqlite.d.ts +38 -0
- package/es/sqlite.js +164 -0
- package/es/test-mysql.d.ts +2 -1
- package/es/test-mysql.js +85 -64
- package/es/test-sqlite.d.ts +1 -1
- package/es/test-sqlite.js +3 -1
- package/es/test-xml.d.ts +1 -0
- package/es/test-xml.js +70 -0
- package/package.json +15 -10
- package/src/boot-remote.ts +31 -0
- package/src/boot.ts +129 -0
- package/src/code.ts +342 -1
- package/src/convert-xml.ts +462 -0
- package/src/enum.ts +31 -0
- package/src/error.ts +1 -1
- package/src/index.ts +4 -1
- package/src/list.ts +31 -0
- package/src/object.ts +48 -14
- package/src/set-ex.ts +91 -70
- package/src/sql.ts +1652 -965
- package/src/sqlite.ts +161 -0
- package/src/test-mysql.ts +93 -65
- package/src/test-sqlite.ts +3 -1
- package/src/test-xml.ts +70 -0
- package/cjs/constant.d.ts +0 -13
- package/cjs/constant.js +0 -19
- package/cjs/redis.d.ts +0 -0
- package/cjs/redis.js +0 -1
- package/es/constant.d.ts +0 -13
- package/es/constant.js +0 -16
- package/es/redis.d.ts +0 -0
- package/es/redis.js +0 -1
- package/src/constant.ts +0 -14
- package/src/redis.ts +0 -0
package/es/set-ex.js
CHANGED
|
@@ -6,25 +6,17 @@ export class SetEx extends Set {
|
|
|
6
6
|
* @param replaceWhenExits 当存在时是否覆盖?
|
|
7
7
|
* @param values 初始数组
|
|
8
8
|
*/
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(option) {
|
|
10
10
|
super();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
else {
|
|
21
|
-
this.whenOnExist = onExist;
|
|
22
|
-
this.uniqueKey = key;
|
|
23
|
-
this.replaceItemWhenExits = replaceWhenExits;
|
|
24
|
-
this.whenOnNotExist = onNotExist;
|
|
25
|
-
if (values) {
|
|
26
|
-
this.addAll(...values);
|
|
27
|
-
}
|
|
11
|
+
this._key = option.key;
|
|
12
|
+
this._onExist1 = option.onExist1;
|
|
13
|
+
this._onNotExist1 = option.onNotExist1;
|
|
14
|
+
this._replaceIfExits1 = option.replaceIfExits1 === true;
|
|
15
|
+
this._onExist2 = option.onExist2;
|
|
16
|
+
this._onNotExist2 = option.onNotExist2;
|
|
17
|
+
this._replaceIfExits2 = option.replaceIfExits2 === true;
|
|
18
|
+
if (option.values) {
|
|
19
|
+
this.addAll(...option.values);
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
22
|
/**
|
|
@@ -36,12 +28,12 @@ export class SetEx extends Set {
|
|
|
36
28
|
add(value) {
|
|
37
29
|
let flag = false;
|
|
38
30
|
this.forEach((item) => {
|
|
39
|
-
if (item[this.
|
|
31
|
+
if (item[this._key] === value[this._key]) {
|
|
40
32
|
flag = true;
|
|
41
|
-
if (this.
|
|
42
|
-
this.
|
|
33
|
+
if (this._onExist1) {
|
|
34
|
+
this._onExist1(item, value);
|
|
43
35
|
}
|
|
44
|
-
if (this.
|
|
36
|
+
if (this._replaceIfExits1 === true) {
|
|
45
37
|
super.delete(item);
|
|
46
38
|
flag = false;
|
|
47
39
|
}
|
|
@@ -50,8 +42,8 @@ export class SetEx extends Set {
|
|
|
50
42
|
});
|
|
51
43
|
if (flag === false) {
|
|
52
44
|
super.add(value);
|
|
53
|
-
if (this.
|
|
54
|
-
this.
|
|
45
|
+
if (this._onNotExist1) {
|
|
46
|
+
this._onNotExist1(value);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
return this;
|
|
@@ -77,13 +69,13 @@ export class SetEx extends Set {
|
|
|
77
69
|
let flag = false;
|
|
78
70
|
let tmp = value;
|
|
79
71
|
this.forEach((item) => {
|
|
80
|
-
if (item[this.
|
|
72
|
+
if (item[this._key] === value[this._key]) {
|
|
81
73
|
flag = true;
|
|
82
|
-
if (this.
|
|
83
|
-
this.
|
|
74
|
+
if (this._onExist2) {
|
|
75
|
+
this._onExist2(item, value);
|
|
84
76
|
}
|
|
85
|
-
if (this.
|
|
86
|
-
super.delete(
|
|
77
|
+
if (this._replaceIfExits2 === true) {
|
|
78
|
+
super.delete(value);
|
|
87
79
|
flag = false;
|
|
88
80
|
}
|
|
89
81
|
else {
|
|
@@ -94,8 +86,8 @@ export class SetEx extends Set {
|
|
|
94
86
|
});
|
|
95
87
|
if (flag === false) {
|
|
96
88
|
super.add(value);
|
|
97
|
-
if (this.
|
|
98
|
-
this.
|
|
89
|
+
if (this._onNotExist2) {
|
|
90
|
+
this._onNotExist2(value);
|
|
99
91
|
}
|
|
100
92
|
}
|
|
101
93
|
return tmp;
|
|
@@ -120,7 +112,7 @@ export class SetEx extends Set {
|
|
|
120
112
|
*/
|
|
121
113
|
find(value) {
|
|
122
114
|
for (const item of this) {
|
|
123
|
-
if (item[this.
|
|
115
|
+
if (item[this._key] === value) {
|
|
124
116
|
return item;
|
|
125
117
|
}
|
|
126
118
|
}
|
|
@@ -134,7 +126,7 @@ export class SetEx extends Set {
|
|
|
134
126
|
findAll(value) {
|
|
135
127
|
const res = new Array();
|
|
136
128
|
this.forEach((item) => {
|
|
137
|
-
if (item[this.
|
|
129
|
+
if (item[this._key] === value) {
|
|
138
130
|
res.push(item);
|
|
139
131
|
}
|
|
140
132
|
});
|
|
@@ -177,7 +169,7 @@ export class SetEx extends Set {
|
|
|
177
169
|
*/
|
|
178
170
|
has(value) {
|
|
179
171
|
for (const item of this) {
|
|
180
|
-
if (item[this.
|
|
172
|
+
if (item[this._key] === value) {
|
|
181
173
|
return true;
|
|
182
174
|
}
|
|
183
175
|
}
|
|
@@ -222,7 +214,7 @@ export class SetEx extends Set {
|
|
|
222
214
|
*/
|
|
223
215
|
delete(value) {
|
|
224
216
|
for (const item of this) {
|
|
225
|
-
if (item[this.
|
|
217
|
+
if (item[this._key] === value) {
|
|
226
218
|
super.delete(item);
|
|
227
219
|
return true;
|
|
228
220
|
}
|
|
@@ -236,20 +228,32 @@ export class SetEx extends Set {
|
|
|
236
228
|
* @param {(oldData: T, newData: T) => void} [onExist]
|
|
237
229
|
* @param {boolean} [replaceWhenExits=false]
|
|
238
230
|
*/
|
|
239
|
-
reset(
|
|
240
|
-
|
|
241
|
-
|
|
231
|
+
reset(option) {
|
|
232
|
+
this.clear();
|
|
233
|
+
if (option.key) {
|
|
234
|
+
this._key = option.key;
|
|
242
235
|
}
|
|
243
|
-
if (
|
|
244
|
-
this.
|
|
236
|
+
if (option.onExist1) {
|
|
237
|
+
this._onExist1 = option.onExist1;
|
|
245
238
|
}
|
|
246
|
-
if (
|
|
247
|
-
this.
|
|
239
|
+
if (option.onNotExist1) {
|
|
240
|
+
this._onNotExist1 = option.onNotExist1;
|
|
248
241
|
}
|
|
249
|
-
if (
|
|
250
|
-
this.
|
|
242
|
+
if (option.replaceIfExits1) {
|
|
243
|
+
this._replaceIfExits1 = option.replaceIfExits1;
|
|
244
|
+
}
|
|
245
|
+
if (option.onExist2) {
|
|
246
|
+
this._onExist2 = option.onExist2;
|
|
247
|
+
}
|
|
248
|
+
if (option.onNotExist2) {
|
|
249
|
+
this._onNotExist2 = option.onNotExist2;
|
|
250
|
+
}
|
|
251
|
+
if (option.replaceIfExits2) {
|
|
252
|
+
this._replaceIfExits2 = option.replaceIfExits2;
|
|
253
|
+
}
|
|
254
|
+
if (option.values) {
|
|
255
|
+
this.addAll(...option.values);
|
|
251
256
|
}
|
|
252
|
-
this.clear();
|
|
253
257
|
return this;
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
@@ -310,7 +314,7 @@ export class SetEx extends Set {
|
|
|
310
314
|
const result = {};
|
|
311
315
|
const list = this.toArray({ sort, each, filter, map });
|
|
312
316
|
for (const item of list) {
|
|
313
|
-
const name = item[this.
|
|
317
|
+
const name = item[this._key];
|
|
314
318
|
for (const key in item) {
|
|
315
319
|
if (!result[key]) {
|
|
316
320
|
result[key] = [];
|
|
@@ -320,13 +324,25 @@ export class SetEx extends Set {
|
|
|
320
324
|
}
|
|
321
325
|
return result;
|
|
322
326
|
}
|
|
323
|
-
set
|
|
324
|
-
this.
|
|
327
|
+
set onExist1(onExist1) {
|
|
328
|
+
this._onExist1 = onExist1;
|
|
325
329
|
}
|
|
326
|
-
set
|
|
327
|
-
this.
|
|
330
|
+
set onExist2(onExist2) {
|
|
331
|
+
this._onExist2 = onExist2;
|
|
332
|
+
}
|
|
333
|
+
set onNotExist1(onNotExist1) {
|
|
334
|
+
this._onNotExist1 = onNotExist1;
|
|
328
335
|
}
|
|
329
|
-
set
|
|
330
|
-
this.
|
|
336
|
+
set onNotExist2(onNotExist2) {
|
|
337
|
+
this._onNotExist2 = onNotExist2;
|
|
338
|
+
}
|
|
339
|
+
set replaceIfExits1(replaceIfExits1) {
|
|
340
|
+
this._replaceIfExits1 = replaceIfExits1;
|
|
341
|
+
}
|
|
342
|
+
set replaceIfExits2(replaceIfExits2) {
|
|
343
|
+
this._replaceIfExits2 = replaceIfExits2;
|
|
344
|
+
}
|
|
345
|
+
set key(key) {
|
|
346
|
+
this._key = key;
|
|
331
347
|
}
|
|
332
348
|
}
|