mirror of
https://github.com/youzan/vant.git
synced 2026-01-28 01:10:04 +08:00
feat(Badge): max support string type
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user