UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

16 lines (15 loc) 539 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeDivide = void 0; /** * Divides a by b, returning a fallback value if b is zero. * @author @dailker * @param {number} a - The numerator. * @param {number} b - The denominator. * @param {number} [fallback=0] - The value to return if b is zero. * @returns {number} The result of a / b, or fallback if b is zero. */ function safeDivide(a, b, fallback = 0) { return b === 0 ? fallback : a / b; } exports.safeDivide = safeDivide;