@technobuddha/library
Version:
A large library of useful functions
10 lines (7 loc) • 356 B
text/typescript
import isString from 'lodash/isString';
import isBoolean from 'lodash/isBoolean';
import isNumber from 'lodash/isNumber';
export function toInteger(entity: unknown): number {
return isNumber(entity) ? Math.trunc(entity) : isBoolean(entity) ? (entity ? 1 : 0) : isString(entity) ? Number.parseInt(entity, 10) : Number.NaN;
}
export default toInteger;