UNPKG

diginext-utils

Version:
29 lines 685 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toInt = toInt; const isNull_1 = require("./isNull"); /** * Converts a value to an integer. * Returns 0 if the value cannot be converted. * * @param value - The value to convert * @returns The integer representation * * @example * ```ts * toInt('42'); // 42 * toInt('3.14'); // 3 * toInt(5.7); // 5 * toInt('hello'); // 0 * toInt(null); // 0 * toInt(''); // 0 * ``` */ function toInt(value) { if ((0, isNull_1.isNull)(value)) { return 0; } const result = parseInt(String(value), 10); return Number.isNaN(result) ? 0 : result; } //# sourceMappingURL=toInt.js.map