@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
@@ -2,7 +2,26 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.StringHelper = void 0;
5
+ /**
6
+ * String utility class providing formatting and safe serialization helpers.
7
+ * 字符串工具类,提供格式化和安全序列化帮助方法。
8
+ */
5
9
  class StringHelper {
10
+ /**
11
+ * Format a string by replacing positional placeholders `{N}` with the corresponding argument.
12
+ * Works similarly to C#'s String.Format.
13
+ *
14
+ * 通过将位置占位符 `{N}` 替换为对应参数来格式化字符串。
15
+ * 用法类似于 C# 的 String.Format。
16
+ *
17
+ * @param source the format template string containing `{0}`, `{1}`, … placeholders / 包含 `{0}`、`{1}` 等占位符的格式模板字符串
18
+ * @param args a single argument or an array of arguments / 单个参数或参数数组
19
+ * @returns the formatted string / 格式化后的字符串
20
+ *
21
+ * @example
22
+ * StringHelper.format("Hello, {0}! You have {1} messages.", "Alice", 5);
23
+ * // => "Hello, Alice! You have 5 messages."
24
+ */
6
25
  static format(source, args) {
7
26
  if (!args) {
8
27
  return source;
@@ -19,13 +38,16 @@ class StringHelper {
19
38
  });
20
39
  }
21
40
  /**
22
- * @deprecated
41
+ * @deprecated Use stringifySafe instead.
42
+ *
43
+ * Convert a value to a string. Throws an Error if the value is a function type.
44
+ * For safer usage, prefer stringifySafe which returns "" on failure.
23
45
  *
24
- * convert an object to be a string.
25
- * This is an unsafe function to convert an object to be string. suggest to use stringifySafe to convert object to string.
46
+ * 将值转换为字符串。若值为函数类型则抛出 Error。
47
+ * 建议使用更安全的 stringifySafe,失败时返回 ""。
26
48
  *
27
- * @param src source object
28
- * @returns target string
49
+ * @param data the value to convert / 要转换的值
50
+ * @returns the string representation / 字符串表示
29
51
  */
30
52
  static stringify(data) {
31
53
  const type = typeof data;
@@ -44,10 +66,15 @@ class StringHelper {
44
66
  return JSON.stringify(data);
45
67
  }
46
68
  /**
47
- * convert an object to be a string safty. empty string will be return when error occurs in converting
69
+ * Convert a value to a string safely.
70
+ * Returns an empty string if any error occurs during conversion
71
+ * (e.g. circular references or function types).
72
+ *
73
+ * 安全地将值转换为字符串。
74
+ * 若转换过程中发生任何错误(如循环引用或函数类型),则返回空字符串。
48
75
  *
49
- * @param src source object
50
- * @returns target string
76
+ * @param data the value to convert / 要转换的值
77
+ * @returns the string representation, or "" on failure / 字符串表示,失败时返回 ""
51
78
  */
52
79
  static stringifySafe(data) {
53
80
  try {
package/dist/lib/index.js CHANGED
@@ -2,73 +2,114 @@
2
2
  /**@format */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TOTP = exports.SHA = exports.RSA = exports.QRCode = exports.hash = exports.guid = exports.Base32 = exports.Json = exports.Integer = exports.DataView = exports.Bytes = exports.StringHelper = exports.ArrayHelper = exports.ObjectHelper = exports.ObjectCalculater = exports.Environment = exports.getBoolean = exports.Performance = exports.Log = exports.parseAreaString = exports.parseAreaCode = exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = exports.Path = exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = exports.TMap = exports.EncryptOption = exports.PathBase = exports.LogLevel = exports.Exception = exports.AreaCode = void 0;
5
- // src/types
5
+ /**
6
+ * @aitianyu.cn/types — Public API entry point
7
+ *
8
+ * This file re-exports every public symbol from the library.
9
+ * Import from this package directly rather than from sub-paths.
10
+ *
11
+ * @aitianyu.cn/types — 公共 API 入口
12
+ *
13
+ * 本文件重新导出库中所有公共符号。
14
+ * 请直接从本包导入,而非从子路径导入。
15
+ *
16
+ * @example
17
+ * import { guid, Log, StringHelper, TOTP } from "@aitianyu.cn/types";
18
+ */
19
+ // ─── Type definitions / 类型定义 ────────────────────────────────────────────
20
+ /** International area code enum. / 国际区域码枚举。 */
6
21
  var AreaCode_1 = require("./types/AreaCode");
7
22
  Object.defineProperty(exports, "AreaCode", { enumerable: true, get: function () { return AreaCode_1.AreaCode; } });
23
+ /** Base exception class for all custom errors. / 所有自定义异常的基类。 */
8
24
  var Exception_1 = require("./types/Exception");
9
25
  Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });
26
+ /** Log level enum and log/performance recorder interfaces. / 日志级别枚举及日志/性能记录器接口。 */
10
27
  var Logs_1 = require("./types/Logs");
11
28
  Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return Logs_1.LogLevel; } });
