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.

18 lines (17 loc) 607 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractDates = void 0; /** * Extracts date-like substrings from a string. * * Example: extractDates("Today is 2023-05-01 and tomorrow is 02/05/2023") → ["2023-05-01", "02/05/2023"] * * @author @dailker * @param {string} str - The input string. * @returns {string[]} Array of date-like substrings found. */ function extractDates(str) { const regex = /\b\d{1,2}[\/\-\.]\d{1,2}[\/\-\.]\d{2,4}\b|\b\d{4}-\d{2}-\d{2}\b/g; return str.match(regex) || []; } exports.extractDates = extractDates;