Skip to content

Commit 80e72fd

Browse files
committed
feat: coding
1 parent 2a029ba commit 80e72fd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/utils/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export const underlineToHump = (str: string): string => {
3434
})
3535
}
3636

37+
/**
38+
* 驼峰转横杠
39+
*/
40+
export const humpToDash = (str: string): string => {
41+
return str.replace(/([A-Z])/g, '-$1').toLowerCase()
42+
}
43+
3744
export const setCssVar = (prop: string, val: any, dom = document.documentElement) => {
3845
dom.style.setProperty(prop, val)
3946
}
@@ -67,7 +74,7 @@ export const trim = (str: string) => {
6774
* @param {Date | number | string} time 需要转换的时间
6875
* @param {String} fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss
6976
*/
70-
export const formatTime = (time: Date | number | string, fmt: string) => {
77+
export function formatTime(time: Date | number | string, fmt: string) {
7178
if (!time) return ''
7279
else {
7380
const date = new Date(time)
@@ -98,7 +105,7 @@ export const formatTime = (time: Date | number | string, fmt: string) => {
98105
/**
99106
* 生成随机字符串
100107
*/
101-
export const toAnyString = () => {
108+
export function toAnyString() {
102109
const str: string = 'xxxxx-xxxxx-4xxxx-yxxxx-xxxxx'.replace(/[xy]/g, (c: string) => {
103110
const r: number = (Math.random() * 16) | 0
104111
const v: number = c === 'x' ? r : (r & 0x3) | 0x8
@@ -107,6 +114,13 @@ export const toAnyString = () => {
107114
return str
108115
}
109116

117+
/**
118+
* 首字母大写
119+
*/
120+
export function firstUpperCase(str: string) {
121+
return str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase())
122+
}
123+
110124
export const generateUUID = () => {
111125
if (typeof crypto === 'object') {
112126
if (typeof crypto.randomUUID === 'function') {

0 commit comments

Comments
 (0)