UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

15 lines 478 B
import { endsWith } from "../StringUtils"; import { toFloat } from "./toFloat"; export function multiply100(source, defaultValue) { if (source === undefined || source === null) { return defaultValue; } if (typeof source === 'number') { return source * 100; } if (endsWith(source, '%')) { return toFloat(source.replace('%', ''), defaultValue); } var alias = toFloat(source); return alias === undefined || alias === null ? defaultValue : alias * 100; }