@maiyunnet/kebab 2.0.3 → 2.0.5

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.
Files changed (89) hide show
  1. package/index.d.ts +14 -0
  2. package/index.js +1 -1
  3. package/lib/buffer.d.ts +25 -0
  4. package/lib/captcha.d.ts +12 -0
  5. package/lib/consistent.d.ts +20 -0
  6. package/lib/core.d.ts +85 -0
  7. package/lib/crypto.d.ts +47 -0
  8. package/lib/db.d.ts +88 -0
  9. package/lib/dns.d.ts +75 -0
  10. package/lib/fs.d.ts +49 -0
  11. package/lib/jwt.d.ts +30 -0
  12. package/lib/kv.d.ts +111 -0
  13. package/lib/lan.d.ts +10 -0
  14. package/lib/net/formdata.d.ts +23 -0
  15. package/lib/net/request.d.ts +23 -0
  16. package/lib/net/response.d.ts +14 -0
  17. package/lib/net.d.ts +65 -0
  18. package/lib/s3.d.ts +35 -0
  19. package/lib/scan.d.ts +31 -0
  20. package/lib/session.d.ts +22 -0
  21. package/lib/sql.d.ts +57 -0
  22. package/lib/ssh/sftp.d.ts +40 -0
  23. package/lib/ssh/shell.d.ts +13 -0
  24. package/lib/ssh.d.ts +24 -0
  25. package/lib/text.d.ts +40 -0
  26. package/lib/time.d.ts +22 -0
  27. package/lib/ws.d.ts +87 -0
  28. package/lib/zip.d.ts +40 -0
  29. package/lib/zlib.d.ts +25 -0
  30. package/main.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/sys/child.d.ts +1 -0
  33. package/sys/cmd.d.ts +1 -0
  34. package/sys/ctr.d.ts +96 -0
  35. package/sys/master.d.ts +1 -0
  36. package/sys/mod.d.ts +205 -0
  37. package/sys/route.d.ts +31 -0
  38. package/tsconfig.json +1 -1
  39. package/www/example/ctr/main.d.ts +4 -0
  40. package/www/example/ctr/middle.d.ts +6 -0
  41. package/www/example/ctr/test.d.ts +94 -0
  42. package/www/example/mod/test.d.ts +20 -0
  43. package/www/example/mod/testdata.d.ts +9 -0
  44. package/www/example/ws/mproxy.d.ts +4 -0
  45. package/www/example/ws/rproxy.d.ts +4 -0
  46. package/www/example/ws/test.d.ts +7 -0
  47. package/index.ts +0 -33
  48. package/lib/buffer.ts +0 -152
  49. package/lib/captcha.ts +0 -63
  50. package/lib/consistent.ts +0 -219
  51. package/lib/core.ts +0 -880
  52. package/lib/crypto.ts +0 -384
  53. package/lib/db.ts +0 -719
  54. package/lib/dns.ts +0 -405
  55. package/lib/fs.ts +0 -527
  56. package/lib/jwt.ts +0 -276
  57. package/lib/kv.ts +0 -1489
  58. package/lib/lan.ts +0 -87
  59. package/lib/net/formdata.ts +0 -166
  60. package/lib/net/request.ts +0 -150
  61. package/lib/net/response.ts +0 -59
  62. package/lib/net.ts +0 -662
  63. package/lib/s3.ts +0 -235
  64. package/lib/scan.ts +0 -364
  65. package/lib/session.ts +0 -230
  66. package/lib/sql.ts +0 -1149
  67. package/lib/ssh/sftp.ts +0 -508
  68. package/lib/ssh/shell.ts +0 -123
  69. package/lib/ssh.ts +0 -191
  70. package/lib/text.ts +0 -626
  71. package/lib/time.ts +0 -254
  72. package/lib/ws.ts +0 -523
  73. package/lib/zip.ts +0 -447
  74. package/lib/zlib.ts +0 -350
  75. package/main.ts +0 -27
  76. package/sys/child.ts +0 -678
  77. package/sys/cmd.ts +0 -225
  78. package/sys/ctr.ts +0 -904
  79. package/sys/master.ts +0 -355
  80. package/sys/mod.ts +0 -1871
  81. package/sys/route.ts +0 -1113
  82. package/www/example/ctr/main.ts +0 -9
  83. package/www/example/ctr/middle.ts +0 -26
  84. package/www/example/ctr/test.ts +0 -3218
  85. package/www/example/mod/test.ts +0 -47
  86. package/www/example/mod/testdata.ts +0 -30
  87. package/www/example/ws/mproxy.ts +0 -16
  88. package/www/example/ws/rproxy.ts +0 -14
  89. package/www/example/ws/test.ts +0 -36
