@pawover/kit 0.1.0 → 0.2.0

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.
@@ -26,7 +26,7 @@ declare class ArrayUtil {
26
26
  * ```
27
27
  */
28
28
  static cast<T>(candidate: T | T[] | null | undefined, checkEmpty?: true): NonNullable<T>[];
29
- static cast<T>(candidate: T | T[] | null | undefined, checkEmpty?: false): T[];
29
+ static cast<T>(candidate: T | T[] | null | undefined, checkEmpty: false): T[];
30
30
  /**
31
31
  * 获取数组第一项
32
32
  *
@@ -3717,6 +3717,39 @@ declare class ObjectUtil {
3717
3717
  * 字符串工具类
3718
3718
  */
3719
3719
  declare class StringUtil {
3720
+ /**
3721
+ * 将任意值转换为字符串
3722
+ * - 当传入数值字面量时,返回对应的字符串字面量类型
3723
+ *
3724
+ * @param candidate 待转换的值
3725
+ * @param checkEmpty 是否检查空值(`null` / `undefined` / 空白字符串),默认为 `true`
3726
+ * @returns 转换后的字符串
3727
+ * @example
3728
+ * ```ts
3729
+ * // 重载 1: null / undefined + checkEmpty = true (默认) → ""
3730
+ * StringUtil.cast(null); // ""
3731
+ * StringUtil.cast(undefined); // ""
3732
+ * StringUtil.cast(""); // ""
3733
+ * StringUtil.cast(" "); // ""
3734
+ *
3735
+ * // 重载 2: null / undefined + checkEmpty = false → "null" / "undefined"
3736
+ * StringUtil.cast(null, false); // "null" (类型为 "null")
3737
+ * StringUtil.cast(undefined, false); // "undefined" (类型为 "undefined")
3738
+ *
3739
+ * // 重载 3: 原始类型 → 字符串字面量类型
3740
+ * StringUtil.cast(123); // "123" (类型为 "123")
3741
+ * StringUtil.cast("hello"); // "hello" (类型为 "hello")
3742
+ * StringUtil.cast(true); // "true" (类型为 "true")
3743
+ * StringUtil.cast(42n); // "42" (类型为 "42")
3744
+ *
3745
+ * // 重载 4: 其他类型 → string
3746
+ * StringUtil.cast(Symbol("foo")); // "Symbol(foo)" (类型为 string)
3747
+ * ```
3748
+ */
3749
+ static cast<T extends null | undefined>(candidate: T, checkEmpty?: true): "";
3750
+ static cast<T extends null | undefined>(candidate: T, checkEmpty: false): `${T}`;
3751
+ static cast<T extends string | number | bigint | boolean>(candidate: T, checkEmpty?: boolean): `${T}`;
3752
+ static cast(candidate: unknown, checkEmpty?: boolean): string;
3720
3753
  /**
3721
3754
  * 从字符串中提取数字字符串
3722
3755
  * - 移除非数字字符,保留符号和小数点
@@ -4102,15 +4135,18 @@ declare class TypeUtil {
4102
4135
  private static isConstructable;
4103
4136
  /**
4104
4137
  * 检查 value 是否为 string 类型
4138
+ * - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
4105
4139
  *
4106
4140
  * @param value 待检查值
4107
- * @param checkEmpty 是否检查空字符串
4141
+ * @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
4108
4142
  * @returns 是否为字符串
4109
4143
  * @example
4110
4144
  * ```ts
4111
4145
  * TypeUtil.isString("abc"); // true
4112
4146
  * TypeUtil.isString(""); // true
4113
4147
  * TypeUtil.isString("", true); // false
4148
+ * TypeUtil.isString(" ", true); // false
4149
+ * TypeUtil.isString(" a ", true); // true
4114
4150
  * ```
4115
4151
  */
4116
4152
  static isString(value: unknown, checkEmpty?: boolean): value is string;
@@ -4322,18 +4358,19 @@ declare class TypeUtil {
4322
4358
  *
4323
4359
  * @param value 待检查值
4324
4360
  * @param prototypeCheck 是否进行原型检查,默认 `true`
4325
- * @returns 是否为 Plain Object (当 checkPrototype=true) 或 object
4361
+ * @returns 是否为 Plain Object (当 prototypeCheck=true) 或 object
4326
4362
  * @example
4327
4363
  * ```ts
4328
- * TypeUtil.isObject({}); // true
4329
- * TypeUtil.isObject([]); // false
4330
- * TypeUtil.isObject(new Date()); // false
4331
- * TypeUtil.isObject(new Date(), false); // true
4332
- * TypeUtil.isObject(Object.create(null)) // false
4333
- * TypeUtil.isObject(Object.create(null), false) // true
4364
+ * TypeUtil.isPlainObject({}); // true
4365
+ * TypeUtil.isPlainObject([]); // false
4366
+ * TypeUtil.isPlainObject(new Date()); // false
4367
+ * TypeUtil.isPlainObject(new (class {})()); // false
4368
+ * TypeUtil.isPlainObject(new (class {})(), false); // true
4369
+ * TypeUtil.isPlainObject(Object.create(null)) // false
4370
+ * TypeUtil.isPlainObject(Object.create(null), false) // true
4334
4371
  * ```
4335
4372
  */
4336
- static isObject(value: unknown, prototypeCheck?: boolean): value is Record<PropertyKey, unknown>;
4373
+ static isPlainObject(value: unknown, prototypeCheck?: boolean): value is Record<PropertyKey, unknown>;
4337
4374
  /**
4338
4375
  * 判断一个对象是否为有效的枚举
4339
4376
  * - 枚举成员不能为空