@maiyunnet/kebab 2.0.16 → 3.0.1

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 (82) hide show
  1. package/README.md +1 -5
  2. package/bin/kebab.js +1 -1
  3. package/index.d.ts +1 -1
  4. package/index.js +16 -18
  5. package/lib/buffer.js +4 -11
  6. package/lib/captcha.js +6 -44
  7. package/lib/consistent.js +8 -51
  8. package/lib/core.d.ts +4 -4
  9. package/lib/core.js +70 -132
  10. package/lib/crypto.js +43 -99
  11. package/lib/db.d.ts +5 -5
  12. package/lib/db.js +31 -68
  13. package/lib/dns.d.ts +1 -1
  14. package/lib/dns.js +12 -50
  15. package/lib/fs.js +26 -81
  16. package/lib/jwt.d.ts +3 -3
  17. package/lib/jwt.js +9 -50
  18. package/lib/kv.d.ts +4 -4
  19. package/lib/kv.js +31 -69
  20. package/lib/lan.js +4 -41
  21. package/lib/net/cacert.pem +78 -2
  22. package/lib/net/formdata.js +5 -42
  23. package/lib/net/request.d.ts +2 -2
  24. package/lib/net/request.js +3 -42
  25. package/lib/net/response.d.ts +1 -1
  26. package/lib/net/response.js +1 -5
  27. package/lib/net.d.ts +5 -5
  28. package/lib/net.js +24 -73
  29. package/lib/s3.d.ts +1 -1
  30. package/lib/s3.js +20 -59
  31. package/lib/scan.d.ts +3 -3
  32. package/lib/scan.js +10 -50
  33. package/lib/session.d.ts +3 -3
  34. package/lib/session.js +9 -46
  35. package/lib/sql.d.ts +2 -2
  36. package/lib/sql.js +9 -50
  37. package/lib/ssh/sftp.js +5 -46
  38. package/lib/ssh/shell.js +2 -39
  39. package/lib/ssh.d.ts +2 -2
  40. package/lib/ssh.js +5 -43
  41. package/lib/text.d.ts +1 -1
  42. package/lib/text.js +40 -104
  43. package/lib/time.d.ts +1 -1
  44. package/lib/time.js +10 -50
  45. package/lib/turnstile.d.ts +1 -1
  46. package/lib/turnstile.js +6 -43
  47. package/lib/ws.d.ts +2 -2
  48. package/lib/ws.js +14 -56
  49. package/lib/zip.d.ts +1 -1
  50. package/lib/zip.js +6 -47
  51. package/lib/zlib.js +17 -68
  52. package/main.js +6 -44
  53. package/package.json +9 -8
  54. package/sys/child.js +10 -45
  55. package/sys/cmd.js +8 -43
  56. package/sys/ctr.d.ts +5 -5
  57. package/sys/ctr.js +9 -47
  58. package/sys/master.js +11 -46
  59. package/sys/mod.d.ts +9 -5
  60. package/sys/mod.js +9 -43
  61. package/sys/route.d.ts +2 -2
  62. package/sys/route.js +24 -64
  63. package/types/index.d.ts +1 -0
  64. package/www/example/ctr/main.d.ts +1 -1
  65. package/www/example/ctr/main.js +2 -38
  66. package/www/example/ctr/middle.d.ts +2 -2
  67. package/www/example/ctr/middle.js +2 -38
  68. package/www/example/ctr/test.d.ts +2 -2
  69. package/www/example/ctr/test.js +65 -72
  70. package/www/example/mod/test.d.ts +2 -2
  71. package/www/example/mod/test.js +4 -42
  72. package/www/example/mod/testdata.d.ts +1 -1
  73. package/www/example/mod/testdata.js +3 -8
  74. package/www/example/ws/mproxy.d.ts +1 -1
  75. package/www/example/ws/mproxy.js +6 -41
  76. package/www/example/ws/rproxy.d.ts +1 -1
  77. package/www/example/ws/rproxy.js +5 -40
  78. package/www/example/ws/rsocket.d.ts +1 -1
  79. package/www/example/ws/rsocket.js +5 -40
  80. package/www/example/ws/test.d.ts +1 -1
  81. package/www/example/ws/test.js +7 -42
  82. package/eslint.config.js +0 -22