package/lib/time.ts DELETED
@@ -1,254 +0,0 @@
1
- /**
2
- * Project: Kebab, User: JianSuoQiYue
3
- * Date: 2019-6-6 12:04:15
4
- * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
5
- */
6
- import * as sCtr from '~/sys/ctr';
7
-
8
- export interface IOptions {
9
- /** --- 时区 --- */
10
- 'zone'?: number;
11
- /** --- 字符串、时间戳(秒或毫秒) --- */
12
- 'data'?: string | number;
13
- }
14
-
15
- /** --- 一小时的秒数 --- */
16
- export const HOUR = 3600;
17
- /** --- 一天的秒数 --- */
18
- export const DAY = 86400;
19
- /** --- 一年(365 天) */
20
- export const YEAR = 31536000;
21
-
22
- /** --- 星期名 --- */
23
- const dayNames: string[][] = [
24
- ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
25
- ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
26
- ];
27
- /** --- 月份名 --- */
28
- const monthNames: string[][] = [
29
- ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
30
- ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
31
- ];
32
-
33
- export class Time {
34
-
35
- /** --- 当前 date --- */
36
- private readonly _date!: Date;
37
-
38
- /** --- 当前时区 --- */
39
- private _zone: number = 0;
40
-
41
- /**
42
- * --- 构造函数 ---
43
- * @param opt
44
- */
45
- public constructor(ctr: sCtr.Ctr, opt: IOptions) {
46
- this._zone = opt.zone ?? ctr.getPrototype('_config').set.timezone ?? 0;
47
- if (opt.data) {
48
- if (typeof opt.data === 'number') {
49
- let dataStr: string = opt.data.toString();
50
- if (dataStr.length < 13) {
51
- dataStr += '000';
52
- opt.data = Number(dataStr);
53
- }
54
- this._date = new Date(opt.data);
55
- }
56
- else if (typeof opt.data === 'string') {
57
- this._date = new Date(opt.data);
58
- /** --- 与当前设定时区的差小时 --- */
59
- const offset = this._date.getTimezoneOffset() / 60 + this._zone;
60
- if (offset !== 0) {
61
- this._date.setUTCHours(this._date.getUTCHours() - offset);
62
- }
63
- }
64
- }
65
- else {
66
- this._date = new Date();
67
- }
68
- }
69
-
70
- /**
71
- * --- 设置时区 ---
72
- * @param zone 北京时间如 8
73
- */
74
- public setZone(zone: number): void {
75
- this._zone = zone;
76
- }
77
-
78
- /**
79
- * --- 获取时区 ---
80
- */
81
- public getZone(): number {
82
- return this._zone;
83
- }
84
-
85
- /**
86
- * --- 获取 UTC 字符串 ---
87
- */
88
- public toUTCString(): string {
89
- return this._date.toUTCString();
90
- }
91
-
92
- /**
93
- * --- 获取格式化的字符串 ---
94
- * @param f 格式化字符串
95
- * @param zone 时区小时,如 8
96
- */
97
- public format(f: string, zone?: number): string {
98
- return format(zone ?? 0, f, this._date);
99
- }
100
-
101
- /**
102
- * --- 获取秒级时间戳 ---
103
- */
104
- public stamp(): number {
105
- return stamp(this._date);
106
- }
107
- }
108
-
109
- /**
110
- * --- 创建获取一个时间对象 ---
111
- * @param opt
112
- */
113
- export function get(ctr: sCtr.Ctr, opt: IOptions = {}): Time {
114
- return new Time(ctr, opt);
115
- }
116
-
117
- /**
118
- * --- 获取秒级时间戳 ---
119
- * @param date Date 对象可选
120
- * @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
121
- */
122
- export function stamp(date?: Date | string, zone?: number | sCtr.Ctr | null): number {
123
- if (date) {
124
- if (date instanceof Date) {
125
- return Math.floor(date.getTime() / 1000);
126
- }
127
- if (zone === null || zone === undefined) {
128
- zone = -(new Date()).getTimezoneOffset();
129
- }
130
- else if (zone instanceof sCtr.Ctr) {
131
- zone = zone.getPrototype('_config').set.timezone * 60;
132
- }
133
- else {
134
- zone *= 60;
135
- }
136
- /** --- 时区是否是负数 --- */
137
- const negative = zone < 0;
138
- /** --- 时区绝对值 --- */
139
- const zoneabs = Math.abs(zone);
140
- return Math.floor((new Date(`${date} ${negative ? '-' : '+'}${Math.floor(zoneabs / 60)}:${zoneabs % 60}`)).getTime() / 1000);
141
- }
142
- else {
143
- return Math.floor(Date.now() / 1000);
144
- }
145
- }
146
-
147
- /**
148
- * --- 是否是毫秒 ---
149
- * @param time 要判断的时间戳
150
- */
151
- export function isMs(time: number): boolean {
152
- return time > 1000000000000 ? true : false;
153
- }
154
-
155
- /**
156
- * --- 将时间对象转换为时间字符串 ---
157
- * @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
158
- * @param f 转换格式
159
- * @param date 时间对象或秒/毫秒级数字,如果是秒请乘以 1000
160
- */
161
- export function format(zone: number | sCtr.Ctr | null, f: string, date?: Date | number): string {
162
- const over: string[] = [];
163
- if (date === undefined) {
164
- date = new Date();
165
- }
166
- else if (typeof date === 'number') {
167
- date = new Date(isMs(date) ? date : date * 1000);
168
- }
169
- if (zone === null) {
170
- zone = (-date.getTimezoneOffset()) / 60;
171
- }
172
- else if (zone instanceof sCtr.Ctr) {
173
- zone = zone.getPrototype('_config').set.timezone;
174
- }
175
- if (zone !== 0) {
176
- date = new Date(date.getTime() + zone * 60 * 60 * 1000);
177
- }
178
- for (const v of f) {
179
- switch (v) {
180
- case 'd': {
181
- over.push(date.getUTCDate().toString().padStart(2, '0'));
182
- break;
183
- }
184
- case 'D': {
185
- over.push(dayNames[0][date.getUTCDay()]);
186
- break;
187
- }
188
- case 'j': {
189
- over.push(date.getUTCDate().toString());
190
- break;
191
- }
192
- case 'l': {
193
- over.push(dayNames[1][date.getUTCDay()]);
194
- break;
195
- }
196
- case 'N': {
197
- const d = date.getUTCDay();
198
- over.push((d ? d : 7).toString());
199
- break;
200
- }
201
- case 'w': {
202
- over.push(date.getUTCDay().toString());
203
- break;
204
- }
205
- case 'Y': {
206
- over.push(date.getUTCFullYear().toString());
207
- break;
208
- }
209
- case 'y': {
210
- over.push(date.getUTCFullYear().toString().slice(-2));
211
- break;
212
- }
213
- case 'F': {
214
- over.push(monthNames[1][date.getUTCMonth()]);
215
- break;
216
- }
217
- case 'M': {
218
- over.push(monthNames[0][date.getUTCMonth()]);
219
- break;
220
- }
221
- case 'm': {
222
- over.push((date.getUTCMonth() + 1).toString().padStart(2, '0'));
223
- break;
224
- }
225
- case 'H': {
226
- over.push(date.getUTCHours().toString().padStart(2, '0'));
227
- break;
228
- }
229
- case 'h': {
230
- const h = date.getUTCHours();
231
- over.push((h > 12 ? h - 12 : h).toString().padStart(2, '0'));
232
- break;
233
- }
234
- case 'i': {
235
- over.push(date.getUTCMinutes().toString().padStart(2, '0'));
236
- break;
237
- }
238
- case 's': {
239
- over.push(date.getUTCSeconds().toString().padStart(2, '0'));
240
- break;
241
- }
242
- case 'T': {
243
- const t = -(date.getTimezoneOffset() / 60);
244
- over.push('UTC' + (t >= 0 ? '+' : '') + t.toString());
245
- break;
246
- }
247
- default: {
248
- over.push(v);
249
- break;
250
- }
251
- }
252
- }
253
- return over.join('');
254
- }