@pawover/kit 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "description": "一个基于 TypeScript 的开发工具包",
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.1.0",
11
+ "version": "0.1.1",
12
12
  "engines": {
13
13
  "node": ">=22.20.0"
14
14
  },
@@ -53,7 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@commitlint/cli": "^21.0.2",
55
55
  "@commitlint/config-conventional": "^21.0.2",
56
- "@eslint-react/eslint-plugin": "^5.8.9",
56
+ "@eslint-react/eslint-plugin": "^5.8.11",
57
57
  "@pawover/eslint-rules": "^0.2.0",
58
58
  "@playwright/test": "^1.60.0",
59
59
  "@stylistic/eslint-plugin": "^5.10.0",
@@ -11,7 +11,7 @@ function useLatest(value) {
11
11
  return ref;
12
12
  }
13
13
  //#endregion
14
- //#region ../utils/dist/string-C_OCj9Lg.js
14
+ //#region ../utils/dist/string-p6hZ1Mjb.js
15
15
  function _typeof(o) {
16
16
  "@babel/helpers - typeof";
17
17
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -65,19 +65,22 @@ var TypeUtil = class {
65
65
  }
66
66
  /**
67
67
  * 检查 value 是否为 string 类型
68
+ * - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
68
69
  *
69
70
  * @param value 待检查值
70
- * @param checkEmpty 是否检查空字符串
71
+ * @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
71
72
  * @returns 是否为字符串
72
73
  * @example
73
74
  * ```ts
74
75
  * TypeUtil.isString("abc"); // true
75
76
  * TypeUtil.isString(""); // true
76
77
  * TypeUtil.isString("", true); // false
78
+ * TypeUtil.isString(" ", true); // false
79
+ * TypeUtil.isString(" a ", true); // true
77
80
  * ```
78
81
  */
79
82
  static isString(value, checkEmpty = false) {
80
- return typeof value === "string" && (!checkEmpty || !!value.length);
83
+ return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
81
84
  }
82
85
  /**
83
86
  * 检查 value 是否为 number 类型
@@ -741,6 +744,13 @@ _defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
741
744
  * 字符串工具类
742
745
  */
743
746
  var StringUtil = class {
747
+ static cast(candidate, checkEmpty = true) {
748
+ if (checkEmpty) {
749
+ if (candidate === null || candidate === void 0) return "";
750
+ if (typeof candidate === "string" && candidate.trim().length === 0) return "";
751
+ }
752
+ return String(candidate);
753
+ }
744
754
  /**
745
755
  * 从字符串中提取数字字符串
746
756
  * - 移除非数字字符,保留符号和小数点
@@ -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;
@@ -1,4 +1,4 @@
1
- import { n as TypeUtil, r as _defineProperty, t as StringUtil } from "./string-C_OCj9Lg.js";
1
+ import { n as TypeUtil, r as _defineProperty, t as StringUtil } from "./string-p6hZ1Mjb.js";
2
2
  //#region src/array/arrayUtil.ts
3
3
  /**
4
4
  * 数组工具类
@@ -1,4 +1,4 @@
1
- import { n as TypeUtil, t as StringUtil } from "./string-C_OCj9Lg.js";
1
+ import { n as TypeUtil, t as StringUtil } from "./string-p6hZ1Mjb.js";
2
2
  //#region src/math/mathUtil.ts
3
3
  /**
4
4
  * 数学工具类
@@ -60,19 +60,22 @@ var TypeUtil = class {
60
60
  }
61
61
  /**
62
62
  * 检查 value 是否为 string 类型
63
+ * - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
63
64
  *
64
65
  * @param value 待检查值
65
- * @param checkEmpty 是否检查空字符串
66
+ * @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
66
67
  * @returns 是否为字符串
67
68
  * @example
68
69
  * ```ts
69
70
  * TypeUtil.isString("abc"); // true
70
71
  * TypeUtil.isString(""); // true
71
72
  * TypeUtil.isString("", true); // false
73
+ * TypeUtil.isString(" ", true); // false
74
+ * TypeUtil.isString(" a ", true); // true
72
75
  * ```
73
76
  */
74
77
  static isString(value, checkEmpty = false) {
75
- return typeof value === "string" && (!checkEmpty || !!value.length);
78
+ return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
76
79
  }
77
80
  /**
78
81
  * 检查 value 是否为 number 类型
@@ -738,6 +741,13 @@ _defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
738
741
  * 字符串工具类
739
742
  */
740
743
  var StringUtil = class {
744
+ static cast(candidate, checkEmpty = true) {
745
+ if (checkEmpty) {
746
+ if (candidate === null || candidate === void 0) return "";
747
+ if (typeof candidate === "string" && candidate.trim().length === 0) return "";
748
+ }
749
+ return String(candidate);
750
+ }
741
751
  /**
742
752
  * 从字符串中提取数字字符串
743
753
  * - 移除非数字字符,保留符号和小数点