s94-utils 0.0.1 → 0.0.2
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/README.md +43 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +376 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types/index.d.ts +175 -0
- package/package.json +25 -12
- package/src/index.js +0 -556
- package/src/index.mjs +0 -556
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
declare class Queue {
|
|
2
|
+
list: {
|
|
3
|
+
callback: () => any;
|
|
4
|
+
thisArg: any;
|
|
5
|
+
}[];
|
|
6
|
+
running: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
status: number;
|
|
9
|
+
/**
|
|
10
|
+
* 构建队列
|
|
11
|
+
* @param {number} [limit] 同时执行的槽位数量限制,默认为:1
|
|
12
|
+
* @param {boolean} [start] 构建好后,是否直接开始队列
|
|
13
|
+
* @returns {Queue}
|
|
14
|
+
*/
|
|
15
|
+
constructor(limit?: number, start?: boolean);
|
|
16
|
+
__run(): this;
|
|
17
|
+
/**
|
|
18
|
+
* 插入执行
|
|
19
|
+
* @param {function} callback 回调函数,如果返回 Promise ,会占用执行槽位直到 Promise 兑现
|
|
20
|
+
* @param {any} thisArg 执行时的this对象
|
|
21
|
+
* @returns {Queue}
|
|
22
|
+
*/
|
|
23
|
+
add(callback: () => any, thisArg: any): this;
|
|
24
|
+
start(): this;
|
|
25
|
+
stop(): void;
|
|
26
|
+
}
|
|
27
|
+
type TypeCacheEngine = {
|
|
28
|
+
getItem: (name: string) => string | Promise<string>;
|
|
29
|
+
setItem: (name: string, data: any) => Promise<any>;
|
|
30
|
+
removeItem?: (name: string) => Promise<any>;
|
|
31
|
+
clear?: () => any;
|
|
32
|
+
};
|
|
33
|
+
declare class Cache {
|
|
34
|
+
Storage: TypeCacheEngine;
|
|
35
|
+
/**
|
|
36
|
+
* 构建缓存器,传入缓存引擎对象,
|
|
37
|
+
* @param { {getItem:(name:string)=>string|Promise<string>, setItem:(name:string, data:any)=>Promise<any>, removeItem?:(name:string)=>Promise<any>, clear?:()=>any } } engine
|
|
38
|
+
*/
|
|
39
|
+
constructor(engine: TypeCacheEngine);
|
|
40
|
+
/**
|
|
41
|
+
* 获取缓存
|
|
42
|
+
* @param {any} name 缓存名
|
|
43
|
+
* @param {any} def 默认值
|
|
44
|
+
* @returns {any | Promise<any>} 由引擎的 getItem 确定是否返回 Promise
|
|
45
|
+
*/
|
|
46
|
+
get(name: any, def?: any): any;
|
|
47
|
+
/**
|
|
48
|
+
* 设定缓存
|
|
49
|
+
* @param {string} name 缓存名称
|
|
50
|
+
* @param {any} value 缓存值
|
|
51
|
+
* @param {number} timeout 过期时间(毫秒),默认或者小于0,表示永久
|
|
52
|
+
* @returns {Promise<any>}
|
|
53
|
+
*/
|
|
54
|
+
set(name: string, value: any, timeout?: number): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* 移除缓存
|
|
57
|
+
* @param {string} name
|
|
58
|
+
* @returns {Promise<any>}
|
|
59
|
+
*/
|
|
60
|
+
remove(name: string): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* 清理缓存,如果引擎存在 clear 方法,
|
|
63
|
+
* @returns {Promise<any>}
|
|
64
|
+
*/
|
|
65
|
+
clear(): Promise<any> | undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 返回参数的类型,例如 Object,Date
|
|
69
|
+
* @param {any} obj
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
declare function var_type(obj: any): string;
|
|
73
|
+
/**
|
|
74
|
+
* 转字符串
|
|
75
|
+
* @param {any} val
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
declare function to_string(val: any): any;
|
|
79
|
+
/**
|
|
80
|
+
* 去除字符串两边的空白
|
|
81
|
+
* @param {string} str
|
|
82
|
+
* @param {string} [mask] 额外需要去除的字符串
|
|
83
|
+
* @returns {string}
|
|
84
|
+
*/
|
|
85
|
+
declare function trim(str: string, mask?: string): string;
|
|
86
|
+
/**
|
|
87
|
+
* 计算相对路径
|
|
88
|
+
* @param {string} path
|
|
89
|
+
* @param {string} base
|
|
90
|
+
* @returns {*|string}
|
|
91
|
+
*/
|
|
92
|
+
declare function path(path: string, base: string): string;
|
|
93
|
+
type TypeEachCallback = (v: any, k: string, obj: Object, ks: string[]) => any;
|
|
94
|
+
type TypeEachOption = {
|
|
95
|
+
each: TypeEachCallback;
|
|
96
|
+
over?: () => any;
|
|
97
|
+
limit?: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* 遍历对象
|
|
101
|
+
* @param {Object} obj
|
|
102
|
+
* @param { TypeEachOption | (v:any, k:string, obj:Object)=>any } op 遍历回调函数 或者 包含遍历回调的配置
|
|
103
|
+
* @param {any} [thisArg] 回调函数的this对象
|
|
104
|
+
*/
|
|
105
|
+
declare function each(obj: Object, op: TypeEachOption | TypeEachCallback, thisArg: any): void;
|
|
106
|
+
/**
|
|
107
|
+
* 递归遍历
|
|
108
|
+
* @param {Object} obj 遍历的对象
|
|
109
|
+
* @param {string} childkey 递归遍历子对象的参数名,如果为空表示遍历整个子对象
|
|
110
|
+
* @param { (v:any, k:string, obj:Object, ks:string[])=>any } callback 遍历回调函数
|
|
111
|
+
* @param {boolean} [is_layer] 是否按层结构(0,1,00,01,10...)递归,false表示按树结构(0,00,01,1,10...)
|
|
112
|
+
* @param {any} [thisArg] 遍历回调的this,默认为子对象
|
|
113
|
+
*/
|
|
114
|
+
declare function eachloop(obj: Object, childkey: string, callback: TypeEachCallback, is_layer?: boolean, thisArg?: any): void;
|
|
115
|
+
/**
|
|
116
|
+
* url查询参数解码
|
|
117
|
+
* @param {string} str url查询参数字符串,例如:a=1&b[]=2&b[]=3
|
|
118
|
+
* @returns {{[key:string]: string|Object}}
|
|
119
|
+
*/
|
|
120
|
+
declare function param_decode(str: string): {};
|
|
121
|
+
/**
|
|
122
|
+
* url查询参数编码
|
|
123
|
+
* @param {Object} obj 数据对象
|
|
124
|
+
* @returns {string}
|
|
125
|
+
*/
|
|
126
|
+
declare function param_encode(obj: any): string;
|
|
127
|
+
/**
|
|
128
|
+
* 数据签名
|
|
129
|
+
* @param {any} data 数据
|
|
130
|
+
* @param {number} len 长度, 默认64
|
|
131
|
+
* @returns {string}
|
|
132
|
+
*/
|
|
133
|
+
declare function encode(data: any, len?: number): string;
|
|
134
|
+
/**
|
|
135
|
+
* 对象的指定值获取 或者 设定
|
|
136
|
+
* @param {any} data 数据源
|
|
137
|
+
* @param {string|{[key:string]: any}} key_data 获取的键,或者设定数据的键值对
|
|
138
|
+
* @param {any} def 值不存在的默认值
|
|
139
|
+
* @returns {*}
|
|
140
|
+
*/
|
|
141
|
+
declare function map(data: any, key_data: string | {
|
|
142
|
+
[key: string]: any;
|
|
143
|
+
}, def: any): any;
|
|
144
|
+
type TypeDateReturn = {
|
|
145
|
+
timestamp: number;
|
|
146
|
+
y: number;
|
|
147
|
+
m: number;
|
|
148
|
+
d: number;
|
|
149
|
+
h: number;
|
|
150
|
+
i: number;
|
|
151
|
+
s: number;
|
|
152
|
+
w: number;
|
|
153
|
+
string: string;
|
|
154
|
+
zone: number;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* 日期处理
|
|
158
|
+
* @param {string|number|Date} date 日期,可以是字符串、时间戳(毫秒)
|
|
159
|
+
* @param {string} fmt 日期字符串格式,如果data为字符串,然后fmt为空,那么会推定日期为 年月日时分秒、日月年时分秒 中的一种
|
|
160
|
+
* @param {number} [zone] 时区,东正,西负。-12~12
|
|
161
|
+
* @returns {{timestamp: number, y: number, m: number, d: number, h: number, i: number, s: number, w: number, string: string, zone: number}}
|
|
162
|
+
*/
|
|
163
|
+
declare function date(date: string | number | Date, fmt?: string, zone?: number): TypeDateReturn;
|
|
164
|
+
/**
|
|
165
|
+
* 事件管理,on,off,emit
|
|
166
|
+
*/
|
|
167
|
+
declare const event_manage: {
|
|
168
|
+
__event_list: {
|
|
169
|
+
[k: string]: ((data?: any) => any)[];
|
|
170
|
+
};
|
|
171
|
+
on(event_name: string, callback: (data?: any) => any, first?: any): void;
|
|
172
|
+
off(event_name: string, callback: (data?: any) => any): void;
|
|
173
|
+
emit(event_name: string, data: any, thisArg?: any): void;
|
|
174
|
+
};
|
|
175
|
+
export { Queue, Cache, var_type, to_string, trim, path, each, eachloop, param_decode, param_encode, encode, map, date, event_manage, };
|
package/package.json
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s94-utils",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "s94本人常用的工具方法包",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
7
|
-
"module": "
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
14
17
|
},
|
|
15
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
16
22
|
"sideEffects": false,
|
|
17
|
-
|
|
18
23
|
"scripts": {
|
|
19
|
-
"
|
|
24
|
+
"dev": "vite build --watch",
|
|
25
|
+
"build": "tsc && vite build",
|
|
26
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
27
|
},
|
|
21
28
|
"author": "",
|
|
22
|
-
"license": "ISC"
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.0.10",
|
|
32
|
+
"typescript": "^5.9.3",
|
|
33
|
+
"vite": "^7.3.1",
|
|
34
|
+
"vite-plugin-dts": "^4.5.4"
|
|
35
|
+
}
|
|
23
36
|
}
|