UNPKG

@ukbhra/common-utils

Version:

A collection of reusable utility functions for string, object, validation, and general operations in Node.js projects.

22 lines 941 B
export const isEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); export const isUUID = (uuid) => /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid); export const isPhoneNumber = (num) => /^\+?[1-9]\d{1,14}$/.test(num); // E.164 format export const isJsonString = (str) => { try { JSON.parse(str); return true; } catch { return false; } }; export const isAlpha = (str) => /^[A-Za-z]+$/.test(str); export const isAlphanumeric = (str) => /^[A-Za-z0-9]+$/.test(str); export const isNumeric = (str) => /^-?\d+(\.\d+)?$/.test(str); export const isUrl = (str) => /^(https?:\/\/)?([\w\-]+\.)+[\w\-]+(\/[\w\-._~:/?#[\]@!$&'()*+,;=]*)?$/.test(str); export const isDate = (str) => { const date = Date.parse(str); return !isNaN(date); }; export const isEmptyOrWhitespace = (str) => !str || str.trim().length === 0; //# sourceMappingURL=validationUtil.js.map