package/lib/ssh/sftp.js CHANGED
@@ -1,43 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Connection = void 0;
37
1
  // --- 库和定义 ---
38
- const core = __importStar(require("~/lib/core"));
39
- const text = __importStar(require("~/lib/text"));
40
- class Connection {
2
+ import * as core from '../../lib/core.js';
3
+ import * as text from '../../lib/text.js';
4
+ export class Connection {
41
5
  constructor(sftp, path) {
42
6
  this._client = sftp;
43
7
  this._path = path;
@@ -54,9 +18,7 @@ class Connection {
54
18
  'encoding': options
55
19
  };
56
20
  }
57
- else if (!options) {
58
- options = {};
59
- }
21
+ options ??= {};
60
22
  const encoding = options.encoding;
61
23
  const start = options.start;
62
24
  const end = options.end;
@@ -407,9 +369,7 @@ class Connection {
407
369
  'encoding': options
408
370
  };
409
371
  }
410
- else if (!options) {
411
- options = {};
412
- }
372
+ options ??= {};
413
373
  return this._client.createWriteStream(path, options);
414
374
  }
415
375
  /**
@@ -476,4 +436,3 @@ class Connection {
476
436
  this._client.end();
477
437
  }
478
438
  }
479
- exports.Connection = Connection;
package/lib/ssh/shell.js CHANGED
@@ -1,41 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Connection = void 0;
37
- const lCore = __importStar(require("~/lib/core"));
38
- class Connection {
1
+ import * as lCore from '../../lib/core.js';
2
+ export class Connection {
39
3
  constructor(stream) {
40
4
  this._client = stream;
41
5
  }
@@ -137,4 +101,3 @@ class Connection {
137
101
  return this._client;
138
102
  }
139
103
  }
140
- exports.Connection = Connection;
package/lib/ssh.d.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  * Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
5
5
  */
6
6
  import * as ssh2 from 'ssh2';
