General
Code samples and patterns for everyday tasks
#Arrays47
Array Difference
Find elements in the first array that are not present in the second array.
Array Frequencies
Count how many times each value appears in an array and return a frequency map.
Array Head
Get the first n elements of an array.
Array Intersection
Find common elements that exist in both arrays.
Array Tail
Get the last n elements of an array.
Array Union
Combine two arrays and remove duplicates to produce a union.
Average Array
Calculate the arithmetic mean of all numbers in an array.
Chunk Array
Split an array into smaller chunks of a specified size.
Compact Array
Remove falsy values (null, false, 0, empty strings) from an array.
Count Array Occurrences
Count occurrences of each value in an array and return a frequency map.
Count By Property
Count occurrences of array elements grouped by a specified property.
Drop While
Remove elements from the start of an array while a condition is true.
Fill Array
Create an array filled with a specific value.
Find Index
Find the index of the first element matching a condition.
Flatten Array
Flatten a nested array to a single level.
Generate Range
Generate a sequence of numbers within a specified range with a configurable step value.
Get Last Array Element
Get the last element of an array.
Get Random Array Item
Select and return a random element from an array.
Group By Property
Group array items by a property value.
Index by Property
Convert an array of objects to an object indexed by a property.
Index By Property
Create an object indexed by a property value for fast lookups.
Matrix Multiply
Multiply two matrices.
Matrix Transpose
Transpose a 2D matrix (swap rows and columns).
Max Value in Array
Find the maximum value in an array.
Min Value in Array
Find the minimum value in an array.
Nth Largest Element
Find the nth largest element in an array by sorting in descending order.
Nth Smallest Element
Find the nth smallest element in an array by sorting in ascending order.
Partition Array
Split an array into two groups based on a condition.
Partition Array
Split an array into two arrays based on a condition, separating even and odd numbers.
Pluck Property
Extract a specific property value from each object in an array.
Remove Array Duplicates
Remove duplicate values from an array while preserving the original order of first occurrences.
Reverse Array
Reverse the order of elements in an array, returning a new array with elements in opposite order.
Rotate Array Left
Rotate array elements to the left by a specified number of positions, wrapping elements around.
Rotate Array Right
Rotate array elements to the right by a specified number of positions, wrapping elements around.
Rotate Matrix 90
Rotate a 2D square matrix 90 degrees clockwise by transposing and reversing rows.
Sample Array
Get N random items from an array without replacement.
Shuffle Array
Randomly shuffle the elements of an array (Fisher-Yates algorithm).
Sort Array Ascending
Sort an array of numbers in ascending order.
Sort Array Descending
Sort an array of numbers in descending order.
Sort by Property
Sort an array of objects by a specific property.
Sum Array
Calculate the sum of all numbers in an array.
Symmetric Difference
Find elements in either array but not in both (exclusive OR).
Take While
Take elements from the start of an array while a condition is true.
Unique by Property
Remove duplicates from array of objects by a specific property.
Unzip Arrays
Separate zipped arrays back into individual arrays (inverse of zip).
Zip Arrays
Combine multiple arrays element by element into tuples.
Zip Arrays
Combine multiple arrays element-wise into pairs.
#Async2
#Colors6
Blend Colors
Blend two hex colors together with a customizable ratio.
Darken Color
Darken a hex color by a percentage.
Invert Color
Invert a hex color (get complementary color).
Is Light Color
Check if a hex color is light (good for determining text color).
Lighten Color
Lighten a hex color by a percentage.
Random Hex Color
Generate a random hexadecimal color code for use in CSS or graphics applications.
#Dates20
Add Days to Date
Add a specified number of days to a date and return the result in ISO format.
Business Days Between
Calculate the number of business days (weekdays) between two dates. Excludes Saturdays and Sundays, useful for project planning and SLA calculations.
Calculate Age
Calculate age in years from a birth date, accounting for month and day.
Count Working Days
Count working days (excluding weekends) between dates.
Days Between Dates
Calculate the number of days between two dates.
Days in Month
Get the number of days in a specific month.
End of Day
Get the end of day (23:59:59.999) for a date.
End of Month
Get the last day of the month for a date.
Get Current ISO Date
Get the current date in ISO 8601 format.
Get Current Timestamp
Get the current Unix timestamp in milliseconds.
Get Day of Week
Get the day of the week name from a date.
Get Quarter
Get the quarter (1-4) for a date.
Get Week Number
Get the ISO week number from a date.
Is Leap Year
Check if a year is a leap year.
Is Same Day
Check if two dates are on the same day.
Is Weekend
Check if a date falls on a weekend (Saturday or Sunday).
Relative Time (Time Ago)
Convert a date to a human-readable relative time format such as '2 hours ago' or 'in 3 days'.
Start of Day
Get the start of day (midnight) for a date.
Start of Month
Get the first day of the month for a date.
Start of Week
Get the start of the week for a date.
#Http4
Check Cloudflare Cache Status
Check if a resource is served from Cloudflare's cache by inspecting the CF-Cache-Status header.
Fetch Error Details
Extract status, headers and body from an HTTP error response.
HTTP Status Message
Get the standard message for any HTTP status code.
Retry Fetch with Backoff
Automatically retry failed HTTP requests with exponential backoff.
#Math26
Calculate Median
Calculate the median value of an array of numbers.
Calculate Mode
Find the most frequent value(s) in an array.
Calculate Percentile
Calculate the nth percentile of an array using linear interpolation.
Celsius to Fahrenheit
Convert temperature from Celsius to Fahrenheit using the standard formula.
Clamp Number
Restrict a number to be within a minimum and maximum range.
Count Set Bits
Count the number of set bits (1s) in a number's binary representation.
Degrees to Radians
Convert degrees to radians.
Distance Between Points
Calculate the Euclidean distance between two points.
Fahrenheit to Celsius
Convert temperature from Fahrenheit to Celsius.
Haversine Distance
Calculate distance between two GPS coordinates.
Is Even
Check if a number is even.
Is Odd
Check if a number is odd.
Is Power of Two
Check if a number is a power of two.
Linear Interpolation
Interpolate between two values.
Map Value to Range
Map a value from one range to another.
Next Power of Two
Find the next power of two greater than or equal to a given number.
Normalize Array
Normalize array values to a 0-1 range using min-max scaling.
Ordinal Suffix
Add an ordinal suffix to a number, returning formats like 1st, 2nd, 3rd, 4th.
Percentage Change
Calculate the percentage change between an old and new value.
Radians to Degrees
Convert an angle from radians to degrees.
Random Float
Generate a random floating-point number within a specified range with configurable decimal precision.
Random Integer
Generate a random integer within an inclusive range specified by minimum and maximum values.
Round to Decimals
Round a floating-point number to a specified number of decimal places for precision control.
Seeded Random
Generate reproducible random numbers using a seed value. Same seed always produces the same sequence, essential for testing and procedural generation.
Standard Deviation
Calculate the standard deviation of an array of numbers.
Sum of Digits
Calculate the sum of all digits in a number.
#Objects27
Count Object Properties
Count the number of enumerable properties in an object.
Deep Clone Object
Create a deep copy of an object (handles nested objects and arrays).
Deep Equal
Check if two values are deeply equal by recursively comparing all nested properties. Works with objects, arrays, and primitives.
Deep Freeze Object
Recursively freeze an object and all nested objects to make them immutable.
Deep Merge Objects
Deep merge two objects, combining nested properties.
Flatten Object
Flatten a nested object to a single level with dot notation keys.
Get Nested Value
Safely get a nested property value from an object.
Invert Object
Swap keys and values in an object.
Is Empty Object
Check if an object has no properties.
Merge Objects
Merge two objects together (shallow merge).
Object Diff
Find the differences between two objects, showing changed, added, and removed keys.
Object Filter by Values
Filter object entries based on their values using a threshold condition.
Object Group By Key
Group an array of objects by a specified key into categorized collections.
Object Has Key
Check if an object has a specific key using dot notation for nested paths.
Object Invert
Swap keys and values in an object, making values become keys.
Object Map Values
Apply a transformation function to all object values while preserving keys.
Object Omit
Create a new object with specified keys omitted from the original.
Object Pick
Create a new object with only the specified keys from the original.
Object Rename Keys
Rename keys in an object based on a provided key mapping.
Object Set Nested Value
Set a value at a nested path in an object using dot notation.
Object to Query String
Convert an object to a URL-encoded query string for use in URLs.
Omit Properties
Create an object without the specified properties using comma-separated keys.
Pick Properties
Create an object with only the specified properties using comma-separated keys.
Query String to Object
Parse a URL query string into an object with decoded key-value pairs.
Rename Object Keys
Rename keys in an object based on a provided mapping of old key names to new key names.
Transform Object Values
Apply a transformation to all values in an object.
Unflatten Object
Convert a flat object with dot notation keys to a nested object.
#Security3
Constant Time Compare
Compare two strings in constant time to prevent timing attacks. Unlike === which returns early on first mismatch, this compares all characters regardless of where differences occur.
SQL Injection Prevention
Use parameterized queries to prevent SQL injection attacks.
XSS Attack Prevention
Escape HTML entities to prevent Cross-Site Scripting attacks.
#Strings44
Capitalize First Letter
Capitalize the first letter of a string while keeping the rest unchanged.
Capitalize Words
Capitalize the first letter of each word in a string (title case).
Center String
Center a string within a given width by padding with spaces.
Compare Strings (Case Insensitive)
Compare two strings ignoring case differences.
Convert to Camel Case
Convert a string to camelCase format with lowercase first letter.
Convert to Kebab Case
Convert a string to kebab-case format.
Convert to Pascal Case
Convert a string to PascalCase format, capitalizing each word and removing separators.
Convert to Snake Case
Convert a string to snake_case format.
Count Characters
Count the number of characters in a string, with option to exclude spaces.
Count Regex Matches
Count how many times a regex pattern matches in a string.
Count Substring Occurrences
Count how many times a substring appears in a string (non-overlapping).
Count Syllables
Estimate the number of syllables in an English word.
Count Words
Count the number of whitespace-separated words in a string.
Extract @Mentions
Extract all @mentions from a text string.
Extract Emails from Text
Extract all email addresses from a text string.
Extract Hashtags
Extract all hashtags from a text string.
Extract Initials
Extract initials from a name.
Extract Numbers from String
Extract all numbers from a string.
Extract URLs from Text
Extract all URLs from a text string.
Find Longest Word
Find the longest word in a string.
Highlight Matches
Wrap regex matches with HTML tags.
Indent String
Add indentation to each line of a string.
Match Whole Word
Match a whole word only (with word boundaries).
Normalize Whitespace
Replace multiple consecutive whitespace characters with a single space and trim edges.
Pad String End
Pad a string from the end with a specified character to reach a target length.
Pad String Start
Pad a string from the start with a specified character to reach a target length.
Redact Secrets
Mask sensitive data like API keys, tokens, and passwords in text. Essential for logging and error messages to prevent credential exposure.
Remove Accents
Remove diacritical marks and accents from Unicode characters, converting them to their ASCII equivalents.
Remove Common Indent
Remove the common leading whitespace from all lines in a multi-line string, normalizing indentation.
Remove Duplicate Characters
Remove duplicate characters from a string while keeping only the first occurrence of each character.
Repeat String
Repeat a string a specified number of times to create a new concatenated string.
Reverse String
Reverse the order of characters in a string, creating a mirror image of the original text.
Simple Template String
Replace placeholders in a template string with values.
Slugify String
Convert a string to a URL-friendly slug.
Split Keep Delimiter
Split string but keep the delimiter in results.
String to Character Array
Convert a string to an array of characters.
Strip ANSI Codes
Remove ANSI escape codes from a string.
Strip HTML Tags
Remove all HTML tags from a string.
Strip Markdown
Remove Markdown formatting and return plain text.
Title Case
Capitalize the first letter of each word in a string.
Trim Extra Whitespace
Remove extra whitespace from a string, keeping single spaces between words.
Truncate String
Truncate a string to a specified length with ellipsis.
Word Wrap
Wrap text to specified line width.
Wrap Text
Wrap text at a specified character width.
#Validation18
Check Password Strength
Check if a password meets strength requirements (8+ chars, uppercase, lowercase, number, special).
Get Type
Get the precise type of any value.
Is Alpha Only
Check if a string contains only alphabetic characters.
Is Alphanumeric
Check if a string contains only letters and numbers.
Is Array
Check if a value is an array.
Is Empty
Check if a value is empty (null, undefined, empty string, array, or object).
Is Numeric
Check if a string represents a valid number.
Validate Credit Card (Luhn)
Validate a credit card number using the Luhn algorithm.
Validate Date
Check if a string is a valid date.
Validate Email
Check if a string is a valid email address.
Validate Hex Color
Check if a string is a valid hex color code.
Validate IPv4 Address
Check if a string is a valid IPv4 address.
Validate JSON
Check if a string is valid JSON.
Validate Phone Number
Check if a string is a valid phone number (basic international format).
Validate Regex Pattern
Check if a string is a valid regex pattern.
Validate Slug
Check if a string is a valid URL slug.
Validate URL
Check if a string is a valid URL.
Validate UUID
Check if a string is a valid UUID (v1-v7).