@tuniao/tnui-vue3-uniapp
Version:
TuniaoUI for vue3 uniapp
20 lines (18 loc) • 489 B
text/typescript
import { isString } from '../types'
/**
* 格式化dom的尺寸单位
* @param value 待处理的值
* @param unit 默认单位
* @param empty 是否返回空值
* @returns 处理后的值
*/
export const formatDomSizeValue = (
value: string | number,
unit = 'rpx',
empty = true
): string => {
if (!value) return empty ? '' : `0${unit}`
if (isString(value) && /(^calc)|(%|vw|vh|px|rpx|auto)$/.test(value as string))
return value as string
return `${value}${unit}`
}