@daysnap/utils 0.0.59 → 0.0.61

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 过滤对象的 undefined null '' 属性,返回一个新对象
3
+ * @param obj 需要过滤的对象
4
+ * @param expand 如果是传的是布尔类型 true, 则还会过滤空数组、空对象的情况
5
+ */
6
+ export declare function filterEmptyValue(obj: Record<string, any>, expand?: boolean | ((key: string, value: any) => boolean)): Record<string, any>;
@@ -0,0 +1,29 @@
1
+ import { isEmpty } from './isEmpty';
2
+ import { isEmptyArray } from './isEmptyArray';
3
+ import { isEmptyObject } from './isEmptyObject';
4
+ import { isFunction } from './isFunction';
5
+ /**
6
+ * 过滤对象的 undefined null '' 属性,返回一个新对象
7
+ * @param obj 需要过滤的对象
8
+ * @param expand 如果是传的是布尔类型 true, 则还会过滤空数组、空对象的情况
9
+ */
10
+ export function filterEmptyValue(obj, expand = false) {
11
+ return Object.entries(obj).reduce((res, [key, value]) => {
12
+ if (isFunction(expand) && expand(key, value)) {
13
+ res[key] = value;
14
+ }
15
+ else {
16
+ if (!isEmpty(value)) {
17
+ if (expand) {
18
+ if (!isEmptyArray(value) && !isEmptyObject(value)) {
19
+ res[key] = value;
20
+ }
21
+ }
22
+ else {
23
+ res[key] = value;
24
+ }
25
+ }
26
+ }
27
+ return res;
28
+ }, {});
29
+ }
package/es/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './exitFullscreen';
16
16
  export * from './filterBankCardNo';
17
17
  export * from './filterCRLF';
18
18
  export * from './filterEmoji';
19
+ export * from './filterEmptyValue';
19
20
  export * from './filterIdCard';
20
21
  export * from './filterName';
21
22
  export * from './filterPhone';
@@ -43,6 +44,7 @@ export * from './isChinese';
43
44
  export * from './isDate';
44
45
  export * from './isEmail';
45
46
  export * from './isEmpty';
47
+ export * from './isEmptyArray';
46
48
  export * from './isEmptyObject';
47
49
  export * from './isError';
48
50
  export * from './isFunction';
package/es/index.js CHANGED
@@ -17,6 +17,7 @@ export * from './exitFullscreen';
17
17
  export * from './filterBankCardNo';
18
18
  export * from './filterCRLF';
19
19
  export * from './filterEmoji';
20
+ export * from './filterEmptyValue';
20
21
  export * from './filterIdCard';
21
22
  export * from './filterName';
22
23
  export * from './filterPhone';
@@ -44,6 +45,7 @@ export * from './isChinese';
44
45
  export * from './isDate';
45
46
  export * from './isEmail';
46
47
  export * from './isEmpty';
48
+ export * from './isEmptyArray';
47
49
  export * from './isEmptyObject';
48
50
  export * from './isError';
49
51
  export * from './isFunction';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否是空数组
3
+ */
4
+ export declare function isEmptyArray(val: unknown): boolean;
@@ -0,0 +1,7 @@
1
+ import { isArray } from './isArray';
2
+ /**
3
+ * 判断是否是空数组
4
+ */
5
+ export function isEmptyArray(val) {
6
+ return isArray(val) && val.length === 0;
7
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 过滤对象的 undefined null '' 属性,返回一个新对象
3
+ * @param obj 需要过滤的对象
4
+ * @param expand 如果是传的是布尔类型 true, 则还会过滤空数组、空对象的情况
5
+ */
6
+ export declare function filterEmptyValue(obj: Record<string, any>, expand?: boolean | ((key: string, value: any) => boolean)): Record<string, any>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterEmptyValue = void 0;
4
+ const isEmpty_1 = require("./isEmpty");
5
+ const isEmptyArray_1 = require("./isEmptyArray");
6
+ const isEmptyObject_1 = require("./isEmptyObject");
7
+ const isFunction_1 = require("./isFunction");
8
+ /**
9
+ * 过滤对象的 undefined null '' 属性,返回一个新对象
10
+ * @param obj 需要过滤的对象
11
+ * @param expand 如果是传的是布尔类型 true, 则还会过滤空数组、空对象的情况
12
+ */
13
+ function filterEmptyValue(obj, expand = false) {
14
+ return Object.entries(obj).reduce((res, [key, value]) => {
15
+ if ((0, isFunction_1.isFunction)(expand) && expand(key, value)) {
16
+ res[key] = value;
17
+ }
18
+ else {
19
+ if (!(0, isEmpty_1.isEmpty)(value)) {
20
+ if (expand) {
21
+ if (!(0, isEmptyArray_1.isEmptyArray)(value) && !(0, isEmptyObject_1.isEmptyObject)(value)) {
22
+ res[key] = value;
23
+ }
24
+ }
25
+ else {
26
+ res[key] = value;
27
+ }
28
+ }
29
+ }
30
+ return res;
31
+ }, {});
32
+ }
33
+ exports.filterEmptyValue = filterEmptyValue;
package/lib/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './exitFullscreen';
16
16
  export * from './filterBankCardNo';
17
17
  export * from './filterCRLF';
18
18
  export * from './filterEmoji';
19
+ export * from './filterEmptyValue';
19
20
  export * from './filterIdCard';
20
21
  export * from './filterName';
21
22
  export * from './filterPhone';
@@ -43,6 +44,7 @@ export * from './isChinese';
43
44
  export * from './isDate';
44
45
  export * from './isEmail';
45
46
  export * from './isEmpty';
47
+ export * from './isEmptyArray';
46
48
  export * from './isEmptyObject';
47
49
  export * from './isError';
48
50
  export * from './isFunction';
package/lib/index.js CHANGED
@@ -33,6 +33,7 @@ __exportStar(require("./exitFullscreen"), exports);
33
33
  __exportStar(require("./filterBankCardNo"), exports);
34
34
  __exportStar(require("./filterCRLF"), exports);
35
35
  __exportStar(require("./filterEmoji"), exports);
36
+ __exportStar(require("./filterEmptyValue"), exports);
36
37
  __exportStar(require("./filterIdCard"), exports);
37
38
  __exportStar(require("./filterName"), exports);
38
39
  __exportStar(require("./filterPhone"), exports);
@@ -60,6 +61,7 @@ __exportStar(require("./isChinese"), exports);
60
61
  __exportStar(require("./isDate"), exports);
61
62
  __exportStar(require("./isEmail"), exports);
62
63
  __exportStar(require("./isEmpty"), exports);
64
+ __exportStar(require("./isEmptyArray"), exports);
63
65
  __exportStar(require("./isEmptyObject"), exports);
64
66
  __exportStar(require("./isError"), exports);
65
67
  __exportStar(require("./isFunction"), exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否是空数组
3
+ */
4
+ export declare function isEmptyArray(val: unknown): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmptyArray = void 0;
4
+ const isArray_1 = require("./isArray");
5
+ /**
6
+ * 判断是否是空数组
7
+ */
8
+ function isEmptyArray(val) {
9
+ return (0, isArray_1.isArray)(val) && val.length === 0;
10
+ }
11
+ exports.isEmptyArray = isEmptyArray;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",