29
+ /** Abstract path base class. / 抽象路径基类。 */
12
30
  var PathBase_1 = require("./types/PathBase");
13
31
  Object.defineProperty(exports, "PathBase", { enumerable: true, get: function () { return PathBase_1.PathBase; } });
32
+ /** Encryption option enum and cipher interface. / 加密选项枚举和密码接口。 */
14
33
  var Security_1 = require("./types/Security");
15
34
  Object.defineProperty(exports, "EncryptOption", { enumerable: true, get: function () { return Security_1.EncryptOption; } });
35
+ /** Generic comparable-key map. / 支持可比较键的泛型映射表。 */
16
36
  var TMap_1 = require("./types/TMap");
17
37
  Object.defineProperty(exports, "TMap", { enumerable: true, get: function () { return TMap_1.TMap; } });
18
- // utilities
19
- // coding
38
+ // ─── Coding utilities / 编码工具 ─────────────────────────────────────────────
39
+ /** Path-related exception classes. / 路径相关异常类。 */
20
40
  var Error_1 = require("./coding/Error");
21
41
  Object.defineProperty(exports, "PathProcessorSourceLostException", { enumerable: true, get: function () { return Error_1.PathProcessorSourceLostException; } });
22
42
  Object.defineProperty(exports, "PathDirectoryValidationFailException", { enumerable: true, get: function () { return Error_1.PathDirectoryValidationFailException; } });
23
43
  Object.defineProperty(exports, "PathDirAndFileConvertInvaild", { enumerable: true, get: function () { return Error_1.PathDirAndFileConvertInvaild; } });
44
+ /** Path type and Path class. / 路径类型及 Path 类。 */
24
45
  var Path_1 = require("./coding/Path");
25
46
  Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return Path_1.Path; } });
26
- // core
47
+ // ─── Core utilities / 核心工具 ───────────────────────────────────────────────
48
+ /** Core exception classes for argument and object operations. / 参数和对象操作的核心异常类。 */
27
49
  var Errors_1 = require("./core/Errors");
28
50
  Object.defineProperty(exports, "ArgumentNullOrEmptyException", { enumerable: true, get: function () { return Errors_1.ArgumentNullOrEmptyException; } });
29
51
  Object.defineProperty(exports, "ObjectCloneFunctionNotSupportException", { enumerable: true, get: function () { return Errors_1.ObjectCloneFunctionNotSupportException; } });
30
52
  Object.defineProperty(exports, "ObjectMergeStatusCheckFailedException", { enumerable: true, get: function () { return Errors_1.ObjectMergeStatusCheckFailedException; } });
31
53
  Object.defineProperty(exports, "ObjectDiffApplyInvalidStatusException", { enumerable: true, get: function () { return Errors_1.ObjectDiffApplyInvalidStatusException; } });
