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