@aitianyu.cn/types 0.1.2 → 0.1.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.
Files changed (66) hide show
  1. package/README.md +44 -0
  2. package/dist/lib/coding/Error.js +16 -6
  3. package/dist/lib/coding/Path.js +41 -20
  4. package/dist/lib/core/Environment.js +14 -0
  5. package/dist/lib/core/Errors.js +34 -13
  6. package/dist/lib/core/Language.js +60 -7
  7. package/dist/lib/core/Log.js +34 -2
  8. package/dist/lib/core/TypeConvertion.js +20 -0
  9. package/dist/lib/core/object/ArrayHelper.js +15 -4
  10. package/dist/lib/core/object/Bytes.js +8 -4
  11. package/dist/lib/core/object/Calculater.js +109 -44
  12. package/dist/lib/core/object/DataView.js +13 -4
  13. package/dist/lib/core/object/Integer.js +57 -36
  14. package/dist/lib/core/object/Json.js +22 -10
  15. package/dist/lib/core/object/ObjectHelper.js +38 -14
  16. package/dist/lib/core/object/StringHelper.js +35 -8
  17. package/dist/lib/index.js +47 -6
  18. package/dist/lib/security/Base32.js +22 -13
  19. package/dist/lib/security/Guid.js +18 -1
  20. package/dist/lib/security/Hash.js +10 -1
  21. package/dist/lib/security/QRCode.js +16 -4
  22. package/dist/lib/security/RSA.js +33 -20
  23. package/dist/lib/security/SHA.js +25 -15
  24. package/dist/lib/security/TOTP.js +31 -9
  25. package/dist/lib/types/AreaCode.js +140 -131
  26. package/dist/lib/types/Exception.js +17 -3
  27. package/dist/lib/types/Logs.js +13 -7
  28. package/dist/lib/types/PathBase.js +43 -23
  29. package/dist/lib/types/Security.js +6 -1
  30. package/dist/lib/types/TMap.js +48 -30
  31. package/dist/types/coding/Error.d.ts +16 -6
  32. package/dist/types/coding/Path.d.ts +45 -21
  33. package/dist/types/core/Environment.d.ts +14 -0
  34. package/dist/types/core/Errors.d.ts +34 -13
  35. package/dist/types/core/Language.d.ts +33 -7
  36. package/dist/types/core/Log.d.ts +34 -2
  37. package/dist/types/core/TypeConvertion.d.ts +20 -0
  38. package/dist/types/core/interface/ITJSON.d.ts +11 -0
  39. package/dist/types/core/interface/ITianyuType.d.ts +11 -0
  40. package/dist/types/core/object/ArrayHelper.d.ts +15 -4
  41. package/dist/types/core/object/Bytes.d.ts +8 -4
  42. package/dist/types/core/object/Calculater.d.ts +38 -10
  43. package/dist/types/core/object/DataView.d.ts +13 -4
  44. package/dist/types/core/object/Integer.d.ts +57 -36
  45. package/dist/types/core/object/Json.d.ts +22 -10
  46. package/dist/types/core/object/ObjectHelper.d.ts +38 -14
  47. package/dist/types/core/object/StringHelper.d.ts +35 -8
  48. package/dist/types/index.d.ts +44 -0
  49. package/dist/types/security/Base32.d.ts +31 -18
  50. package/dist/types/security/Guid.d.ts +19 -1
  51. package/dist/types/security/Hash.d.ts +10 -1
  52. package/dist/types/security/QRCode.d.ts +16 -4
  53. package/dist/types/security/RSA.d.ts +51 -28
  54. package/dist/types/security/SHA.d.ts +25 -15
  55. package/dist/types/security/TOTP.d.ts +31 -9
  56. package/dist/types/types/AreaCode.d.ts +140 -1
  57. package/dist/types/types/Exception.d.ts +17 -3
  58. package/dist/types/types/Logs.d.ts +59 -30
  59. package/dist/types/types/Object.d.ts +16 -7
  60. package/dist/types/types/PathBase.d.ts +43 -23
  61. package/dist/types/types/Security.d.ts +21 -8
  62. package/dist/types/types/TMap.d.ts +48 -30
  63. package/dist/types/types/Types.d.ts +42 -10
  64. package/doc/en/README.md +372 -0
  65. package/doc/zh/README.md +372 -0
  66. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @aitianyu.cn/types
