@wxhccc/es-util 1.5.2 → 2.0.0

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 CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@wxhccc/es-util",
3
- "version": "1.5.2",
3
+ "version": "2.0.0",
4
4
  "description": "A library that contains some useful methods",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "unpkg": "dist/index.min.js",
8
- "types": "types/index.d.ts",
8
+ "types": "dist/index.d.ts",
9
9
  "scripts": {
10
10
  "start": "npm run dev",
11
11
  "test": "jest",
12
12
  "dev": "rollup -w -c --environment NODE_ENV:development",
13
- "build": "rollup -c"
13
+ "clean": "rimraf dist/**",
14
+ "build": "yarn clean && rollup -c"
14
15
  },
15
16
  "keywords": [
16
17
  "array-tree-switch",
@@ -21,7 +22,8 @@
21
22
  "idCard",
22
23
  "validate",
23
24
  "mapToObject",
24
- "string-switch"
25
+ "string-switch",
26
+ "mask data"
25
27
  ],
26
28
  "author": "wxhccc",
27
29
  "license": "MIT",
@@ -41,27 +43,26 @@
41
43
  "@rollup/plugin-commonjs": "^18.0.0",
42
44
  "@rollup/plugin-node-resolve": "^11.2.1",
43
45
  "@types/jest": "^26.0.23",
44
- "@typescript-eslint/eslint-plugin": "^2.19.0",
45
- "@typescript-eslint/parser": "^2.19.0",
46
- "@vue/test-utils": "^2.0.0-rc.6",
46
+ "@types/lodash": "^4.14.182",
47
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
48
+ "@typescript-eslint/parser": "^5.30.7",
47
49
  "babel-eslint": "^8.2.6",
48
- "enzyme": "^3.11.0",
49
- "enzyme-adapter-react-16": "^1.15.6",
50
- "eslint": "^4.19.1",
51
- "jest": "^26.6.3",
52
- "lodash": "^4.17.15",
53
- "react": "^17.0.2",
54
- "react-dom": "^17.0.2",
55
- "rollup": "^2.45.1",
50
+ "eslint": "^8.20.0",
51
+ "eslint-config-prettier": "^8.5.0",
52
+ "eslint-plugin-prettier": "^4.2.1",
53
+ "jest": "^28.1.3",
54
+ "jest-environment-jsdom": "^28.1.3",
55
+ "prettier": "^2.7.1",
56
+ "rimraf": "^3.0.2",
57
+ "rollup": "^2.77.0",
56
58
  "rollup-plugin-terser": "^7.0.2",
57
- "rollup-plugin-typescript2": "^0.30.0",
59
+ "rollup-plugin-typescript2": "^0.32.1",
60
+ "ts-jest": "^28.0.7",
58
61
  "tslib": "^1.10.0",
59
- "typescript": "^4.2.4",
60
- "vue": "^3.0.11"
62
+ "typescript": "^4.7.4"
61
63
  },
62
64
  "files": [
63
- "dist",
64
- "types"
65
+ "dist"
65
66
  ],
66
67
  "dependencies": {}
67
68
  }
