File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 1+ import { isNumber } from '../../util' ;
12import AbstractCalculator from './calculator' ;
23
34const CALC_UNIT = 'CALC_UNIT' ;
45
56const regexp = new RegExp ( CALC_UNIT , 'g' ) ;
67
7- function unit ( value : string | number ) {
8- if ( typeof value === 'number' ) {
8+ const unit = ( value : string | number ) => {
9+ if ( isNumber ( value ) ) {
910 return `${ value } ${ CALC_UNIT } ` ;
1011 }
1112 return value ;
12- }
13+ } ;
1314
1415export default class CSSCalculator extends AbstractCalculator {
1516 result : string = '' ;
@@ -30,8 +31,8 @@ export default class CSSCalculator extends AbstractCalculator {
3031
3132 if ( num instanceof CSSCalculator ) {
3233 this . result = `(${ num . result } )` ;
33- } else if ( numType === 'number' ) {
34- this . result = unit ( num as number ) ;
34+ } else if ( isNumber ( num ) ) {
35+ this . result = unit ( num ) ;
3536 } else if ( numType === 'string' ) {
3637 this . result = num as string ;
3738 }
Original file line number Diff line number Diff line change @@ -155,12 +155,16 @@ export function supportLogicProps(): boolean {
155155
156156export const isClientSide = canUseDom ( ) ;
157157
158- export function unit ( num : string | number ) {
159- if ( typeof num === 'number' ) {
158+ export const isNumber = ( val : any ) : val is number => {
159+ return typeof val === 'number' && ! Number . isNaN ( val ) ;
160+ } ;
161+
162+ export const unit = ( num : string | number ) => {
163+ if ( isNumber ( num ) ) {
160164 return `${ num } px` ;
161165 }
162166 return num ;
163- }
167+ } ;
164168
165169export function toStyleStr (
166170 style : string ,
You can’t perform that action at this time.
0 commit comments