7
- import * as shell from './ssh/shell';
8
- import * as sftp from './ssh/sftp';
7
+ import * as shell from './ssh/shell.js';
8
+ import * as sftp from './ssh/sftp.js';
9
9
  interface IExtOptions {
10
10
  'mproxy'?: {
11
11
  'host': string;
package/lib/ssh.js CHANGED
@@ -1,52 +1,15 @@
1
- "use strict";
2
1
  /**
3
2
  * Project: Kebab, User: JianSuoQiYue
4
3
  * Date: 2019-6-8 21:34:35
5
4
  * Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
6
5
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || (function () {
24
- var ownKeys = function(o) {
25
- ownKeys = Object.getOwnPropertyNames || function (o) {
26
- var ar = [];
27
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
- return ar;
29
- };
30
- return ownKeys(o);
31
- };
32
- return function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- })();
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.Connection = void 0;
42
- exports.get = get;
43
6
  // --- 第三方 ---
44
- const ssh2 = __importStar(require("ssh2"));
7
+ import * as ssh2 from 'ssh2';
45
8
  // --- 自己 ---
46
- const shell = __importStar(require("./ssh/shell"));
47
- const sftp = __importStar(require("./ssh/sftp"));
9
+ import * as shell from './ssh/shell.js';
10
+ import * as sftp from './ssh/sftp.js';
48
11
  /** 主连接对象 */
49
- class Connection {
12
+ export class Connection {
50
13
  constructor() {
51
14
  this._client = new ssh2.Client();
52
15
  }
@@ -191,12 +154,11 @@ class Connection {
191
154
  });
192
155
  }
193
156
  }
194
- exports.Connection = Connection;
195
157
  /**
196
158
  * --- 创建一个 SSH 连接 ---
197
159
  * @param opt 选项
198
160
  */
199
- async function get(opt) {
161
+ export async function get(opt) {
200
162
  const conn = new Connection();
201
163
  const rtn = await conn.connect(opt);
202
164
  return rtn ? conn : null;
package/lib/text.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as types from '~/types';
1
+ import * as types from '../types/index.js';
2
2
  /**
3
3
  * --- 将文件大小格式化为带单位的字符串 ---
4
4
  * @param size 文件大小
package/lib/text.js CHANGED
@@ -1,80 +1,16 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.REGEXP_ASCII = exports.REGEXP_DOMAIN = exports.REGEXP_IPV6 = exports.REGEXP_IPV4 = exports.REGEXP_EMAIL = void 0;
37
- exports.sizeFormat = sizeFormat;
38
- exports.parseUrl = parseUrl;
39
- exports.urlResolve = urlResolve;
40
- exports.urlAtom = urlAtom;
41
- exports.isEMail = isEMail;
42
- exports.isIPv4 = isIPv4;
43
- exports.isIPv6 = isIPv6;
44
- exports.isDomain = isDomain;
45
- exports.isAscii = isAscii;
46
- exports.nlReplace = nlReplace;
47
- exports.parseDomain = parseDomain;
48
- exports.match = match;
49
- exports.isPhoneCN = isPhoneCN;
50
- exports.isIdCardCN = isIdCardCN;
51
- exports.queryStringify = queryStringify;
52
- exports.queryParse = queryParse;
53
- exports.htmlescape = htmlescape;
54
- exports.isRealPath = isRealPath;
55
- exports.getFilename = getFilename;
56
- exports.stringifyResult = stringifyResult;
57
- exports.parseJson = parseJson;
58
- exports.stringifyJson = stringifyJson;
59
- exports.stringifyBuffer = stringifyBuffer;
60
- exports.isFalsy = isFalsy;
61
- exports.isTruthy = isTruthy;
62
- exports.logicalOr = logicalOr;
63
- exports.str2int = str2int;
64
- exports.int2str = int2str;
65
1
  /**
66
2
  * Project: Kebab, User: JianSuoQiYue
67
3
  * Date: 2019-5-15 16:49:39
68
4
  * Last: 2020-04-06 20:51:06, 2022-9-29 15:18:16, 2022-12-29 00:01:30, 2024-3-6 17:53:14, 2024-5-31 17:29:52, 2025-6-13 15:47:02
69
5
  */
70
- const kebab = __importStar(require("~/index"));
71
- const fs = __importStar(require("./fs"));
6
+ import * as kebab from '../index.js';
7
+ import * as fs from './fs.js';
72
8
  /**
73
9
  * --- 将文件大小格式化为带单位的字符串 ---
74
10
  * @param size 文件大小
75
11
  * @param spliter 分隔符
76
12
  */
77
- function sizeFormat(size, spliter = ' ') {
13
+ export function sizeFormat(size, spliter = ' ') {
78
14
  const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
79
15
  let i = 0;
80
16
  for (; i < 6 && size >= 1024.0; ++i) {
@@ -86,7 +22,7 @@ function sizeFormat(size, spliter = ' ') {
86
22
  * --- 格式化一段 URL ---
87
23
  * @param url
88
24
  */
89
- function parseUrl(url) {
25
+ export function parseUrl(url) {
90
26
  // --- test: https://ab-3dc:aak9()$@github.com:80/nodejs/node/blob/master/lib/url.js?mail=abc@def.com#223 ---
91
27
  const rtn = {
92
28
  'protocol': null,
@@ -168,7 +104,7 @@ function parseUrl(url) {
168
104
  * @param from 基准路径
169
105
  * @param to 相对路径
170
106
  */
171
- function urlResolve(from, to) {
107
+ export function urlResolve(from, to) {
172
108
  from = from.replace('\\', '/');
173
109
  to = to.replace('\\', '/');
174
110
  // --- to 为空,直接返回 form ---
@@ -229,7 +165,7 @@ function urlResolve(from, to) {
229
165
  * --- 将路径中的 ../ ./ 都按规范妥善处理 ---
230
166
  * @param url 要处理的地址
231
167
  */
232
- function urlAtom(url) {
168
+ export function urlAtom(url) {
233
169
  // --- 删掉 ./ ---
234
170
  while (url.includes('/./')) {
235
171
  url = url.replace(/\/\.\//g, '/');
@@ -241,53 +177,53 @@ function urlAtom(url) {
241
177
  url = url.replace(/\.\.\//g, '');
242
178
  return url;
243
179
  }
244
- exports.REGEXP_EMAIL = /^[-_\w.]+@[-_\w.]+\.([a-zA-Z]+)$/i;
180
+ export const REGEXP_EMAIL = /^[-_\w.]+@[-_\w.]+\.([a-zA-Z]+)$/i;
245
181
  /**
246
182
  * --- 是否是邮件地址 ---
247
183
  * @param email
248
184
  */
249
- function isEMail(email) {
250
- return exports.REGEXP_EMAIL.test(email);
185
+ export function isEMail(email) {
186
+ return REGEXP_EMAIL.test(email);
251
187
  }
252
- exports.REGEXP_IPV4 = /^[0-9]{1,3}(\.[0-9]{1,3}){3}$/i;
188
+ export const REGEXP_IPV4 = /^[0-9]{1,3}(\.[0-9]{1,3}){3}$/i;
253
189
  /**
254
190
  * --- 是否是 IPv4 ---
255
191
  * @param ip
256
192
  */
257
- function isIPv4(ip) {
258
- return exports.REGEXP_IPV4.test(ip);
193
+ export function isIPv4(ip) {
194
+ return REGEXP_IPV4.test(ip);
259
195
  }
260
- exports.REGEXP_IPV6 = /^(\w*?:){2,7}[\w.]*$/i;
196
+ export const REGEXP_IPV6 = /^(\w*?:){2,7}[\w.]*$/i;
261
197
  /**
262
198
  * --- 是否是 IPv6 ---
263
199
  * @param ip
264
200
  */
265
- function isIPv6(ip) {
266
- return exports.REGEXP_IPV6.test(ip + ':');
201
+ export function isIPv6(ip) {
202
+ return REGEXP_IPV6.test(ip + ':');
267
203
  }
268
- exports.REGEXP_DOMAIN = /^.+?\.((?![0-9]).)+$/i;
204
+ export const REGEXP_DOMAIN = /^.+?\.((?![0-9]).)+$/i;
269
205
  /**
270
206
  * --- 判断是否是域名 ---
271
207
  * @param string $domain
272
208
  * @return bool
273
209
  */
274
- function isDomain(domain) {
275
- return exports.REGEXP_DOMAIN.test(domain);
210
+ export function isDomain(domain) {
211
+ return REGEXP_DOMAIN.test(domain);
276
212
  }
277
- exports.REGEXP_ASCII = /^[\x20-\x7E]*$/;
213
+ export const REGEXP_ASCII = /^[\x20-\x7E]*$/;
278
214
  /**
279
215
  * --- 判断是否在 ascii 字符集内,仅可输入部分 ---
280
216
  * @param text 要判断的文本
281
217
  */
282
- function isAscii(text) {
283
- return exports.REGEXP_ASCII.test(text);
218
+ export function isAscii(text) {
219
+ return REGEXP_ASCII.test(text);
284
220
  }
285
221
  /**
286
222
  * --- 换行替换为别的 ---
287
223
  * @param str 要替换的字符串
288
224
  * @param to 换行替换符
289
225
  */
290
- function nlReplace(str, to = '\n') {
226
+ export function nlReplace(str, to = '\n') {
291
227
  str = str.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
292
228
  if (to !== '\n') {
293
229
  str = str.replace(/\n/g, to);
@@ -300,7 +236,7 @@ let tldList;
300
236
  * --- 解析域名并获取 tld/sld/domain/sub ---
301
237
  * @param domain 域名
302
238
  */
303
- async function parseDomain(domain) {
239
+ export async function parseDomain(domain) {
304
240
  const rtn = {
305
241
  tld: null,
306
242
  sld: null,
@@ -356,7 +292,7 @@ async function parseDomain(domain) {
356
292
  * @param str 要检测的字符串
357
293
  * @param regs 正则列表
358
294
  */
359
- function match(str, regs) {
295
+ export function match(str, regs) {
360
296
  for (const reg of regs) {
361
297
  if (reg.test(str)) {
362
298
  return true;
@@ -369,14 +305,14 @@ function match(str, regs) {
369
305
  * --- 判断手机号是否是 11 位,不做真实性校验 ---
370
306
  * @param p 手机号
371
307
  */
372
- function isPhoneCN(p) {
308
+ export function isPhoneCN(p) {
373
309
  return /^1[0-9]{10}$/.test(p);
374
310
  }
375
311
  /**
376
312
  * --- 是否是中国大陆身份证号码 ---
377
313
  * @param idcard 身份证号
378
314
  */
379
- function isIdCardCN(idcard) {
315
+ export function isIdCardCN(idcard) {
380
316
  if (idcard.length !== 18) {
381
317
  return false;
382
318
  }
@@ -409,7 +345,7 @@ function isIdCardCN(idcard) {
409
345
  * @param query 要转换的对象
410
346
  * @param encode 是否转义
411
347
  */
412
- function queryStringify(query, encode = true) {
348
+ export function queryStringify(query, encode = true) {
413
349
  if (encode) {
414
350
  return Object.entries(query).map(([k, v]) => {
415
351
  if (Array.isArray(v)) {
@@ -429,7 +365,7 @@ function queryStringify(query, encode = true) {
429
365
  * --- 将 query string 转换为对象 ---
430
366
  * @param query 要转换的字符串
431
367
  */
432
- function queryParse(query) {
368
+ export function queryParse(query) {
433
369
  const ret = {};
434
370
  const arrayKeys = {};
435
371
  const arr = query.split('&');
@@ -463,7 +399,7 @@ function queryParse(query) {
463
399
  * --- HTML 特殊字符转换为实体字符 ---
464
400
  * @param html 待转换的 HTML
465
401
  */
466
- function htmlescape(html) {
402
+ export function htmlescape(html) {
467
403
  const type = typeof html;
468
404
  if (type !== 'string') {
469
405
  return '[' + type + ']';
@@ -474,7 +410,7 @@ function htmlescape(html) {
474
410
  * --- 判断是否是绝对路径,是返回 true,相对路径返回 false ---
475
411
  * @param path 要判断的路径字符串
476
412
  */
477
- function isRealPath(path) {
413
+ export function isRealPath(path) {
478
414
  path = path.replace(/\\/g, '/');
479
415
  if (path.startsWith('/')) {
480
416
  return true;
@@ -485,7 +421,7 @@ function isRealPath(path) {
485
421
  * --- 获取文件名 ---
486
422
  * @param path 文件路径
487
423
  */
488
- function getFilename(path) {
424
+ export function getFilename(path) {
489
425
  path = path.replace(/\\/g, '/');
490
426
  const lio = path.lastIndexOf('/');
491
427
  if (lio === -1) {
@@ -497,7 +433,7 @@ function getFilename(path) {
497
433
  * --- 将普通的返回 JSON 对象序列化为字符串,Mutton 不能使用 ---
498
434
  * @param o 返回 JSON 对象
499
435
  */
500
- function stringifyResult(rtn) {
436
+ export function stringifyResult(rtn) {
501
437
  if (Array.isArray(rtn)) {
502
438
  // --- [0, 'xxx'] 模式 ---
503
439
  if (rtn.length === 0) {
@@ -536,7 +472,7 @@ function stringifyResult(rtn) {
536
472
  * --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt,Kebab true, Mutton false ---
537
473
  * @param str 要解析的 json 字符串
538
474
  */
539
- function parseJson(str) {
475
+ export function parseJson(str) {
540
476
  try {
541
477
  str = str.replace(/("[\w-]+?" *: *)([-+0-9]+)([ \r\n]*[,}]|$)/g, (v, v1, v2, v3) => {
542
478
  return v1 + '"-mybigint-' + v2 + '"' + v3;
@@ -565,7 +501,7 @@ function parseJson(str) {
565
501
  * @param obj 要转换的 json 对象
566
502
  * @param space 美化方式
567
503
  */
568
- function stringifyJson(obj, space) {
504
+ export function stringifyJson(obj, space) {
569
505
  return JSON.stringify(obj, (k, v) => {
570
506
  if (typeof v === 'bigint') {
571
507
  return '-mybigint-' + v.toString();
@@ -577,7 +513,7 @@ function stringifyJson(obj, space) {
577
513
  * --- 输出文本格式的 buffer ---
578
514
  * @param buf 原始 buffer
579
515
  */
580
- function stringifyBuffer(buf) {
516
+ export function stringifyBuffer(buf) {
581
517
  const arr = buf.toString('hex').match(/.{1,2}/g);
582
518
  return `<Buffer ${arr ? arr.join(' ') : ''}>`;
583
519
  }
@@ -585,14 +521,14 @@ function stringifyBuffer(buf) {
585
521
  * --- 判断一个值是否是虚假的(为 null/undefined/空字符串/false/0) ---
586
522
  * @param val 要判断的值
587
523
  */
588
- function isFalsy(val) {
524
+ export function isFalsy(val) {
589
525
  return (val === null) || (val === undefined) || (val === '') || (val === false) || (val === 0);
590
526
  }
591
527
  /**
592
528
  * --- 判断一个值是否是真实的(不为 null/undefined/空字符串/false/0) ---
593
529
  * @param val 要判断的值
594
530
  */
595
- function isTruthy(val) {
531
+ export function isTruthy(val) {
596
532
  return !isFalsy(val);
597
533
  }
598
534
  /**
@@ -600,7 +536,7 @@ function isTruthy(val) {
600
536
  * @param v1 比对值
601
537
  * @param v2 比对值
602
538
  */
603
- function logicalOr(v1, v2) {
539
+ export function logicalOr(v1, v2) {
604
540
  return (isFalsy(v1) ? v2 : v1);
605
541
  }
606
542
  /**
@@ -613,7 +549,7 @@ function logicalOr(v1, v2) {
613
549
  * @param str 要转换的数字字符串
614
550
  * @param digits 小数点右移位数
615
551
  */
616
- function str2int(str, digits = 3) {
552
+ export function str2int(str, digits = 3) {
617
553
  const num = parseFloat(str);
618
554
  /** --- 位数,如 1000 --- */
619
555
  const factor = Math.pow(10, digits);
@@ -630,7 +566,7 @@ function str2int(str, digits = 3) {
630
566
  * @param digits 小数点左移位数
631
567
  * @param decimal 最终保留的小数位数
632
568
  */
633
- function int2str(int, digits = 4, decimal = 2) {
569
+ export function int2str(int, digits = 4, decimal = 2) {
634
570
  /** --- 正负符号 --- */
635
571
  const sign = int < 0 ? '-' : '';
636
572
  const absInt = Math.abs(int);
package/lib/time.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Date: 2019-6-6 12:04:15
4
4
  * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
5
5
  */
6
- import * as sCtr from '~/sys/ctr';
6
+ import * as sCtr from '../sys/ctr.js';
7
7
  export interface IOptions {
8
8
  /** --- 时区 --- */
9
9
  'zone'?: number;
package/lib/time.js CHANGED
@@ -1,55 +1,15 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Time = exports.YEAR = exports.DAY = exports.HOUR = void 0;
37
- exports.get = get;
38
- exports.stamp = stamp;
39
- exports.isMs = isMs;
40
- exports.format = format;
41
1
  /**
42
2
  * Project: Kebab, User: JianSuoQiYue
43
3
  * Date: 2019-6-6 12:04:15
44
4
  * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
45
5
  */
46
- const sCtr = __importStar(require("~/sys/ctr"));
6
+ import * as sCtr from '../sys/ctr.js';
47
7
  /** --- 一小时的秒数 --- */
48
- exports.HOUR = 3600;
8
+ export const HOUR = 3600;
49
9
  /** --- 一天的秒数 --- */
50
- exports.DAY = 86400;
10
+ export const DAY = 86400;
51
11
  /** --- 一年(365 天) */
52
- exports.YEAR = 31536000;
12
+ export const YEAR = 31536000;
53
13
  /** --- 星期名 --- */
54
14
  const dayNames = [
55
15
  ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
@@ -60,7 +20,7 @@ const monthNames = [
60
20
  ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
61
21
  ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
62
22
  ];
63
- class Time {
23
+ export class Time {
64
24
  /**
65
25
  * --- 构造函数 ---
66
26
  * @param opt
@@ -125,12 +85,11 @@ class Time {
125
85
  return stamp(this._date);
126
86
  }
127
87
  }
128
- exports.Time = Time;
129
88
  /**
130
89
  * --- 创建获取一个时间对象 ---
131
90
  * @param opt
132
91
  */
133
- function get(ctr, opt = {}) {
92
+ export function get(ctr, opt = {}) {
134
93
  return new Time(ctr, opt);
135
94
  }
136
95
  /**
@@ -138,7 +97,7 @@ function get(ctr, opt = {}) {
138
97
  * @param date Date 对象可选
139
98
  * @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
140
99
  */
141
- function stamp(date, zone) {
100
+ export function stamp(date, zone) {
142
101
  if (date) {
143
102
  if (date instanceof Date) {
144
103
  return Math.floor(date.getTime() / 1000);
@@ -166,7 +125,7 @@ function stamp(date, zone) {
166
125
  * --- 是否是毫秒 ---
167
126
  * @param time 要判断的时间戳
168
127
  */
169
- function isMs(time) {
128
+ export function isMs(time) {
170
129
  return time > 1000000000000 ? true : false;
171
130
  }
172
131
  /**
@@ -175,7 +134,7 @@ function isMs(time) {
175
134
  * @param f 转换格式
176
135
  * @param date 时间对象或秒/毫秒级数字,如果是秒请乘以 1000
177
136
  */
178
- function format(zone, f, date) {
137
+ export function format(zone, f, date) {
179
138
  const over = [];
180
139
  if (date === undefined) {
181
140
  date = new Date();
@@ -189,6 +148,7 @@ function format(zone, f, date) {
189
148
  else if (zone instanceof sCtr.Ctr) {
190
149
  zone = zone.getPrototype('_config').set.timezone;
191
150
  }
151
+ zone ??= (-date.getTimezoneOffset()) / 60;
192
152
  if (zone !== 0) {
193
153
  date = new Date(date.getTime() + zone * 60 * 60 * 1000);
194
154
  }
@@ -1,4 +1,4 @@
1
- import * as sCtr from '~/sys/ctr';
1
+ import * as sCtr from '../sys/ctr.js';
2
2
  /**
3
3
  * 0. CloudFlare:https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
4
4
  * 1. 腾讯云:https://cloud.tencent.com/document/product/1110/36926