Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
80e72fd9
authored
Oct 31, 2023
by
xingyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: coding
parent
2a029ba3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
src/utils/index.ts
+16
-2
No files found.
src/utils/index.ts
View file @
80e72fd9
...
...
@@ -34,6 +34,13 @@ export const underlineToHump = (str: string): string => {
})
}
/**
* 驼峰转横杠
*/
export
const
humpToDash
=
(
str
:
string
):
string
=>
{
return
str
.
replace
(
/
([
A-Z
])
/g
,
'-$1'
).
toLowerCase
()
}
export
const
setCssVar
=
(
prop
:
string
,
val
:
any
,
dom
=
document
.
documentElement
)
=>
{
dom
.
style
.
setProperty
(
prop
,
val
)
}
...
...
@@ -67,7 +74,7 @@ export const trim = (str: string) => {
* @param {Date | number | string} time 需要转换的时间
* @param {String} fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss
*/
export
const
formatTime
=
(
time
:
Date
|
number
|
string
,
fmt
:
string
)
=>
{
export
function
formatTime
(
time
:
Date
|
number
|
string
,
fmt
:
string
)
{
if
(
!
time
)
return
''
else
{
const
date
=
new
Date
(
time
)
...
...
@@ -98,7 +105,7 @@ export const formatTime = (time: Date | number | string, fmt: string) => {
/**
* 生成随机字符串
*/
export
const
toAnyString
=
()
=>
{
export
function
toAnyString
()
{
const
str
:
string
=
'xxxxx-xxxxx-4xxxx-yxxxx-xxxxx'
.
replace
(
/
[
xy
]
/g
,
(
c
:
string
)
=>
{
const
r
:
number
=
(
Math
.
random
()
*
16
)
|
0
const
v
:
number
=
c
===
'x'
?
r
:
(
r
&
0x3
)
|
0x8
...
...
@@ -107,6 +114,13 @@ export const toAnyString = () => {
return
str
}
/**
* 首字母大写
*/
export
function
firstUpperCase
(
str
:
string
)
{
return
str
.
toLowerCase
().
replace
(
/
(
|^
)[
a-z
]
/g
,
(
L
)
=>
L
.
toUpperCase
())
}
export
const
generateUUID
=
()
=>
{
if
(
typeof
crypto
===
'object'
)
{
if
(
typeof
crypto
.
randomUUID
===
'function'
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment