forked from eleme/morjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eleme#113 from hwaphon/fix/20230914_animation_exce…
…ption fix: animation 动画因用户指定单位导致双单位异常问题
- Loading branch information
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function isNumeric(val: string): boolean { | ||
return /^\d+(\.\d+)?$/.test(val) | ||
} | ||
|
||
function isDef<T>(val: T): val is NonNullable<T> { | ||
return val !== undefined && val !== null | ||
} | ||
|
||
export function addUnit( | ||
value: string | number, | ||
unit = 'px' | ||
): string | undefined { | ||
if (!isDef(value)) { | ||
return undefined | ||
} | ||
|
||
// eslint-disable-next-line no-param-reassign | ||
value = String(value) | ||
return isNumeric(value) ? `${value}${unit}` : value | ||
} |