Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/theme/calc/CSSCalculator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { isNumber } from '@/util';
Comment thread
li-jia-nan marked this conversation as resolved.
Outdated
import AbstractCalculator from './calculator';

const CALC_UNIT = 'CALC_UNIT';

const regexp = new RegExp(CALC_UNIT, 'g');

function unit(value: string | number) {
if (typeof value === 'number') {
const unit = (value: string | number) => {
if (isNumber(value)) {
return `${value}${CALC_UNIT}`;
}
return value;
}
};
Comment thread
li-jia-nan marked this conversation as resolved.

export default class CSSCalculator extends AbstractCalculator {
result: string = '';
Expand All @@ -30,8 +31,8 @@ export default class CSSCalculator extends AbstractCalculator {

if (num instanceof CSSCalculator) {
this.result = `(${num.result})`;
} else if (numType === 'number') {
this.result = unit(num as number);
} else if (isNumber(num)) {
this.result = unit(num);
Comment thread
li-jia-nan marked this conversation as resolved.
} else if (numType === 'string') {
this.result = num as string;
}
Comment thread
li-jia-nan marked this conversation as resolved.
Expand Down
10 changes: 7 additions & 3 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ export function supportLogicProps(): boolean {

export const isClientSide = canUseDom();

export function unit(num: string | number) {
if (typeof num === 'number') {
export const isNumber = (val: any): val is number => {
return typeof val === 'number' && !Number.isNaN(val);
};

export const unit = (num: string | number) => {
if (isNumber(num)) {
return `${num}px`;
}
return num;
}
};
Comment thread
li-jia-nan marked this conversation as resolved.

export function toStyleStr(
style: string,
Expand Down
Loading