import type { DealDataType } from '~/typings/utils'
import { isArray, isEmpty, isNil, isObject } from 'lodash-es'
export function noop() {
return undefined
}
export async function sleep(time: number) {
return new Promise((resolve) => {
setTimeout(resolve, time)
})
}
export function dealData({
data = '',
format = '-',
prefix = '',
suffix = '',
result,
hideEmptyStr = true,
showAffix = false,
}: DealDataType) {
if (result) {
if (showAffix) {
return `${prefix}${result}${suffix}`
}
return result
}
if (isNil(data)) {
return `${prefix}${format}${suffix}`
}
if (data === '' && hideEmptyStr) {
return `${prefix}${format}${suffix}`
}
if (isArray(data) || isObject(data)) {
if (isEmpty(data)) {
return format
}
return data
}
return `${prefix}${data}${suffix}`
}