@maiyunnet/kebab 2.0.2 → 2.0.4

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 (49) hide show
  1. package/index.js +1 -1
  2. package/lib/sql.js +1 -3
  3. package/lib/text.js +5 -1
  4. package/package.json +1 -1
  5. package/tsconfig.json +1 -1
  6. package/index.ts +0 -33
  7. package/lib/buffer.ts +0 -152
  8. package/lib/captcha.ts +0 -63
  9. package/lib/consistent.ts +0 -219
  10. package/lib/core.ts +0 -880
  11. package/lib/crypto.ts +0 -384
  12. package/lib/db.ts +0 -719
  13. package/lib/dns.ts +0 -405
  14. package/lib/fs.ts +0 -527
  15. package/lib/jwt.ts +0 -276
  16. package/lib/kv.ts +0 -1489
  17. package/lib/lan.ts +0 -87
  18. package/lib/net/formdata.ts +0 -166
  19. package/lib/net/request.ts +0 -150
  20. package/lib/net/response.ts +0 -59
  21. package/lib/net.ts +0 -662
  22. package/lib/s3.ts +0 -235
  23. package/lib/scan.ts +0 -364
  24. package/lib/session.ts +0 -230
  25. package/lib/sql.ts +0 -1151
  26. package/lib/ssh/sftp.ts +0 -508
  27. package/lib/ssh/shell.ts +0 -123
  28. package/lib/ssh.ts +0 -191
  29. package/lib/text.ts +0 -615
  30. package/lib/time.ts +0 -254
  31. package/lib/ws.ts +0 -523
  32. package/lib/zip.ts +0 -447
  33. package/lib/zlib.ts +0 -350
  34. package/main.ts +0 -27
  35. package/sys/child.ts +0 -678
  36. package/sys/cmd.ts +0 -225
  37. package/sys/ctr.ts +0 -904
  38. package/sys/master.ts +0 -355
  39. package/sys/mod.ts +0 -1871
  40. package/sys/route.ts +0 -1113
  41. package/types/index.d.ts +0 -283
  42. package/www/example/ctr/main.ts +0 -9
  43. package/www/example/ctr/middle.ts +0 -26
  44. package/www/example/ctr/test.ts +0 -3218
  45. package/www/example/mod/test.ts +0 -47
  46. package/www/example/mod/testdata.ts +0 -30
  47. package/www/example/ws/mproxy.ts +0 -16
  48. package/www/example/ws/rproxy.ts +0 -14
  49. 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
- }