@@ -34,6 +34,13 @@ export const underlineToHump = (str: string): string => {
34
34
} )
35
35
}
36
36
37
+ /**
38
+ * 驼峰转横杠
39
+ */
40
+ export const humpToDash = ( str : string ) : string => {
41
+ return str . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( )
42
+ }
43
+
37
44
export const setCssVar = ( prop : string , val : any , dom = document . documentElement ) => {
38
45
dom . style . setProperty ( prop , val )
39
46
}
@@ -67,7 +74,7 @@ export const trim = (str: string) => {
67
74
* @param {Date | number | string } time 需要转换的时间
68
75
* @param {String } fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss
69
76
*/
70
- export const formatTime = ( time : Date | number | string , fmt : string ) => {
77
+ export function formatTime ( time : Date | number | string , fmt : string ) {
71
78
if ( ! time ) return ''
72
79
else {
73
80
const date = new Date ( time )
@@ -98,7 +105,7 @@ export const formatTime = (time: Date | number | string, fmt: string) => {
98
105
/**
99
106
* 生成随机字符串
100
107
*/
101
- export const toAnyString = ( ) => {
108
+ export function toAnyString ( ) {
102
109
const str : string = 'xxxxx-xxxxx-4xxxx-yxxxx-xxxxx' . replace ( / [ x y ] / g, ( c : string ) => {
103
110
const r : number = ( Math . random ( ) * 16 ) | 0
104
111
const v : number = c === 'x' ? r : ( r & 0x3 ) | 0x8
@@ -107,6 +114,13 @@ export const toAnyString = () => {
107
114
return str
108
115
}
109
116
117
+ /**
118
+ * 首字母大写
119
+ */
120
+ export function firstUpperCase ( str : string ) {
121
+ return str . toLowerCase ( ) . replace ( / ( | ^ ) [ a - z ] / g, ( L ) => L . toUpperCase ( ) )
122
+ }
123
+
110
124
export const generateUUID = ( ) => {
111
125
if ( typeof crypto === 'object' ) {
112
126
if ( typeof crypto . randomUUID === 'function' ) {
0 commit comments