Snippets are memory anchors.

Iterator Helpers

Iterator helpers are exposed by defining new methods on the Iterator object's prototype. These methods align with many functional programming methods you're used to using, such as map, filter, reduce, and other similar methods.

Light Dark

Uses the light-dark() CSS function to automatically switch between light and dark color values based on the user's system preference or color scheme setting. This modern CSS feature eliminates the need for complex media queries when implementing dark mode support.

Trim Text

Intelligently truncates text at word boundaries to maintain readability. Unlike basic string truncation that cuts words mid-character, this function finds the last complete word within the specified length and adds ellipsis appropriately. Returns both the processed text and a boolean indicating whether truncation occurred.

Cross Fade

Uses the cross-fade() CSS function to blend two or more images at defined transparency levels. This function allows you to create smooth transitions and overlay effects by specifying opacity percentages for each image in the blend.

Create 2d Array

Creates a 2D array (matrix) with specified dimensions and initial values using Array.from(). This utility function provides a clean and type-safe way to generate matrix-like data structures.

Convert String to Html

Converts an HTML string into real HTML DOM elements using the DOMParser Web API. This function safely parses HTML strings and returns the first element from the parsed content, with proper error handling for malformed HTML.

Is Valid Color

Validates whether a given string is a valid CSS color value. Uses the browser's CSS: supports() API to check color validity and provides an option to allow or disallow CSS special values like inherit, transparent, currentcolor, etc.

Shuffle

Shuffles an array in-place using the Fisher-Yates shuffle algorithm. This function randomly rearranges the elements of an array and returns the same array (mutated). It provides a uniform distribution, meaning each possible permutation has an equal probability of occurring.

Delay

Creates a Promise that resolves after a specified amount of time. This is useful for creating a pause or "sleep" effect within async functions.