32
54
  Object.defineProperty(exports, "ObjectDiffMergeFailedException", { enumerable: true, get: function () { return Errors_1.ObjectDiffMergeFailedException; } });
55
+ /** Area code ↔ string conversion helpers. / 区域码与字符串的转换帮助函数。 */
33
56
  var Language_1 = require("./core/Language");
34
57
  Object.defineProperty(exports, "parseAreaCode", { enumerable: true, get: function () { return Language_1.parseAreaCode; } });
35
58
  Object.defineProperty(exports, "parseAreaString", { enumerable: true, get: function () { return Language_1.parseAreaString; } });
59
+ /** Global log instance and performance tracker. / 全局日志实例和性能跟踪器。 */
36
60
  var Log_1 = require("./core/Log");
37
61
  Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
38
62
  Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return Log_1.Performance; } });
63
+ /** Type conversion helpers. / 类型转换帮助函数。 */
39
64
  var TypeConvertion_1 = require("./core/TypeConvertion");
40
65
  Object.defineProperty(exports, "getBoolean", { enumerable: true, get: function () { return TypeConvertion_1.getBoolean; } });
66
+ /** Runtime environment detection. / 运行时环境检测。 */
41
67
  var Environment_1 = require("./core/Environment");
42
68
  Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return Environment_1.Environment; } });
43
- //// object
69
+ // ─── Object helpers / 对象帮助工具 ───────────────────────────────────────────
70
+ /** Object diff calculation and merge. / 对象差异计算与合并。 */
44
71
  var Calculater_1 = require("./core/object/Calculater");
45
72
  Object.defineProperty(exports, "ObjectCalculater", { enumerable: true, get: function () { return Calculater_1.ObjectCalculater; } });
73
+ /** Deep clone, compare, and serialization validation. / 深度克隆、比较和序列化校验。 */
46
74
  var ObjectHelper_1 = require("./core/object/ObjectHelper");
47
75
  Object.defineProperty(exports, "ObjectHelper", { enumerable: true, get: function () { return ObjectHelper_1.ObjectHelper; } });
76
+ /** Array merge and deduplication. / 数组合并与去重。 */
48
77
  var ArrayHelper_1 = require("./core/object/ArrayHelper");
49
78
  Object.defineProperty(exports, "ArrayHelper", { enumerable: true, get: function () { return ArrayHelper_1.ArrayHelper; } });
79
+ /** String formatting and safe serialization. / 字符串格式化和安全序列化。 */
50
80
  var StringHelper_1 = require("./core/object/StringHelper");
51
81
  Object.defineProperty(exports, "StringHelper", { enumerable: true, get: function () { return StringHelper_1.StringHelper; } });
82
+ /** Random byte buffer generation. / 随机字节缓冲区生成。 */
52
83
  var Bytes_1 = require("./core/object/Bytes");
53
84
  Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return Bytes_1.Bytes; } });
85
+ /** Binary DataView parsing helper. / 二进制 DataView 解析帮助工具。 */
54
86
  var DataView_1 = require("./core/object/DataView");
55
87
  Object.defineProperty(exports, "DataView", { enumerable: true, get: function () { return DataView_1.DataView; } });
88
+ /** Bitwise operations and random integer generation. / 位运算和随机整数生成。 */
56
89
  var Integer_1 = require("./core/object/Integer");
57
90
  Object.defineProperty(exports, "Integer", { enumerable: true, get: function () { return Integer_1.Integer; } });
91
+ /** Safe JSON parsing helpers. / 安全 JSON 解析帮助工具。 */
58
92
  var Json_1 = require("./core/object/Json");
59
93
  Object.defineProperty(exports, "Json", { enumerable: true, get: function () { return Json_1.Json; } });
60
- // security
94
+ // ─── Security utilities / 安全工具 ──────────────────────────────────────────
95
+ /** Base32 encoding/decoding (RFC3548, RFC4648, RFC4648-HEX, Crockford). / Base32 编解码。 */
61
96
  var Base32_1 = require("./security/Base32");
