[improvement] adjust utils

This commit is contained in:
陈嘉涵
2019-06-06 11:49:39 +08:00
parent f5059ea6ba
commit d7a5be67fe
37 changed files with 96 additions and 82 deletions

View File

@@ -0,0 +1,3 @@
export function range(num: number, min: number, max: number): number {
return Math.min(Math.max(num, min), max);
}

View 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;
}

View 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;
}