create-enum-es 1.0.0 → 1.0.3
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.
|
@@ -1,4 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
type IEMap = Readonly<Record<any, readonly [any, any]>>;
|
|
2
|
+
type TEUnion<T extends IEMap> = keyof T;
|
|
3
|
+
type TEValue<T extends IEMap> = T[TEUnion<T>][0];
|
|
4
|
+
type IVMap<U extends string | number | symbol, T extends IEMap> = {
|
|
5
|
+
[K in U]: T[K] extends readonly [infer V, infer F] ? V : any;
|
|
6
|
+
};
|
|
7
|
+
type IEnum<T extends IEMap, Enum> = {
|
|
8
|
+
readonly [K in keyof T]: T[K] extends readonly [infer V, infer F] ? V : any;
|
|
9
|
+
} & Enum;
|
|
10
|
+
interface IArguConf {
|
|
11
|
+
arguType?: "key" | "value";
|
|
12
|
+
}
|
|
13
|
+
interface IFeildConf {
|
|
14
|
+
labelKey?: string;
|
|
15
|
+
valueKey?: string;
|
|
16
|
+
}
|
|
17
|
+
type IConf = IArguConf & IFeildConf;
|
|
18
|
+
type IArgLastConfig<U, T extends IEMap> = U extends [...infer Rest, infer Last] ? Last extends IConf ? (Last["labelKey"] extends string ? {
|
|
19
|
+
[K in Last["labelKey"]]: TEValue<T>;
|
|
20
|
+
} : {
|
|
21
|
+
label: string;
|
|
22
|
+
}) & (Last["valueKey"] extends string ? {
|
|
23
|
+
[K in Last["valueKey"]]: any;
|
|
24
|
+
} : {
|
|
25
|
+
value: TEValue<T>;
|
|
26
|
+
}) : {
|
|
27
|
+
label: string;
|
|
28
|
+
value: TEValue<T>;
|
|
29
|
+
} : never;
|
|
30
|
+
|
|
2
31
|
/**
|
|
3
32
|
* 枚举类
|
|
4
33
|
* @param {Object} enumMap 枚举对象
|
|
@@ -94,4 +123,5 @@ declare class Enum<T extends IEMap> {
|
|
|
94
123
|
* @returns
|
|
95
124
|
*/
|
|
96
125
|
declare const createEnum: <T extends IEMap>(enumMap: T) => IEnum<T, Enum<T>>;
|
|
126
|
+
|
|
97
127
|
export { createEnum };
|
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-enum-es",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "处理前端枚举的工具方法,支持ts类型检测",
|
|
5
5
|
"main": "dist/create-enum.es.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"homepage": "https://github.com/wangxiaoqi0123/create-enum-es",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/wangxiaoqi0123/create-enum-es"
|
|
12
|
+
},
|
|
6
13
|
"private": false,
|
|
7
14
|
"files": [
|
|
8
|
-
"dist
|
|
15
|
+
"dist/**.js",
|
|
16
|
+
"dist/index.d.ts",
|
|
9
17
|
"package.json",
|
|
10
18
|
"README.md"
|
|
11
19
|
],
|
|
@@ -25,6 +33,7 @@
|
|
|
25
33
|
"devDependencies": {
|
|
26
34
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
27
35
|
"rollup": "^4.18.1",
|
|
36
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
28
37
|
"typescript": "^5.5.3"
|
|
29
38
|
}
|
|
30
|
-
}
|
|
39
|
+
}
|
package/dist/types/typeing.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export type ITypeData = "undefined" | "null" | "boolean" | "number" | "string" | "symbol" | "function" | "array" | "object" | "date" | "regexp" | "error" | "map" | "set" | "weakmap" | "weakset" | "arraybuffer" | "dataview" | "promise" | "int8array" | "uint8array" | "uint8clampedarray" | "int16array" | "uint16array" | "int32array" | "uint32array" | "float32array" | "float64array" | "bigint64array" | "biguint64array";
|
|
2
|
-
export type IEMap = Readonly<Record<any, readonly [any, any]>>;
|
|
3
|
-
export type TEUnion<T extends IEMap> = keyof T;
|
|
4
|
-
export type TEValue<T extends IEMap> = T[TEUnion<T>][0];
|
|
5
|
-
export type IVMap<U extends string | number | symbol, T extends IEMap> = {
|
|
6
|
-
[K in U]: T[K] extends readonly [infer V, infer F] ? V : any;
|
|
7
|
-
};
|
|
8
|
-
export type IEnum<T extends IEMap, Enum> = {
|
|
9
|
-
readonly [K in keyof T]: T[K] extends readonly [infer V, infer F] ? V : any;
|
|
10
|
-
} & Enum;
|
|
11
|
-
export interface IArguConf {
|
|
12
|
-
arguType?: "key" | "value";
|
|
13
|
-
}
|
|
14
|
-
export interface IFeildConf {
|
|
15
|
-
labelKey?: string;
|
|
16
|
-
valueKey?: string;
|
|
17
|
-
}
|
|
18
|
-
export type IConf = IArguConf & IFeildConf;
|
|
19
|
-
export type IArgLastConfig<U, T extends IEMap> = U extends [...infer Rest, infer Last] ? Last extends IConf ? (Last["labelKey"] extends string ? {
|
|
20
|
-
[K in Last["labelKey"]]: TEValue<T>;
|
|
21
|
-
} : {
|
|
22
|
-
label: string;
|
|
23
|
-
}) & (Last["valueKey"] extends string ? {
|
|
24
|
-
[K in Last["valueKey"]]: any;
|
|
25
|
-
} : {
|
|
26
|
-
value: TEValue<T>;
|
|
27
|
-
}) : {
|
|
28
|
-
label: string;
|
|
29
|
-
value: TEValue<T>;
|
|
30
|
-
} : never;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ITypeData } from "../typeing";
|
|
2
|
-
/**
|
|
3
|
-
* 数据类型
|
|
4
|
-
* @param {*} data
|
|
5
|
-
* @param {String} type
|
|
6
|
-
* @returns {Boolean}
|
|
7
|
-
*/
|
|
8
|
-
export declare function isType<T>(data: T, type: ITypeData): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* 数据是否为空
|
|
11
|
-
* @param {*} data
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export declare function isEmpty<T>(data: T): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* 深度拷贝
|
|
17
|
-
* @param {Object|Array} obj
|
|
18
|
-
* @return {Object|Array}
|
|
19
|
-
*/
|
|
20
|
-
export declare function deepClone(obj: any): {};
|