feat(Badge): max support string type

This commit is contained in:
chenjiahan
2020-10-02 17:05:08 +08:00
parent 56c50666ce
commit 839b8654ee
7 changed files with 24 additions and 23 deletions

View File

@@ -6,8 +6,7 @@ export function addUnit(value?: string | number): string | undefined {
return undefined;
}
value = String(value);
return isNumeric(value) ? `${value}px` : value;
return isNumeric(value) ? `${value}px` : String(value);
}
export function getSizeStyle(originSize?: string | number) {

View File

@@ -91,6 +91,7 @@ test('isMobile', () => {
});
test('isNumeric', () => {
expect(isNumeric(1)).toBeTruthy();
expect(isNumeric('1')).toBeTruthy();
expect(isNumeric('1.2')).toBeTruthy();
expect(isNumeric('1..2')).toBeFalsy();

View File

@@ -1,5 +1,5 @@
export function isNumeric(val: string): boolean {
return /^\d+(\.\d+)?$/.test(val);
export function isNumeric(val: string | number): val is string {
return typeof val === 'number' || /^\d+(\.\d+)?$/.test(val);
}
export function isNaN(val: number): val is typeof NaN {