@kilnonedre/foundation 0.0.14 → 0.0.15

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/dist/index.d.ts CHANGED
@@ -472,7 +472,22 @@ declare const isValidEmail: (string: string) => boolean;
472
472
 
473
473
  declare const isValidURL: (string: string) => boolean;
474
474
 
475
- declare const emptyToUndefined: (value: unknown) => unknown;
475
+ /**
476
+ * 将空字符串转换为 undefined。
477
+ *
478
+ * 常用于 Zod 的 preprocess 场景,避免用户输入空字符串时被视为有效值。
479
+ *
480
+ * 示例:
481
+ * - '' => undefined
482
+ * - ' ' => undefined
483
+ * - 'hello' => 'hello'
484
+ * - null => undefined
485
+ * - 123 => undefined
486
+ *
487
+ * @param value 待处理的值
488
+ * @returns 去除首尾空格后的字符串,若为空则返回 undefined
489
+ */
490
+ declare const emptyToUndefined: (value: unknown) => string | undefined;
476
491
  declare const enumValues: <T extends Record<string, string>>(obj: T) => [T[keyof T], ...T[keyof T][]];
477
492
  declare const zTextOptional: (label: string, min?: number, max?: number) => z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
478
493
  declare const zTextRequired: (label: string, min?: number, max?: number) => z.ZodString;
package/dist/index.js CHANGED
@@ -512,9 +512,11 @@ var isValidURL = (string) => {
512
512
  // src/util/validator/schema.ts
513
513
  import { z } from "zod";
514
514
  var emptyToUndefined = (value) => {
515
- if (typeof value !== "string") return value;
515
+ if (typeof value !== "string") {
516
+ return void 0;
517
+ }
516
518
  const v = value.trim();
517
- return v ? v : void 0;
519
+ return v || void 0;
518
520
  };
519
521
  var enumValues = (obj) => Object.values(obj);
520
522
  var zTextOptional = (label, min = 1, max = 32) => z.preprocess(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kilnonedre/foundation",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "private": false,
5
5
  "description": "Kilnonedre frontend foundation package",
6
6
  "type": "module",