indicative-utils
Version:
Reusable utilities for indicative validation library
17 lines (16 loc) • 451 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
function toInt(value, fractional = false) {
if (typeof (value) === 'number') {
return fractional ? value : Math.trunc(value);
}
if (typeof (value) !== 'string') {
return null;
}
const casted = Number(value);
if (isNaN(casted)) {
return null;
}
return fractional ? casted : Math.trunc(casted);
}
exports.toInt = toInt;
;