javascript
const isHex = /^[0-9a-f]+$/i.test(value);Regular expressions, JSON parsing and serialization, dates, Intl formatting, math, and crypto helpers.
Match, capture, replace, split, and validate strings with regex.
const isHex = /^[0-9a-f]+$/i.test(value);const matches = text.match(/\d+/g);const all = [...text.matchAll(/(?<year>\d{4})/g)];const m = /(?<user>[a-z]+)@(?<host>.+)/i.exec(email);
const host = m?.groups?.host;const normalized = text.replace(/\s+/g, " ").trim();const parts = csvLine.split(/\s*,\s*/);function escapeRegex(text) {
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}Parse, stringify, pretty-print, revivers, and replacers.
const data = JSON.parse(raw);const json = JSON.stringify(data);const pretty = JSON.stringify(data, null, 2);const parsed = JSON.parse(raw, (key, value) => key.endsWith("At") ? new Date(value) : value);const json = JSON.stringify(data, (key, value) => key === "password" ? undefined : value);Date, Intl, formatting, parsing, relative time, and timestamps.
const timestamp = Date.now();const date = new Date("2026-03-06T12:00:00Z");const iso = new Date().toISOString();const fmt = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "short" });
fmt.format(new Date());const nf = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
nf.format(1999.5);const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });
rtf.format(-1, "day");const nextWeek = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);Clamp, round, UUIDs, random IDs, and crypto-safe bytes.
const n = Math.floor(Math.random() * 10);Math.round(1.6);
Math.floor(1.6);
Math.ceil(1.2);const clamp = (n, min, max) => Math.min(Math.max(n, min), max);const id = crypto.randomUUID();const bytes = crypto.getRandomValues(new Uint8Array(16));const data = new TextEncoder().encode("hello");
const hash = await crypto.subtle.digest("SHA-256", data);