62
97
  Object.defineProperty(exports, "Base32", { enumerable: true, get: function () { return Base32_1.Base32; } });
98
+ /** UUID v4 generation. / UUID v4 生成。 */
63
99
  var Guid_1 = require("./security/Guid");
64
100
  Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
101
+ /** 32-bit string hash code generation. / 32 位字符串哈希码生成。 */
65
102
  var Hash_1 = require("./security/Hash");
66
103
  Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return Hash_1.hash; } });
104
+ /** Async QR code image generation (base64 data URL). / 异步二维码图片生成(base64 data URL)。 */
67
105
  var QRCode_1 = require("./security/QRCode");
68
106
  Object.defineProperty(exports, "QRCode", { enumerable: true, get: function () { return QRCode_1.QRCode; } });
107
+ /** RSA key-pair generation and directional encryption/decryption. / RSA 密钥对生成及方向性加密/解密。 */
69
108
  var RSA_1 = require("./security/RSA");
70
109
  Object.defineProperty(exports, "RSA", { enumerable: true, get: function () { return RSA_1.RSA; } });
110
+ /** SHA-256 / SHA-512 hashing for data and streams. / 数据和流的 SHA-256 / SHA-512 哈希计算。 */
71
111
  var SHA_1 = require("./security/SHA");
72
112
  Object.defineProperty(exports, "SHA", { enumerable: true, get: function () { return SHA_1.SHA; } });
113
+ /** Time-based One-Time Password generation (RFC 6238). / 基于时间的一次性密码生成(RFC 6238)。 */
73
114
  var TOTP_1 = require("./security/TOTP");
74
115
  Object.defineProperty(exports, "TOTP", { enumerable: true, get: function () { return TOTP_1.TOTP; } });
@@ -6,17 +6,24 @@ const Bytes_1 = require("../core/object/Bytes");
6
6
  const DataView_1 = require("../core/object/DataView");
7
7
  const Integer_1 = require("../core/object/Integer");
8
8
  const StringHelper_1 = require("../core/object/StringHelper");