2
+
3
+ A comprehensive utility library providing base types, helper functions, and security utilities for the aitianyu ecosystem. Supports both Node.js and browser environments.
4
+
5
+ 为 aitianyu 生态系统提供基础类型、帮助函数和安全工具的综合工具库,同时支持 Node.js 和浏览器运行环境。
6
+
7
+ ---
8
+
9
+ **[English Documentation](doc/en/README.md)** | **[中文文档](doc/zh/README.md)**
10
+
11
+ ---
12
+
13
+ ## Quick Start / 快速开始
14
+
15
+ ```bash
16
+ npm install @aitianyu.cn/types
17
+ ```
18
+
19
+ ```typescript
20
+ import { guid, Log, StringHelper, TOTP, Base32, ObjectHelper } from "@aitianyu.cn/types";
21
+
22
+ // Generate a UUID / 生成 UUID
23
+ const id = guid();
24
+
25
+ // Format a string / 格式化字符串
26
+ const msg = StringHelper.format("Hello, {0}!", "world");
27
+
28
+ // Log a message / 记录日志
29
+ Log.info("Application started");
30
+
31
+ // Generate a TOTP secret / 生成 TOTP 密钥
32
+ const secret = TOTP.generate();
33
+ ```
34
+
35
+ ## Features / 功能特性
36
+
37
+ - **Core Utilities / 核心工具** — Logging, environment detection, type conversion, error handling / 日志、运行环境检测、类型转换、错误处理
38
+ - **Object Helpers / 对象帮助工具** — Deep clone, compare, string formatting, array and byte operations / 深度克隆、比较、字符串格式化、数组与字节操作
39
+ - **Security / 安全模块** — TOTP, Base32, GUID/UUID, SHA hashing, RSA encryption, QR code generation / TOTP、Base32、GUID/UUID、SHA 哈希、RSA 加密、二维码生成
40
+ - **Type Definitions / 类型定义** — Common interfaces, generic types, area codes, path utilities / 通用接口、泛型类型、区域码、路径工具
41
+
42
+ ## License
43
+
44
+ ISC © aitianyu.cn
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = void 0;
5
5
  const Exception_1 = require("../types/Exception");
6
6
  /**
7
- * Source lost exception of Path Processor.
8
- * Exception will be thrown if the path is file but the file field is not specified
7
+ * Thrown when a Path instance is typed as "file" but no file name has been provided.
8
+ * Path 实例的类型为 "file" 但未指定文件名时抛出此异常。
9
9
  */
