mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 02:08:12 +08:00
perf(utils): addUnit support string number (#10362)
This commit is contained in:
parent
364d1a24fc
commit
42fb53aaa6
@ -1,5 +1,5 @@
|
||||
import { isClient } from '@vueuse/core'
|
||||
import { isNumber, isObject, isString } from '../types'
|
||||
import { isNumber, isObject, isString, isStringNumber } from '../types'
|
||||
import { camelize } from '../strings'
|
||||
import { entriesOf, keysOf } from '../objects'
|
||||
import { debugWarn } from '../error'
|
||||
@ -76,10 +76,10 @@ export const removeStyle = (
|
||||
|
||||
export function addUnit(value?: string | number, defaultUnit = 'px') {
|
||||
if (!value) return ''
|
||||
if (isString(value)) {
|
||||
return value
|
||||
} else if (isNumber(value)) {
|
||||
if (isNumber(value) || isStringNumber(value)) {
|
||||
return `${value}${defaultUnit}`
|
||||
} else if (isString(value)) {
|
||||
return value
|
||||
}
|
||||
debugWarn(SCOPE, 'binding value must be a string or number')
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { isArray, isObject } from '@vue/shared'
|
||||
import { isArray, isObject, isString } from '@vue/shared'
|
||||
import { isNil } from 'lodash-unified'
|
||||
|
||||
export {
|
||||
@ -28,3 +28,10 @@ export const isElement = (e: unknown): e is Element => {
|
||||
export const isPropAbsent = (prop: unknown): prop is null | undefined => {
|
||||
return isNil(prop)
|
||||
}
|
||||
|
||||
export const isStringNumber = (val: string): boolean => {
|
||||
if (!isString(val)) {
|
||||
return false
|
||||
}
|
||||
return !Number.isNaN(Number(val))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user