@fastcar/core 0.3.13 → 0.3.14
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/package.json +1 -1
- package/src/utils/FilterCondition.ts +49 -0
- package/src/utils/ValidationUtil.ts +9 -1
- package/src/utils.ts +2 -1
- package/target/utils/FilterCondition.js +45 -0
- package/target/utils/ValidationUtil.js +7 -1
- package/target/utils.js +3 -1
- package/utils.d.ts +10 -0
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import ValidationUtil from "./ValidationUtil";
|
|
2
|
+
|
|
3
|
+
export default class FilterCondition {
|
|
4
|
+
private where: { [key: string]: any };
|
|
5
|
+
|
|
6
|
+
constructor(where?: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }) {
|
|
7
|
+
this.where = {};
|
|
8
|
+
if (ValidationUtil.isNotNull(where) && where) {
|
|
9
|
+
this.addFiled(where, info);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//过滤空的值
|
|
14
|
+
filterNull(excludeField: string[] = []) {
|
|
15
|
+
let keys = Object.keys(this.where);
|
|
16
|
+
keys.forEach((key) => {
|
|
17
|
+
let value = Reflect.get(this.where, key);
|
|
18
|
+
if (!excludeField.includes(key) && !ValidationUtil.isNotMinSize(value, 1)) {
|
|
19
|
+
Reflect.deleteProperty(this.where, key);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
addFiled(where: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }) {
|
|
27
|
+
let { field = [], excludeField = [] } = info || {};
|
|
28
|
+
let all = field.length == 0 && excludeField.length == 0;
|
|
29
|
+
|
|
30
|
+
for (let key in where) {
|
|
31
|
+
if (all || (field.length > 0 && field.includes(key)) || (field.length == 0 && !excludeField.includes(key))) {
|
|
32
|
+
let value = where[key];
|
|
33
|
+
//排除基础类型,数组和空对象
|
|
34
|
+
if (ValidationUtil.isNotNull(value) && ValidationUtil.isObject(value) && !ValidationUtil.isArray(value, "array")) {
|
|
35
|
+
let beforeObj = Reflect.get(this.where, key) || {};
|
|
36
|
+
Reflect.set(this.where, key, Object.assign({}, beforeObj, where[key]));
|
|
37
|
+
} else {
|
|
38
|
+
Reflect.set(this.where, key, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
toObject() {
|
|
47
|
+
return this.where;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -68,7 +68,15 @@ export default class ValidationUtil {
|
|
|
68
68
|
return param.length >= value;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
if (TypeUtil.isMap(param) || TypeUtil.isSet(param)) {
|
|
72
|
+
return param.size >= value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (ValidationUtil.isNull(param)) {
|
|
76
|
+
return 0 >= value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let v = param.toString();
|
|
72
80
|
return v.length >= value;
|
|
73
81
|
}
|
|
74
82
|
|
package/src/utils.ts
CHANGED
|
@@ -9,6 +9,7 @@ import MixTool from "./utils/Mix";
|
|
|
9
9
|
import TypeUtil from "./utils/TypeUtil";
|
|
10
10
|
import ValidationUtil from "./utils/ValidationUtil";
|
|
11
11
|
import IPUtils from "./utils/IPUtils";
|
|
12
|
+
import FilterCondition from "./utils/FilterCondition";
|
|
12
13
|
|
|
13
14
|
//实用工具集合类
|
|
14
|
-
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils };
|
|
15
|
+
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils, FilterCondition };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ValidationUtil_1 = require("./ValidationUtil");
|
|
4
|
+
class FilterCondition {
|
|
5
|
+
where;
|
|
6
|
+
constructor(where, info) {
|
|
7
|
+
this.where = {};
|
|
8
|
+
if (ValidationUtil_1.default.isNotNull(where) && where) {
|
|
9
|
+
this.addFiled(where, info);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//过滤空的值
|
|
13
|
+
filterNull(excludeField = []) {
|
|
14
|
+
let keys = Object.keys(this.where);
|
|
15
|
+
keys.forEach((key) => {
|
|
16
|
+
let value = Reflect.get(this.where, key);
|
|
17
|
+
if (!excludeField.includes(key) && !ValidationUtil_1.default.isNotMinSize(value, 1)) {
|
|
18
|
+
Reflect.deleteProperty(this.where, key);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
addFiled(where, info) {
|
|
24
|
+
let { field = [], excludeField = [] } = info || {};
|
|
25
|
+
let all = field.length == 0 && excludeField.length == 0;
|
|
26
|
+
for (let key in where) {
|
|
27
|
+
if (all || (field.length > 0 && field.includes(key)) || (field.length == 0 && !excludeField.includes(key))) {
|
|
28
|
+
let value = where[key];
|
|
29
|
+
//排除基础类型,数组和空对象
|
|
30
|
+
if (ValidationUtil_1.default.isNotNull(value) && ValidationUtil_1.default.isObject(value) && !ValidationUtil_1.default.isArray(value, "array")) {
|
|
31
|
+
let beforeObj = Reflect.get(this.where, key) || {};
|
|
32
|
+
Reflect.set(this.where, key, Object.assign({}, beforeObj, where[key]));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Reflect.set(this.where, key, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
toObject() {
|
|
42
|
+
return this.where;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = FilterCondition;
|
|
@@ -55,7 +55,13 @@ class ValidationUtil {
|
|
|
55
55
|
if (Array.isArray(param)) {
|
|
56
56
|
return param.length >= value;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
if (TypeUtil_1.default.isMap(param) || TypeUtil_1.default.isSet(param)) {
|
|
59
|
+
return param.size >= value;
|
|
60
|
+
}
|
|
61
|
+
if (ValidationUtil.isNull(param)) {
|
|
62
|
+
return 0 >= value;
|
|
63
|
+
}
|
|
64
|
+
let v = param.toString();
|
|
59
65
|
return v.length >= value;
|
|
60
66
|
}
|
|
61
67
|
static isNotMaxSize(param, value) {
|
package/target/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
3
|
+
exports.FilterCondition = exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
4
4
|
const ClassLoader_1 = require("./utils/ClassLoader");
|
|
5
5
|
exports.ClassLoader = ClassLoader_1.default;
|
|
6
6
|
const ClassUtils_1 = require("./utils/ClassUtils");
|
|
@@ -23,3 +23,5 @@ const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
|
23
23
|
exports.ValidationUtil = ValidationUtil_1.default;
|
|
24
24
|
const IPUtils_1 = require("./utils/IPUtils");
|
|
25
25
|
exports.IPUtils = IPUtils_1.default;
|
|
26
|
+
const FilterCondition_1 = require("./utils/FilterCondition");
|
|
27
|
+
exports.FilterCondition = FilterCondition_1.default;
|
package/utils.d.ts
CHANGED
|
@@ -180,3 +180,13 @@ export class MixTool {
|
|
|
180
180
|
export class IPUtils {
|
|
181
181
|
static isInnerIP(ip: string): boolean;
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
export class FilterCondition {
|
|
185
|
+
constructor(where?: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] });
|
|
186
|
+
|
|
187
|
+
filterNull(excludeField?: string[]): this;
|
|
188
|
+
|
|
189
|
+
addFiled(where: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }): this;
|
|
190
|
+
|
|
191
|
+
toObject(): { [key: string]: any };
|
|
192
|
+
}
|