@@ -1,49 +0,0 @@
1
- export interface Node {
2
- [key: string]: any;
3
- }
4
- export interface TreeNode {
5
- [key: string]: any;
6
- }
7
- interface Options {
8
- primaryKey?: string;
9
- parentKey?: string;
10
- childrenKey?: string;
11
- }
12
- interface TreeOptions extends Options {
13
- createRoot?: boolean | ((nodes: TreeNode[]) => any);
14
- parentRefKey?: boolean | string;
15
- }
16
- interface NodeOptions extends Options {
17
- hasParentKey?: boolean;
18
- returnObject?: boolean;
19
- }
20
- declare type Tree = TreeNode[] | {
21
- [children: string]: TreeNode[];
22
- };
23
- /**
24
- * translate array to tree
25
- * @param {Array} array the node array need to be translate
26
- * @param {Object} options the options
27
- * @param {string} primaryKey the primary key of node
28
- * @param {string} parentKey the parent's key of node
29
- * @param {string} childrenKey the child's key of node
30
- * @param {boolean | Function} createNode whether create root node, or function which can return root node
31
- * @param {boolean | string} parentRefKey parent reference key of node
32
- */
33
- export declare function array2tree(array: Node[], options?: TreeOptions): Tree;
34
- declare type Nodes = Node[];
35
- declare type NodeMap = {
36
- [id: string]: Node;
37
- };
38
- /**
39
- * translate tree to array
40
- * @param {Array/Object} tree the node tree need to be translate
41
- * @param {Object} options the options
42
- * @param {string} primaryKey the primary key of tree node
43
- * @param {string} parentKey the parent's key of tree node
44
- * @param {string} childrenKey the child's key of tree node
45
- * @param {boolean} hasParentKey whether create parent id in node
46
- * @param {boolean} returnObject whether return object or array
47
- */
48
- export declare function tree2array(tree: Tree, options?: NodeOptions): NodeMap | Nodes;
49
- export {};
package/types/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './array-tree-switch';
2
- export * from './validate';
3
- export * from './object-array';
4
- export * from './value-string-switch';
5
- export * from './promise';
6
- export * from './optional';
@@ -1,33 +0,0 @@
1
- declare type Obj = {
2
- [key: string]: any;
3
- };
4
- /**
5
- * translate object array to key-value map object
6
- *
7
- * @param {Object[]} objectArray
8
- * @param {string} keyProp
9
- * @param {string} valueProp
10
- */
11
- interface PropHandler {
12
- (item: any, index: number): string;
13
- }
14
- export declare function mapToObject(objectArray: any[], keyProp?: string | PropHandler, valueProp?: string | PropHandler): Obj;
15
- /**
16
- * checkout values form object as an array
17
- *
18
- * @param {Object} object
19
- * @param {string[] | Object} keys
20
- * @param {string} valueProp
21
- */
22
- declare type MergeFn = <T>(...args: T[]) => T;
23
- export declare function checkoutBy(object: Obj, keys?: string[] | Obj, mergeFn?: MergeFn): any[];
24
- /**
25
- * pick and rename object values
26
- *
27
- * @param {Object} object
28
- * @param {Object} keysMap
29
- */
30
- export declare function pickRenameKeys(object: Obj, keysMap: {
31
- [key: string]: string;
32
- }): Obj | undefined;
33
- export {};
@@ -1,50 +0,0 @@
1
- declare type AnyObject = Record<string | number, any>;
2
- /**
3
- * JSON.parse string safely
4
- * @param json string
5
- * @param faileValue any
6
- * @returns any
7
- */
8
- export declare function safeJsonParse<T = AnyObject>(json?: string): T | undefined;
9
- export declare function safeJsonParse<T = AnyObject>(json: string | undefined, faileValue: T): T;
10
- /**
11
- * check value whether empty text
12
- * 判断给定变量是否是字面量空值 */
13
- export declare const isNullable: (value: unknown) => value is "" | null | undefined;
14
- /**
15
- * 过滤对象中属性为空('' | undefined | null)的字段
16
- * @param obj 给定对象
17
- * @param deep 是否需要递归过滤
18
- * @returns 过滤后的对象
19
- */
20
- export declare const filterNullable: <T extends AnyObject>(obj: T, deep?: boolean | undefined) => T;
21
- /**
22
- * 将对象中属性值为null的转换为undefined
23
- * @param data 对象数据
24
- * @returns
25
- */
26
- export declare const switchNullToUndefined: (data: any) => any;
27
- /**
28
- * 参数转换规则的配置对象
29
- * 值可以是时间范围转换所需的开始,结束时间字段的名称,或者需要进行拼接的数组
30
- */
31
- export declare type ParamsSwitchMaps<DK extends string = string, RK extends string = string> = Record<DK, [
32
- RK,
33
- RK
34
- ] | [RK, RK, string] | 'join' | 'pop'>;
35
- export declare type DateFormat = (date: any, format?: string) => string;
36
- /**
37
- * 将搜素条件里的数组字段转换为其他格式,通常用于搜索表单的字段转换
38
- * @param formData 传入参数
39
- * @param maps 转换的映射关系,eg:{ date: ['startTime', 'endTime'] }
40
- * @param options 额外的配置参数
41
- */
42
- export declare const formParamsSwitch: <R extends AnyObject = AnyObject, T extends AnyObject = AnyObject>(formData: T, maps: Partial<ParamsSwitchMaps<Exclude<keyof T, number | symbol>, Exclude<keyof R, number | symbol>>>, options?: {
43
- /** 是否需要过滤空数据 */
44
- filterNullable?: boolean | undefined;
45
- /** 时间格式换函数 */
46
- dateFormat?: DateFormat | undefined;
47
- } | undefined) => R;
48
- /** 创建一个绑定了默认时间格式转换函数的formParamsSwitch函数 */
49
- export declare const formParamsSwitchCreator: (dateFormat: DateFormat) => typeof formParamsSwitch;
50
- export {};
@@ -1,44 +0,0 @@
1
- export declare const objType: (val: unknown) => string;
2
- /**
3
- * wrap promise and handle reject or err by return an array like [error, undefined]
4
- * @param promise promise
5
- * @returns Promise<[K, undefined] | [null, T]>
6
- */
7
- export declare function awaitWrapper<T, K = Error>(promise: Promise<T>): Promise<[null, T] | [K, undefined]>;
8
- export declare type SyncRefHandle = [Record<string, boolean>, string];
9
- export declare type LockSwitchHook = (val: boolean) => unknown;
10
- export interface PromiseWithLock<T> extends Promise<T> {
11
- readonly __lockValue: boolean;
12
- unlock: () => void;
13
- }
14
- export declare type ContextType = 'react' | 'vue' | 'unknown';
15
- /**
16
- * wrap promise with lock, support reactive environment like react or vue
17
- * @param promise promise
18
- * @param wrap whether use awaitWrap to wrap result
19
- */
20
- export interface WpOptions {
21
- wrap?: boolean;
22
- lock?: string | LockSwitchHook | SyncRefHandle;
23
- syncRefHandle?: SyncRefHandle;
24
- manualUnlock?: boolean;
25
- }
26
- declare type WpReturn<T> = PromiseWithLock<T | undefined>;
27
- declare type WpArrReturn<T> = PromiseWithLock<[null, T] | [Error, undefined]>;
28
- declare type WpPromise<T> = Promise<T> | (() => Promise<T>);
29
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, wrap?: false): WpReturn<T>;
30
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, wrap: true): WpArrReturn<T>;
31
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, options?: WpOptions & {
32
- wrap?: false;
33
- }): WpReturn<T>;
34
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, options?: WpOptions & {
35
- wrap: true;
36
- }): WpArrReturn<T>;
37
- declare type WP = typeof wrapPromise & {
38
- _checkLockKey: (key: string) => boolean;
39
- };
40
- export declare const wp: WP;
41
- export declare const wpVuePlugin: {
42
- install(appOrVue: any, key?: string): void;
43
- };
44
- export {};
@@ -1,2 +0,0 @@
1
- export declare function ChinaIdCardValid(idNo: string): boolean;
2
- export declare function formulaValidate(string: string, variables?: string[]): boolean;
@@ -1,12 +0,0 @@
1
- interface Options {
2
- standard?: 'metric' | 'iec' | 'jedec';
3
- unitLvl?: string;
4
- precision?: number;
5
- detail?: boolean;
6
- }
7
- export declare function byteStringify(byteNum: number | string, options?: Options): string | {
8
- value: string | number;
9
- unit: string;
10
- } | undefined;
11
- export declare function byteParse(byteStr: string, options?: {}): void;
12
- export {};
@@ -1 +0,0 @@
1
- export * from './byte-string';