-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.ts
45 lines (41 loc) · 1.06 KB
/
common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { isEmpty } from "lodash-es";
export * from "lodash-es";
/**
* 判断值是否为空
* @function isNotEmpty
*
* @param {any} value 值
* @returns {boolean} 是否为空
*
* @example
* const str = null;
* const isNull = isNotEmpty(str);
* console.log('是否不为空', isNull);
*/
export const isNotEmpty = (value: any): boolean => !isEmpty(value);
/**
* 驼峰转横线
* @function humpToLine
*
* @param {string} str 字符,默认为""
* @returns {string} 转换后的字符
*
* @example
* const str = "helloWorld";
* cosnt newStr = humpToLine(str);
* console.log('转换后', newStr);
*/
export const humpToLine = (str = ""): string => str.replace(/\B([A-Z])/g, "-$1").toLowerCase();
/**
* 横线转驼峰
* @function lineToHump
*
* @param {string} str 字符,默认为""
* @returns {string} 转换后的字符
*
* @example
* const str = "hello-world";
* cosnt newStr = lineToHump(str);
* console.log('转换后', newStr);
*/
export const lineToHump = (str = ""): string => str.replace(/-(\w)/g, (all, letter) => letter.toUpperCase());