10
10
  class PathProcessorSourceLostException extends Exception_1.Exception {
11
+ /**
12
+ * @param msg optional additional message / 可选的附加信息
13
+ */
11
14
  constructor(msg) {
12
15
  super(msg);
13
16
  }
@@ -17,10 +20,13 @@ class PathProcessorSourceLostException extends Exception_1.Exception {
17
20
  }
18
21
  exports.PathProcessorSourceLostException = PathProcessorSourceLostException;
19
22
  /**
20
- * Path directory name is not valid.
21
- * Exception will be thrown if the path name has the invalid char
23
+ * Thrown when a path segment contains characters that are not valid in a directory name.
24
+ * 当路径段中包含目录名非法字符时抛出此异常。
22
25
  */
23
26
  class PathDirectoryValidationFailException extends Exception_1.Exception {
27
+ /**
28
+ * @param msg the invalid directory name / 非法的目录名
29
+ */
24
30
  constructor(msg) {
25
31
  super(msg);
26
32
  }
@@ -30,10 +36,14 @@ class PathDirectoryValidationFailException extends Exception_1.Exception {
30
36
  }
31
37
  exports.PathDirectoryValidationFailException = PathDirectoryValidationFailException;
32
38
  /**
33
- * Path is file or directory but target type is not.
34
- * Exception will be thrown if the path is file(directory) but try to convert to directory(file)
39
+ * Thrown when attempting to treat a file path as a directory path or vice versa.
40
+ * 当尝试将文件路径当作目录路径(或反之)进行转换时抛出此异常。
35
41
  */
36
42
  class PathDirAndFileConvertInvaild extends Exception_1.Exception {
43
+ /**
44
+ * @param path the path string that caused the conflict / 引发冲突的路径字符串
45
+ * @param type the actual type of the path / 路径的实际类型
46
+ */
37
47
  constructor(path, type) {
38
48
  super(`${path} 为 ${type === "directory" ? "目录" : "文件"}`);
39
49
  }
@@ -94,16 +94,27 @@ function _parsePathFromString(src) {
94
94
  }
95
95
  return path;
96
96
  }
97
- /** Path */
97
+ /**
98
+ * Represents a file system path with explicit type (directory or file).
99
+ * Supports construction from a string, an array of segments, or a combination.
100
+ * Throws validation exceptions for invalid segment characters or type mismatches.
101
+ *
102
+ * 表示具有明确类型(目录或文件)的文件系统路径。
103
+ * 支持从字符串、目录段数组或两者组合构建实例。
104
+ * 遇到非法字符或类型不匹配时会抛出校验异常。
105
+ */
98
106
  class Path extends PathBase_1.PathBase {
107
+ /** Internal path type indicator. / 内部路径类型标识。 */
99
108
  _type;
109
+ /** The file name component, present only when type is "file". / 文件名组件,仅在类型为 "file" 时存在。 */
100
110
  _file;
101
111
  /**
102
- * Create a new Path instance
112
+ * Create a new Path instance.
113
+ * 创建一个新的 Path 实例。
103
114
  *
104
- * @param dirs the directory names
105
- * @param type indicate which type the Path is
106
- * @param file the file name if the type is file
115
+ * @param dirs directory segments as an array or a full path string / 目录段数组或完整路径字符串
116
+ * @param type explicit target type; inferred from string if omitted / 显式目标类型,省略时从字符串推断
117
+ * @param file explicit file name when type is "file" / 类型为 "file" 时指定文件名
107
118
  */
108
119
  constructor(dirs, type, file) {
109
120
  super();
@@ -125,9 +136,13 @@ class Path extends PathBase_1.PathBase {
125
136
  this._file = actFile;
126
137
  }
127
138
  /**
128
- * Convert the path to a string
139
+ * Convert this path to its string representation.
140
+ * Throws PathProcessorSourceLostException if type is "file" but no file name is set.
129
141
  *
130
- * @returns return the string
142
+ * 将路径转换为字符串表示形式。
143
+ * 若类型为 "file" 但未设置文件名,则抛出 PathProcessorSourceLostException。
144
+ *
145
+ * @returns the formatted path string / 格式化后的路径字符串
131
146
  */
132
147
  toString() {
133
148
  if (this.getType() === "file" && !!!this.getFile()) {
@@ -156,26 +171,29 @@ class Path extends PathBase_1.PathBase {
156
171
  return dirs.join("/");
157
172
  }
158
173
  /**
159
- * Set the target type
174
+ * Set the target type of this path instance.
175
+ * 设置当前路径实例的目标类型。
160
176
  *
161
- * @param type new type
177
+ * @param type the new path type / 新路径类型
162
178
  */
163
179
  setType(type) {
164
180
  this._type = type;
165
181
  }
166
182
  /**
167
- * Get the path type of current instance
183
+ * Get the target type of this path instance.
184
+ * 获取当前路径实例的目标类型。
168
185
  *
169
- * @returns return the path type
186
+ * @returns the path type / 路径类型
170
187
  */
171
188
  getType() {
172
189
  return this._type;
173
190
  }
174
191
  /**
175
- * Set the path file name
192
+ * Set a new file name for this path.
193
+ * 设置当前路径的新文件名。
176
194
  *
177
- * @param file the new file name
178
- * @returns return the old file name
195
+ * @param file the new file name / 新文件名
196
+ * @returns the previous file name, or undefined if none was set / 之前的文件名,未设置时返回 undefined
179
197
  */
180
198
  setFile(file) {
181
199
  const oldFile = this._file;
@@ -183,25 +201,28 @@ class Path extends PathBase_1.PathBase {
183
201
  return oldFile;
184
202
  }
185
203
  /**
186
- * Get the file name of current instance
204
+ * Get the file name component of this path.
205
+ * 获取当前路径的文件名组件。
187
206
  *
188
- * @returns return the file name
207
+ * @returns the file name, or undefined if this is a directory path / 文件名,若为目录路径则返回 undefined
189
208
  */
190
209
  getFile() {
191
210
  return this._file;
192
211
  }
193
212
  /**
194
- * IComparable impl to get a string what equals to current instance
213
+ * IComparable implementation returns the string form for equality comparison.
214
+ * IComparable 实现——返回用于相等性比较的字符串形式。
195
215
  *
196
- * @returns return the string
216
+ * @returns the comparable string / 可比较字符串
197
217
  */
198
218
  getString() {
199
219
  return this.toString();
200
220
  }
201
221
  /**
202
- * Get a hash code of current instance
222
+ * IComparable implementation returns 0 as the hash code.
223
+ * IComparable 实现——返回 0 作为哈希码。
203
224
  *
204
- * @returns always return 0
225
+ * @returns always 0 / 始终返回 0
205
226
  */
206
227
  getHashCode() {
207
228
  return 0;
@@ -2,7 +2,21 @@
2
2
  /** @format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Environment = void 0;
5
+ /**
6
+ * Runtime environment detection utility.
7
+ * Identifies whether the current execution context is Node.js or a browser.
8
+ *
9
+ * 运行时环境检测工具类。
10
+ * 用于识别当前执行上下文是 Node.js 还是浏览器环境。
11
+ */
5
12
  class Environment {
13
+ /**
14
+ * Detect the current runtime environment.
15
+ * 检测当前运行时环境。
16
+ *
17
+ * @returns "node" when running in Node.js, "browser" otherwise
18
+ * 在 Node.js 中运行时返回 "node",否则返回 "browser"
19
+ */
6
20
  static runtimeEnv() {
7
21
  const isNode = !!(typeof process !== "undefined" && process.versions && process.versions.node);
8
22
  return isNode ? "node" : "browser";
@@ -3,8 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = void 0;
5
5
  const Exception_1 = require("../types/Exception");
6
- /** Argument null exception */
6
+ /**
7
+ * Thrown when a required argument is null or an empty string.
8
+ * 当必填参数为 null 或空字符串时抛出。
9
+ */
7
10
  class ArgumentNullOrEmptyException extends Exception_1.Exception {
11
+ /**
12
+ * @param msg the name of the offending argument / 出错的参数名称
13
+ */
8
14
  constructor(msg) {
9
15
  super(msg);
10
16
  }
@@ -14,9 +20,11 @@ class ArgumentNullOrEmptyException extends Exception_1.Exception {
14
20
  }
15
21
  exports.ArgumentNullOrEmptyException = ArgumentNullOrEmptyException;
16
22
  /**
17
- * Object Clone:
18
- * Function type is not supported.
19
- * Exception will be thrown if try to clone a function type object
23
+ * Thrown when attempting to deep-clone an object that contains a function value.
24
+ * Function types are not supported by the clone utility.
25
+ *
26
+ * 当尝试深度克隆包含函数值的对象时抛出。
27
+ * 克隆工具不支持 function 类型。
20
28
  */
21
29
  class ObjectCloneFunctionNotSupportException extends Exception_1.Exception {
22
30
  constructor() {
@@ -28,13 +36,18 @@ class ObjectCloneFunctionNotSupportException extends Exception_1.Exception {
28
36
  }
29
37
  exports.ObjectCloneFunctionNotSupportException = ObjectCloneFunctionNotSupportException;
30
38
  /**
31
- * Object Clone:
32
- * Object different status could not be matched.
33
- * Exception will be thrown if the object diff could not to be merged
39
+ * Thrown when the expected state of an object diff entry does not match
40
+ * the actual current state during a merge operation.
41
+ *
42
+ * 在合并操作中,对象差异条目的预期状态与当前实际状态不匹配时抛出。
34
43
  */
35
44
  class ObjectMergeStatusCheckFailedException extends Exception_1.Exception {
36
45
  status;
37
46
  path;
47
+ /**
48
+ * @param path the diff path where the mismatch occurred / 发生不匹配的差异路径
49
+ * @param status the type of change that failed verification / 校验失败的变更类型
50
+ */
38
51
  constructor(path, status) {
39
52
  super();
40
53
  this.path = path;
@@ -46,12 +59,16 @@ class ObjectMergeStatusCheckFailedException extends Exception_1.Exception {
46
59
  }
47
60
  exports.ObjectMergeStatusCheckFailedException = ObjectMergeStatusCheckFailedException;
48
61
  /**
49
- * Object Clone:
50
- * Object different status could not be applied.
51
- * Exception will be thrown if the object diff could not to be applied
62
+ * Thrown when a diff entry cannot be applied because the current value
63
+ * is in an unexpected state (e.g., a value that should not exist already does).
64
+ *
65
+ * 当差异条目因当前值处于意外状态(如不应存在的值已存在)而无法应用时抛出。
52
66
  */
53
67
  class ObjectDiffApplyInvalidStatusException extends Exception_1.Exception {
54
68
  value;
69
+ /**
70
+ * @param value the value that is in an invalid state / 处于无效状态的值
71
+ */
55
72
  constructor(value) {
56
73
  super();
57
74
  this.value = value;
@@ -69,12 +86,16 @@ class ObjectDiffApplyInvalidStatusException extends Exception_1.Exception {
69
86
  }
70
87
  exports.ObjectDiffApplyInvalidStatusException = ObjectDiffApplyInvalidStatusException;
71
88
  /**
72
- * Object Clone:
73
- * Object different merge failed.
74
- * Exception will be thrown if the object element could not be accessed
89
+ * Thrown when a nested object at a specific path cannot be accessed during a diff merge,
90
+ * typically because an intermediate parent object is missing.
91
+ *
92
+ * 在差异合并期间,因中间父对象缺失等原因导致特定路径处的嵌套对象无法访问时抛出。
75
93
  */
76
94
  class ObjectDiffMergeFailedException extends Exception_1.Exception {
77
95
  path;
96
+ /**
97
+ * @param path the path where the inaccessible object was encountered / 遇到无法访问对象的路径
98
+ */
78
99
  constructor(path) {
79
100
  super();
80
101
  this.path = path;
@@ -3,6 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.parseAreaString = exports.parseAreaCode = void 0;
5
5
  const AreaCode_1 = require("../types/AreaCode");
6
+ /**
7
+ * Internal implementation: convert a locale string to its corresponding AreaCode enum value.
8
+ * The input is normalised to lower-case before matching.
9
+ * When no match is found, the fallback depends on `forceArea`:
10
+ * - false / omitted → AreaCode.zh_CN
11
+ * - true → AreaCode.unknown
12
+ *
13
+ * 内部实现:将语言环境字符串转换为对应的 AreaCode 枚举值。
14
+ * 输入会先转换为小写再进行匹配。
15
+ * 未匹配时的回退值取决于 `forceArea`:
16
+ * - false / 省略 → AreaCode.zh_CN
17
+ * - true → AreaCode.unknown
18
+ *
19
+ * @param areaStr the locale string to parse, e.g. "zh_CN" / 要解析的语言环境字符串,如 "zh_CN"
20
+ * @param forceArea when true, returns AreaCode.unknown for unrecognised strings / 为 true 时,无法识别的字符串返回 AreaCode.unknown
21
+ * @returns the matching AreaCode enum value / 对应的 AreaCode 枚举值
22
+ */
6
23
  // eslint-disable-next-line complexity
7
24
  function _parseAreaString(areaStr, forceArea) {
8
25
  const lowCase = areaStr?.toLowerCase() || "zh_cn";
@@ -271,6 +288,16 @@ function _parseAreaString(areaStr, forceArea) {
271
288
  return forceArea ? AreaCode_1.AreaCode.unknown : AreaCode_1.AreaCode.zh_CN;
272
289
  }
273
290
  }
291
+ /**
292
+ * Internal implementation: convert an AreaCode enum value to its canonical locale string.
293
+ * Falls back to "zh_CN" for AreaCode.unknown and any unrecognised value.
294
+ *
295
+ * 内部实现:将 AreaCode 枚举值转换为其标准语言环境字符串。
296
+ * AreaCode.unknown 及任何无法识别的值均回退为 "zh_CN"。
297
+ *
298
+ * @param eArea the AreaCode enum value to convert / 要转换的 AreaCode 枚举值
299
+ * @returns the canonical locale string, e.g. "zh_CN" / 标准语言环境字符串,如 "zh_CN"
300
+ */
274
301
  // eslint-disable-next-line complexity
275
302
  function _areaCodeToString(eArea) {
276
303
  switch (eArea) {
@@ -539,21 +566,47 @@ function _areaCodeToString(eArea) {
539
566
  }
540
567
  }
541
568
  /**
542
- * Parse area code to general string
569
+ * Convert an AreaCode enum value to its canonical locale string (e.g. "zh_CN", "en_US").
570
+ * Falls back to "zh_CN" for AreaCode.unknown.
571
+ *
572
+ * 将 AreaCode 枚举值转换为其标准语言环境字符串(如 "zh_CN"、"en_US")。
573
+ * AreaCode.unknown 回退为 "zh_CN"。
543
574
  *
544
- * @param eArea the area code
545
- * @returns return the general string of specified area code
575
+ * @param eArea the AreaCode enum value / AreaCode 枚举值
576
+ * @returns the locale string for the given area code / 给定区域码对应的语言环境字符串
577
+ *
578
+ * @example
579
+ * parseAreaCode(AreaCode.zh_CN); // "zh_CN"
580
+ * parseAreaCode(AreaCode.en_US); // "en_US"
546
581
  */
547
582
  function parseAreaCode(eArea) {
548
583
  return _areaCodeToString(eArea);
549
584
  }
550
585
  exports.parseAreaCode = parseAreaCode;
551
586
  /**
552
- * Convert the string to area code
587
+ * Parse a locale string into its corresponding AreaCode enum value.
588
+ * The input is matched case-insensitively (e.g. "ZH_CN", "zh_cn", and "zh_CN" all resolve to AreaCode.zh_CN).
589
+ *
590
+ * When the string cannot be matched:
591
+ * - `forceArea` omitted or false → returns AreaCode.zh_CN (lenient default)
592
+ * - `forceArea` true → returns AreaCode.unknown (strict mode)
593
+ *
594
+ * 将语言环境字符串解析为对应的 AreaCode 枚举值。
595
+ * 输入不区分大小写(如 "ZH_CN"、"zh_cn"、"zh_CN" 均解析为 AreaCode.zh_CN)。
596
+ *
597
+ * 字符串无法匹配时:
598
+ * - `forceArea` 省略或为 false → 返回 AreaCode.zh_CN(宽松默认值)
599
+ * - `forceArea` 为 true → 返回 AreaCode.unknown(严格模式)
600
+ *
601
+ * @param areaStr the locale string to parse; defaults to "zh_CN" if omitted / 要解析的语言环境字符串,省略时默认为 "zh_CN"
602
+ * @param forceArea when true, returns AreaCode.unknown for unrecognised strings / 为 true 时,无法识别的字符串返回 AreaCode.unknown
603
+ * @returns the matching AreaCode enum value / 对应的 AreaCode 枚举值
553
604
  *
554
- * @param areaStr the source string
555
- * @param forceArea a boolean value indicates whether needs to have a strict check for the source string. (That means if in strict mode and the string could not be converted, an unkonwn will be returned.)
556
- * @returns return the area code
605
+ * @example
606
+ * parseAreaString("zh_CN"); // AreaCode.zh_CN
607
+ * parseAreaString("en_US"); // AreaCode.en_US
608
+ * parseAreaString("invalid", true); // AreaCode.unknown
609
+ * parseAreaString("invalid"); // AreaCode.zh_CN
557
610
  */
558
611
  function parseAreaString(areaStr, forceArea) {
559
612
  return _parseAreaString(areaStr, forceArea);
@@ -103,10 +103,42 @@ function _endPerf(recorder, console) {
103
103
  }
104
104
  return perfTime;
105
105
  }
106
- /** Tianyu Log Instance */
106
+ /**
107
+ * The global Tianyu log instance.
108
+ * Provides leveled console logging with optional timestamp support.
109
+ *
110
+ * 全局 Tianyu 日志实例。
111
+ * 提供带可选时间戳的分级控制台日志功能。
112
+ */
107
113
  exports.Log = _log;
108
- /** Tianyu Performance Instance */
114
+ /**
115
+ * The global Tianyu performance tracking instance.
116
+ * Use startPerf / endPerf to measure elapsed time for any named operation.
117
+ *
118
+ * 全局 Tianyu 性能跟踪实例。
119
+ * 使用 startPerf / endPerf 测量任意命名操作的耗时。
120
+ *
121
+ * @example
122
+ * const rec = Performance.startPerf("db-query");
123
+ * // ... do work ...
124
+ * const ms = Performance.endPerf(rec, true); // logs and returns elapsed ms
125
+ */
109
126
  exports.Performance = {
127
+ /**
128
+ * Start a performance recording session.
129
+ * 开始一次性能记录会话。
130
+ *
131
+ * @param id optional session name / 可选的会话名称
132
+ * @returns a recorder object holding the start timestamp / 包含开始时间戳的记录器对象
133
+ */
110
134
  startPerf: _startPerf,
135
+ /**
136
+ * End a performance recording session and return elapsed milliseconds.
137
+ * 结束性能记录会话并返回经过的毫秒数。
138
+ *
139
+ * @param recorder the recorder returned by startPerf / startPerf 返回的记录器
140
+ * @param console whether to print the elapsed time to the console / 是否将耗时输出到控制台
141
+ * @returns elapsed time in milliseconds / 经过的毫秒数
142
+ */
111
143
  endPerf: _endPerf,
112
144
  };
@@ -2,6 +2,26 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getBoolean = void 0;
5
+ /**
6
+ * Convert a value of any type to a boolean.
7
+ * Conversion rules:
8
+ * - null / undefined → false
9
+ * - number: 0 → false, any other number → true
10
+ * - string: "" or "false" (case-insensitive) → false, any other non-empty string → true
11
+ * - boolean: returned as-is
12
+ * - any other type → true
13
+ *
14
+ * 将任意类型的值转换为布尔值。
15
+ * 转换规则:
16
+ * - null / undefined → false
17
+ * - number:0 → false,其他数值 → true
18
+ * - string:空字符串或 "false"(大小写不敏感)→ false,其他非空字符串 → true
19
+ * - boolean:直接返回原值
20
+ * - 其他类型 → true
21
+ *
22
+ * @param value the value to convert / 要转换的值
23
+ * @returns the boolean result / 转换后的布尔值
24
+ */
5
25
  function getBoolean(value) {
6
26
  if (value === null) {
7
27
  return false;
@@ -2,13 +2,24 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ArrayHelper = void 0;
5
- /** Array type related tools */
5
+ /**
6
+ * Array utility class providing merge and deduplication helpers.
7
+ * 数组工具类,提供合并与去重帮助方法。
8
+ */
6
9
  class ArrayHelper {
7
10
  /**
8
- * To merge multiple arrays into a new array and remove duplicated elements.
11
+ * Merge multiple arrays (or individual values) into a single new array,
12
+ * removing duplicate elements. Non-array arguments are treated as single-item arrays.
9
13
  *
10
- * @param {any[]} array arrays
11
- * @returns return a new array
14
+ * 将多个数组(或单个值)合并为一个新数组,并移除重复元素。
15
+ * 非数组参数被视为单元素数组处理。
16
+ *
17
+ * @param array any number of arrays or individual values / 任意数量的数组或单个值
18
+ * @returns a new deduplicated array / 去重后的新数组
19
+ *
20
+ * @example
21
+ * ArrayHelper.merge([1, 2], [2, 3], 4);
22
+ * // => [1, 2, 3, 4]
12
23
  */
13
24
  static merge(...array) {
14
25
  if (array.length === 0) {
@@ -6,13 +6,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Bytes = void 0;
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
- /** Bytes Object type */
9
+ /**
10
+ * Byte buffer utility class.
11
+ * 字节缓冲区工具类。
12
+ */
10
13
  class Bytes {
11
14
  /**
12
- * Get a bytes buffer filled with random data
15
+ * Generate a Buffer of the specified size filled with cryptographically random bytes.
16
+ * 生成指定大小、由密码学安全随机字节填充的 Buffer。
13
17
  *
14
- * @param size the length of bytes buffer
15
- * @returns buffer
18
+ * @param size the number of random bytes to generate / 要生成的随机字节数
19
+ * @returns a Buffer containing random data / 包含随机数据的 Buffer
16
20
  */
17
21
  static random(size) {
18
22
  return crypto_1.default.randomBytes(size);