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) • 594 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractEmails = void 0;
/**
* Finds all email addresses in a string.
*
* Example: extractEmails("Contact me at john@example.com or jane@site.org") → ["john@example.com", "jane@site.org"]
*
* @author @dailker
* @param {string} str - The input string.
* @returns {string[]} Array of email addresses found.
*/
function extractEmails(str) {
const regex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
return str.match(regex) || [];
}
exports.extractEmails = extractEmails;