mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
[improvement] adjust utils
This commit is contained in:
3
packages/utils/format/number.ts
Normal file
3
packages/utils/format/number.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function range(num: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(num, min), max);
|
||||
}
|
9
packages/utils/format/string.ts
Normal file
9
packages/utils/format/string.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const camelizeRE = /-(\w)/g;
|
||||
|
||||
export function camelize(str: string): string {
|
||||
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function padZero(num: number | string): string {
|
||||
return (num < 10 ? '0' : '') + num;
|
||||
}
|
11
packages/utils/format/unit.ts
Normal file
11
packages/utils/format/unit.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { isDef } from '..';
|
||||
import { isNumber } from '../validate/number';
|
||||
|
||||
export function suffixPx(value?: string | number): string | undefined {
|
||||
if (!isDef(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
value = String(value);
|
||||
return isNumber(value) ? `${value}px` : value;
|
||||
}
|
Reference in New Issue
Block a user