9
- /** Base32 Encoding Lib */
9
+ /**
10
+ * Base32 encoding/decoding utility class.
11
+ * Supports RFC3548, RFC4648, RFC4648-HEX, and Crockford encoding formats.
12
+ *
13
+ * Base32 编解码工具类。
14
+ * 支持 RFC3548、RFC4648、RFC4648-HEX 和 Crockford 编码格式。
15
+ */
10
16
  class Base32 {
11
17
  static RFC4648_CHS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
12
18
  static RFC4648_HEX_CHS = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
13
19
  static CROCKFORD_CHS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
14
20
  /**
15
- * To encode the buffer to be a Base32 encoded string
21
+ * Encode a binary buffer to a Base32 string using the specified encoding format.
22
+ * 使用指定的编码格式将二进制缓冲区编码为 Base32 字符串。
16
23
  *
17
- * @param data input source buffer
18
- * @param encoding encoding type
19
- * @returns return the encoded string
24
+ * @param data the input buffer to encode / 要编码的输入缓冲区
25
+ * @param encoding the Base32 encoding format to use / 要使用的 Base32 编码格式
26
+ * @returns the Base32-encoded string / Base32 编码后的字符串
20
27
  */
21
28
  static encode(data, encoding) {
22
29
  const alphabet = Base32.getAlphabet(encoding);
@@ -48,11 +55,12 @@ class Base32 {
48
55
  return output;
49
56
  }
50
57
  /**
51
- * Decode the input string to be an array buffer
58
+ * Decode a Base32 string back to an ArrayBuffer using the specified encoding format.
59
+ * 使用指定的编码格式将 Base32 字符串解码还原为 ArrayBuffer。
52
60
  *
53
- * @param input source string
54
- * @param encoding encoding type
55
- * @returns return the target array buffer
61
+ * @param input the Base32-encoded source string / Base32 编码的源字符串
62
+ * @param encoding the encoding format used to encode the string / 字符串编码时使用的格式
63
+ * @returns the decoded ArrayBuffer / 解码后的 ArrayBuffer
56
64
  */
57
65
  static decode(input, encoding) {
58
66
  const alphabet = Base32.getAlphabet(encoding);
@@ -73,11 +81,12 @@ class Base32 {
73
81
  return output.buffer;
74
82
  }
75
83
  /**
76
- * Get a random string which is encoded by given encoding type
84
+ * Generate a random Base32-encoded string from cryptographically random bytes.
85
+ * 从密码学安全随机字节生成随机 Base32 编码字符串。
77
86
  *
78
- * @param size random bytes size
79
- * @param encoding encoding type
80
- * @returns return encoded random string
87
+ * @param size the number of random bytes to generate before encoding / 编码前生成的随机字节数
88
+ * @param encoding the encoding format to use, defaults to RFC4648 / 要使用的编码格式,默认为 RFC4648
89
+ * @returns the random Base32-encoded string / 随机 Base32 编码字符串
81
90
  */
82
91
  static random(size, encoding = "RFC4648") {
83
92
  const bytes = Bytes_1.Bytes.random(size);
@@ -7,7 +7,24 @@ const UUID_TEMPLATE = {
7
7
  none: "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx",
8
8
  default: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
9
9
  };
10
- /** Generate a Guid value string */
10
+ /**
11
+ * Generate a UUID v4 string.
12
+ * Uses a combination of the current time and high-resolution performance counter
13
+ * as a random seed to maximise uniqueness.
14
+ *
15
+ * 生成 UUID v4 字符串。
16
+ * 使用当前时间与高精度性能计数器的组合作为随机种子,以最大化唯一性。
17
+ *
18
+ * @param type the output format:
19
+ * - "default" (default) — standard hyphenated form "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
20
+ * - "none" — compact form without hyphens
21
+ *
22
+ * 输出格式:
23
+ * - "default"(默认)—— 标准连字符形式 "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
24
+ * - "none" —— 无连字符的紧凑形式
25
+ *
26
+ * @returns the UUID string / UUID 字符串
27
+ */
11
28
  function guid(type = "default") {
12
29
  let d = new Date().getTime();
13
30
  if (typeof performance === "undefined") {
@@ -3,7 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.hash = void 0;
5
5
  const Integer_1 = require("../core/object/Integer");
6
- /** Generate a hash code number of the string */
6
+ /**
7
+ * Generate a 32-bit integer hash code from the given string.
8
+ * Uses a djb2-style rolling hash algorithm over the character codes.
9
+ *
10
+ * 从给定字符串生成 32 位整数哈希码。
11
+ * 使用基于字符码的 djb2 风格滚动哈希算法。
12
+ *
13
+ * @param source the input string / 输入字符串
14
+ * @returns a 32-bit integer hash code / 32 位整数哈希码
15
+ */
7
16
  function hash(source) {
8
17
  let length = source.length;
9
18
  let hashCode = 0;
@@ -26,13 +26,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.QRCode = void 0;
28
28
  const qrcode = __importStar(require("qrcode"));
29
- /** QR code Lib */
29
+ /**
30
+ * QR code generation utility class.
31
+ * Wraps the `qrcode` library to provide an async base64 data-URL API.
32
+ *
33
+ * 二维码生成工具类。
34
+ * 封装 `qrcode` 库,提供异步 base64 data-URL 接口。
35
+ */
30
36
  class QRCode {
31
37
  /**
32
- * Async getting a base64 URL of given text
38
+ * Asynchronously generate a base64-encoded PNG data URL for the given text.
39
+ * The returned data URL can be used directly as an `<img src="...">` attribute.
40
+ * Returns an empty string if QR code generation fails.
33
41
  *
34
- * @param text source text
35
- * @returns return base64 URL string
42
+ * 异步为给定文本生成 base64 编码的 PNG data URL。
43
+ * 返回的 data URL 可直接用作 `<img src="...">` 属性值。
44
+ * 若二维码生成失败则返回空字符串。
45
+ *
46
+ * @param text the text or URL to encode into the QR code / 要编码为二维码的文本或 URL
47
+ * @returns a Promise that resolves to the base64 data URL, or "" on error / 解析为 base64 data URL 的 Promise,出错时为 ""
36
48
  */
37
49
  static async getURL(text) {
38
50
  return new Promise((resolve) => {
@@ -3,13 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.RSA = void 0;
5
5
  const crypto_1 = require("crypto");
6
- /** RSA Lib */
6
+ /**
7
+ * RSA encryption/decryption utility class.
8
+ * Provides key-pair generation and four directional encryption operations
9
+ * (public→private, private→public, and their reverses).
10
+ *
11
+ * RSA 加密/解密工具类。
12
+ * 提供密钥对生成及四种方向的加密操作
13
+ * (公钥→私钥、私钥→公钥,及各自的反向解密)。
14
+ */
7
15
  class RSA {
8
16
  /**
9
- * To get a new RSA public key and private key
17
+ * Generate a new RSA public/private key pair.
18
+ * 生成新的 RSA 公私密钥对。
10
19
  *
11
- * @param options RSA key generation option
12
- * @returns return new RSA key
20
+ * @param options RSA key generation options (modulus length, format, etc.) / RSA 密钥生成选项(模数长度、格式等)
21
+ * @returns an object containing the generated private and public keys / 包含生成的私钥和公钥的对象
13
22
  */
14
23
  static new(options) {
15
24
  const { publicKey, privateKey } = (0, crypto_1.generateKeyPairSync)("rsa", options);
@@ -19,41 +28,45 @@ class RSA {
19
28
  };
20
29
  }
21
30
  /**
22
- * To encode a value with public key, the encoded data can be decoded by private key
31
+ * Encrypt data using the public key (decryptable with the private key).
32
+ * 使用公钥加密数据(可用私钥解密)。
23
33
  *
24
- * @param data input data
25
- * @param publicKey encoding public key
26
- * @returns return encoded buffer
34
+ * @param data the plaintext data to encrypt / 要加密的明文数据
35
+ * @param publicKey the RSA public key / RSA 公钥
36
+ * @returns the encrypted Buffer / 加密后的 Buffer
27
37
  */
28
38
  static encodepub(data, publicKey) {
29
39
  return (0, crypto_1.publicEncrypt)(publicKey, data);
30
40
  }
31
41
  /**
32
- * To encode a value with private key, the encoded data can be decoded by public key
42
+ * Encrypt data using the private key (decryptable with the public key).
43
+ * 使用私钥加密数据(可用公钥解密)。
33
44
  *
34
- * @param data input data
35
- * @param publicKey encoding private key
36
- * @returns return encoded buffer
45
+ * @param data the plaintext data to encrypt / 要加密的明文数据
46
+ * @param privateKey the RSA private key / RSA 私钥
47
+ * @returns the encrypted Buffer / 加密后的 Buffer
37
48
  */
38
49
  static encodepri(data, privateKey) {
39
50
  return (0, crypto_1.privateEncrypt)(privateKey, data);
40
51
  }
41
52
  /**
42
- * To decode a value with public key, the value is encoded by private key
53
+ * Decrypt data using the public key (data was encrypted with the private key).
54
+ * 使用公钥解密数据(数据由私钥加密)。
43
55
  *
44
- * @param data input data
45
- * @param publicKey decoding public key
46
- * @returns return decoded buffer
56
+ * @param data the encrypted data / 加密后的数据
57
+ * @param publicKey the RSA public key / RSA 公钥
58
+ * @returns the decrypted Buffer / 解密后的 Buffer
47
59
  */
48
60
  static decodepub(data, publicKey) {
49
61
  return (0, crypto_1.publicDecrypt)(publicKey, data);
50
62
  }
51
63
  /**
52
- * To decode a value with private key, the value is encoded by public key
64
+ * Decrypt data using the private key (data was encrypted with the public key).
65
+ * 使用私钥解密数据(数据由公钥加密)。
53
66
  *
54
- * @param data input data
55
- * @param privateKey decoding private key
56
- * @returns return decoded buffer
67
+ * @param data the encrypted data / 加密后的数据
68
+ * @param privateKey the RSA private key / RSA 私钥
69
+ * @returns the decrypted Buffer / 解密后的 Buffer
57
70
  */
58
71
  static decodepri(data, privateKey) {
59
72
  return (0, crypto_1.privateDecrypt)(privateKey, data);
@@ -6,24 +6,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SHA = void 0;
8
8
  const crypto_1 = __importDefault(require("crypto"));
9
- /** SHA Lib */
9
+ /**
10
+ * SHA hash utility class.
11
+ * Provides SHA-256 and SHA-512 hashing for both buffer/string data and Node.js streams.
12
+ *
13
+ * SHA 哈希工具类。
14
+ * 为缓冲区/字符串数据和 Node.js 流提供 SHA-256 和 SHA-512 哈希计算。
15
+ */
10
16
  class SHA {
11
17
  /**
12
- * Calculate SHA256 code of data based on specified string encoding.
18
+ * Calculate the SHA-256 hash of string or Buffer data.
19
+ * 计算字符串或 Buffer 数据的 SHA-256 哈希值。
13
20
  *
14
- * @param data source data
15
- * @param encoding string encoding type, default encoding type is 'utf-8', only used when data type is string
16
- * @returns return the SHA256 code buffer
21
+ * @param data the source data / 源数据
22
+ * @param encoding string encoding used when `data` is a string; defaults to "utf-8" / `data` 为字符串时使用的字符串编码,默认为 "utf-8"
23
+ * @returns the SHA-256 digest as a Buffer / SHA-256 摘要 Buffer
17
24
  */
18
25
  static sha256(data, encoding = "utf-8") {
19
26
  return SHA.sha("sha256", data, encoding);
20
27
  }
21
28
  /**
22
- * Calculate SHA512 code of data based on specified string encoding.
29
+ * Calculate the SHA-512 hash of string or Buffer data.
30
+ * 计算字符串或 Buffer 数据的 SHA-512 哈希值。
23
31
  *
24
- * @param data source data
25
- * @param encoding string encoding type, default encoding type is 'utf-8', only used when data type is string
26
- * @returns return the SHA256 code buffer
32
+ * @param data the source data / 源数据
33
+ * @param encoding string encoding used when `data` is a string; defaults to "utf-8" / `data` 为字符串时使用的字符串编码,默认为 "utf-8"
34
+ * @returns the SHA-512 digest as a Buffer / SHA-512 摘要 Buffer
27
35
  */
28
36
  static sha512(data, encoding = "utf-8") {
29
37
  return SHA.sha("sha512", data, encoding);
@@ -35,19 +43,21 @@ class SHA {
35
43
  return hash.digest();
36
44
  }
37
45
  /**
38
- * Calculate SHA256 code of data based on a stream
46
+ * Calculate the SHA-256 hash of data provided via a Node.js readable stream.
47
+ * 通过 Node.js 可读流提供的数据计算 SHA-256 哈希值。
39
48
  *
40
- * @param stream data stream
41
- * @returns return the encoded buffer
49
+ * @param stream the readable data stream / 可读数据流
50
+ * @returns a Promise that resolves to the SHA-256 digest Buffer / 解析为 SHA-256 摘要 Buffer 的 Promise
42
51
  */
43
52
  static async stream256(stream) {
44
53
  return SHA.streamSHA("sha256", stream);
45
54
  }
46
55
  /**
47
- * Calculate SHA512 code of data based on a stream
56
+ * Calculate the SHA-512 hash of data provided via a Node.js readable stream.
57
+ * 通过 Node.js 可读流提供的数据计算 SHA-512 哈希值。
48
58
  *
49
- * @param stream data stream
50
- * @returns return the encoded buffer
59
+ * @param stream the readable data stream / 可读数据流
60
+ * @returns a Promise that resolves to the SHA-512 digest Buffer / 解析为 SHA-512 摘要 Buffer 的 Promise
51
61
  */
52
62
  static async stream512(stream) {
53
63
  return SHA.streamSHA("sha512", stream);
@@ -9,21 +9,38 @@ const crypto_1 = __importDefault(require("crypto"));
9
9
  const Integer_1 = require("../core/object/Integer");
10
10
  const DataView_1 = require("../core/object/DataView");
11
11
  const Base32_1 = require("./Base32");
12
- /** TOTP Lib */
12
+ /**
13
+ * Time-based One-Time Password (TOTP) utility class.
14
+ * Implements the TOTP algorithm as defined in RFC 6238.
15
+ * Compatible with standard authenticator apps (Google Authenticator, Authy, etc.).
16
+ *
17
+ * 基于时间的一次性密码(TOTP)工具类。
18
+ * 实现 RFC 6238 定义的 TOTP 算法。
19
+ * 与标准认证器应用(Google Authenticator、Authy 等)兼容。
20
+ */
13
21
  class TOTP {
14
22
  /**
15
- * To generate a new TOTP secret key
23
+ * Generate a new TOTP secret key encoded in Base32 (RFC4648).
24
+ * The returned key should be stored securely and associated with a user account.
16
25
  *
17
- * @returns TOTP secret key
26
+ * 生成一个以 Base32(RFC4648)编码的新 TOTP 密钥。
27
+ * 返回的密钥应安全存储并与用户账户关联。
28
+ *
29
+ * @returns a Base32-encoded secret key string / Base32 编码的密钥字符串
18
30
  */
19
31
  static generate() {
20
32
  return Base32_1.Base32.random(20);
21
33
  }
22
34
  /**
23
- * Generate TOTP random code
35
+ * Generate the 6-digit TOTP code for the given secret key and time window.
36
+ * The default time window is the current 30-second interval (standard TOTP).
37
+ *
38
+ * 为给定密钥和时间窗口生成 6 位 TOTP 验证码。
39
+ * 默认时间窗口为当前的 30 秒间隔(标准 TOTP)。
24
40
  *
25
- * @param key TOTP secret key
26
- * @returns return TOTP random code
41
+ * @param key the Base32-encoded secret key / Base32 编码的密钥
42
+ * @param time optional Unix timestamp in milliseconds; defaults to Date.now() / 可选的 Unix 时间戳(毫秒),默认为 Date.now()
43
+ * @returns a 6-digit OTP string / 6 位一次性密码字符串
27
44
  */
28
45
  static code(key, time) {
29
46
  const K = Base32_1.Base32.decode(key.toUpperCase(), "RFC4648");
@@ -41,10 +58,15 @@ class TOTP {
41
58
  return code;
42
59
  }
43
60
  /**
44
- * Generate a key and TOTP register URL from given user
61
+ * Generate a new TOTP secret and the corresponding otpauth:// URI for QR code scanning.
62
+ * The URI can be rendered as a QR code so users can add the account to an authenticator app.
63
+ *
64
+ * 生成新的 TOTP 密钥及对应的 otpauth:// URI,用于二维码扫描。
65
+ * 该 URI 可渲染为二维码,方便用户将账户添加到认证器应用。
45
66
  *
46
- * @param user user name
47
- * @returns return the secret key and url
67
+ * @param user the account username or email / 账户用户名或邮箱
68
+ * @param project the issuer / service name shown in the authenticator app / 显示在认证器应用中的发行方/服务名称
69
+ * @returns an object containing the secret key and the otpauth:// URL / 包含密钥和 otpauth:// URL 的对象
48
70
  */
49
71
  static getUrl(user, project = "tianyu-template-project") {
50
72
  const key = TOTP.generate();