ph-utils 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
package/lib/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * 验证字符串是否为空
3
- * @param str 待验证的字符串
4
- * @param ignoreWhitespace 是否忽略空格(包括空白字符串以及[\r\t\n]之类的制表符),默认为true
2
+ * 验证参数是否为空
3
+ * @param str 待验证的参数
4
+ * @param ignoreWhitespace 如果是字符串是否忽略空格(包括空白字符串以及[\r\t\n]之类的制表符),默认为true
5
5
  */
6
- export declare function isBlank(str?: string | null, ignoreWhitespace?: boolean): boolean;
6
+ export declare function isBlank(str?: any, ignoreWhitespace?: boolean): boolean;
7
7
  /**
8
8
  * 屏蔽手机号,中间部分用 * 展示
9
9
  * @param mobile 待屏蔽的手机号
package/lib/index.js CHANGED
@@ -6,15 +6,17 @@ const RANDOM_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345
6
6
  /** 只包含字母的随机数字符 */
7
7
  const NUMBER_RANDOM_CHARTS = "0123456789";
8
8
  /**
9
- * 验证字符串是否为空
10
- * @param str 待验证的字符串
11
- * @param ignoreWhitespace 是否忽略空格(包括空白字符串以及[\r\t\n]之类的制表符),默认为true
9
+ * 验证参数是否为空
10
+ * @param str 待验证的参数
11
+ * @param ignoreWhitespace 如果是字符串是否忽略空格(包括空白字符串以及[\r\t\n]之类的制表符),默认为true
12
12
  */
13
13
  export function isBlank(str, ignoreWhitespace = true) {
14
14
  if (str == null) {
15
15
  return true;
16
16
  }
17
- return (ignoreWhitespace ? str.trim().length : str.length) === 0;
17
+ return ((ignoreWhitespace && typeof str === "string"
18
+ ? str.trim().length
19
+ : str.length) === 0);
18
20
  }
19
21
  /**
20
22
  * 屏蔽手机号,中间部分用 * 展示
package/lib/theme.d.ts CHANGED
@@ -4,13 +4,13 @@ export declare function getSystemTheme(): "dark" | "light" | "auto";
4
4
  * 初始化主题, 让网页能够适应系统主题, 同时根据缓存的主题切换主题
5
5
  * @returns 当前应用的主题
6
6
  */
7
- export declare function initTheme(): Promise<"dark" | "light" | "auto" | undefined>;
7
+ export declare function initTheme(): Promise<"dark" | "light" | "auto">;
8
8
  /**
9
9
  * 切换主题, 通常用于预览
10
10
  * @param theme 切换的主题
11
11
  * @returns 切换后的主题
12
12
  */
13
- export declare function toggleTheme(theme?: "light" | "dark" | "auto"): Promise<"dark" | "light" | "auto" | undefined>;
13
+ export declare function toggleTheme(theme?: "light" | "dark" | "auto"): Promise<"dark" | "light" | "auto">;
14
14
  /** 获取当前主题 */
15
15
  export declare function getTheme(): string;
16
16
  /**
@@ -19,7 +19,7 @@ export declare function getTheme(): string;
19
19
  * @param cache 是否缓存应用的主题, 让应用下一次启动的时候, 可以应用主题, 默认: true
20
20
  * @returns 应用的主题
21
21
  */
22
- export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<"dark" | "light" | "auto" | undefined>;
22
+ export declare function applyTheme(theme?: "light" | "dark" | "auto", cache?: boolean): Promise<"dark" | "light" | "auto">;
23
23
  /** 获取当前主题色 */
24
24
  export declare function getColorTheme(defaultValue?: string): string | undefined;
25
25
  /**
package/lib/theme.js CHANGED
@@ -37,6 +37,9 @@ export async function initTheme() {
37
37
  */
38
38
  export async function toggleTheme(theme) {
39
39
  const classList = document.documentElement.classList;
40
+ if (theme == null) {
41
+ theme = getSystemTheme();
42
+ }
40
43
  if (theme === "light") {
41
44
  classList.add("light");
42
45
  classList.remove("dark");
@@ -26,7 +26,20 @@ declare class Validator {
26
26
  };
27
27
  /**
28
28
  * 构造数据验证转换器
29
+ *
30
+ * See {@link https://gitee.com/towardly/ph/wikis/utils/validator|Validator文档}.
31
+ *
29
32
  * @param schemas 配置验证转换规则
33
+ *
34
+ * @example
35
+ *
36
+ * const validator = new Validator([
37
+ * { key: 'mobile', rules: ['required', 'mobile'] },
38
+ * { key: 'code': rules: /^\d{6}$/, message: '请输入正确的验证码' },
39
+ * { key: 'confirmPassword', rules: ['required', 'same:password'] }
40
+ * ])
41
+ * // 验证某一个字段
42
+ * validator.validateKey().then(res => {})
30
43
  */
31
44
  constructor(schemas: SchemaType[]);
32
45
  /**
package/lib/validator.js CHANGED
@@ -47,7 +47,20 @@ class Validator {
47
47
  rules;
48
48
  /**
49
49
  * 构造数据验证转换器
50
+ *
51
+ * See {@link https://gitee.com/towardly/ph/wikis/utils/validator|Validator文档}.
52
+ *
50
53
  * @param schemas 配置验证转换规则
54
+ *
55
+ * @example
56
+ *
57
+ * const validator = new Validator([
58
+ * { key: 'mobile', rules: ['required', 'mobile'] },
59
+ * { key: 'code': rules: /^\d{6}$/, message: '请输入正确的验证码' },
60
+ * { key: 'confirmPassword', rules: ['required', 'same:password'] }
61
+ * ])
62
+ * // 验证某一个字段
63
+ * validator.validateKey().then(res => {})
51
64
  */
52
65
  constructor(schemas) {
53
66
  let parsedRules = {};
package/package.json CHANGED
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "./*": "./lib/*"
66
66
  },
67
- "version": "0.9.3",
67
+ "version": "0.9.4",
68
68
  "type": "module",
69
69
  "repository": {
70
70
  "type": "git",