feat: coding

This commit is contained in:
xingyu 2023-10-31 10:13:22 +08:00
parent 2a029ba35b
commit 80e72fd924

View File

@ -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) => { export const setCssVar = (prop: string, val: any, dom = document.documentElement) => {
dom.style.setProperty(prop, val) dom.style.setProperty(prop, val)
} }
@ -67,7 +74,7 @@ export const trim = (str: string) => {
* @param {Date | number | string} time * @param {Date | number | string} time
* @param {String} fmt yyyy-MM-ddyyyy-MM-dd HH:mm:ss * @param {String} fmt yyyy-MM-ddyyyy-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 '' if (!time) return ''
else { else {
const date = new Date(time) 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 str: string = 'xxxxx-xxxxx-4xxxx-yxxxx-xxxxx'.replace(/[xy]/g, (c: string) => {
const r: number = (Math.random() * 16) | 0 const r: number = (Math.random() * 16) | 0
const v: number = c === 'x' ? r : (r & 0x3) | 0x8 const v: number = c === 'x' ? r : (r & 0x3) | 0x8
@ -107,6 +114,13 @@ export const toAnyString = () => {
return str return str
} }
/**
*
*/
export function firstUpperCase(str: string) {
return str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase())
}
export const generateUUID = () => { export const generateUUID = () => {
if (typeof crypto === 'object') { if (typeof crypto === 'object') {
if (typeof crypto.randomUUID === 'function') { if (typeof crypto.randomUUID === 'function') {