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.

15 lines (14 loc) 477 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dateToUnixTimestamp = void 0; /** * Converts date to UNIX timestamp in seconds or milliseconds. * @author @dailker * @param {Date} date * @param {'s'|'ms'} [unit='ms'] * @returns {number} */ function dateToUnixTimestamp(date, unit = 'ms') { return unit === 's' ? Math.floor(date.getTime() / 1000) : date.getTime(); } exports.dateToUnixTimestamp = dateToUnixTimestamp;