Debounce Function
Prevents a function from being called too frequently, executes only the last call
function debounce(func, delay) {
let timeoutId;
return function(...args) {Practical browser logic, modern language patterns and small utilities for everyday product work.
31 entriesPrevents a function from being called too frequently, executes only the last call
function debounce(func, delay) {
let timeoutId;
return function(...args) {Limits a function to be executed only once per specified time period
function throttle(func, limit) {
let inThrottle;
return function(...args) {Creates a completely independent copy of an object, including nested objects
function deepClone(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}Formats date objects into specified format strings
function formatDate(date, format = 'YYYY-MM-DD') {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');Generates random numbers within ranges or random strings
const random = {
// Generate random integer within range
int(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;Validates if email address format is correct
function validateEmail(email) {
const regex = /^[^s@]+@[^s@]+.[^s@]+$/;
return regex.test(email);
}Simplifies reading, setting, and deleting browser cookies
const cookies = {
set(name, value, days = 7) {
const expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));Parses URL query parameters into an object
function parseQueryString(queryString) {
if (!queryString) return {};
// Remove leading ? or #Copies text to user's clipboard
async function copyToClipboard(text) {
try {
// Use modern Clipboard API
if (navigator.clipboard && window.isSecureContext) {Detects user device type and browser information
const device = {
// Detect device type
isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);Common array operations and helper functions
const arrayUtils = {
// Remove duplicates from array
unique(arr) {
return [...new Set(arr)];Format numbers as currency with proper symbols and formatting
function formatMoney(amount, currency = 'USD', locale = 'en-US') {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: currency,