### Run Development Server Source: https://github.com/maxdewald/moderndash/blob/main/website/README.md Starts the local development server to preview changes in real-time. Supports optional flags to automatically open the browser. ```bash npm run dev npm run dev -- --open ``` -------------------------------- ### Install ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Installs the ModernDash library using npm. This is the first step to using the utility functions in your project. ```bash npm install moderndash ``` -------------------------------- ### Move Array Element - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Moves an element within an array from a specified starting index to a specified ending index. It takes the array, the source index, and the destination index as arguments. ```typescript import { move } from 'moderndash'; move([1, 2, 3, 4, 5], 0, 2); // => [2, 3, 1, 4, 5] ``` -------------------------------- ### Build and Preview Production Source: https://github.com/maxdewald/moderndash/blob/main/website/README.md Compiles the application for production deployment and allows for local previewing of the generated build. ```bash npm run build npm run preview ``` -------------------------------- ### Initialize a New Svelte Project Source: https://github.com/maxdewald/moderndash/blob/main/website/README.md Uses the create-svelte CLI to scaffold a new project. You can initialize in the current directory or specify a folder name. ```bash npm create svelte@latest npm create svelte@latest my-app ``` -------------------------------- ### Function Utilities Source: https://context7.com/maxdewald/moderndash/llms.txt Utilities for enhancing function behavior like debouncing, throttling, and memoization. ```APIDOC ## debounce ### Description Creates a debounced version of a function that delays invoking until after a specified time has elapsed since the last call. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { debounce } from 'moderndash'; const sayHello = (name: string) => console.log(`Hello, ${name}!`); const debouncedSayHello = debounce(sayHello, 200); debouncedSayHello("John"); debouncedSayHello("Jane"); // => Only "Hello, Jane!" is logged after 200ms // Methods available: debouncedSayHello.cancel(); // Cancel pending invocation debouncedSayHello.flush(); // Immediately invoke debouncedSayHello.pending(); // Check if pending ``` ### Response N/A ``` ```APIDOC ## throttle ### Description Creates a throttled function that invokes at most once per specified time period. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { throttle } from 'moderndash'; const throttled = throttle(() => console.log("Throttled!"), 1000); throttled(); throttled(); // => "Throttled!" is logged once per second ``` ### Response N/A ``` ```APIDOC ## memoize ### Description Creates a function that memoizes the result of a given function with optional TTL and custom resolver. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { memoize } from 'moderndash'; function fibonacci(n: number): number { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } const memoizedFib = memoize(fibonacci, { ttl: 1000 }); memoizedFib(40); // => 102334155 memoizedFib(40); // => 102334155 (cache hit) setTimeout(() => memoizedFib(40), 1000); // => cache miss after TTL // Access cache directly memoizedFib.cache.get("[40]"); memoizedFib.cache.clear(); ``` ### Response N/A ``` ```APIDOC ## maxCalls ### Description Creates a function that invokes the given function as long as it's called <= n times. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { maxCalls } from 'moderndash'; let count = 0; const addCount = () => ++count; const limitAddCount = maxCalls(addCount, 2); limitAddCount(); // => 1 limitAddCount(); // => 2 limitAddCount(); // => 2 (cached result) ``` ### Response N/A ``` ```APIDOC ## minCalls ### Description Creates a function that invokes the given function only after it's called more than n times. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { minCalls } from 'moderndash'; const caution = () => console.log("Caution!"); const limitedCaution = minCalls(caution, 2); limitedCaution(); // => undefined limitedCaution(); // => undefined limitedCaution(); // => "Caution!" (invoked on third call) ``` ### Response N/A ``` ```APIDOC ## times ### Description Invokes a function n times, returning an array of results. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { times } from 'moderndash'; times(index => console.log("Run", index), 3); // => "Run 0" | "Run 1" | "Run 2" times(Math.random, 3); // => [0.123, 0.456, 0.789] times(() => 0, 4); // => [0, 0, 0, 0] ``` ### Response N/A ``` -------------------------------- ### String Manipulation Functions in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md New functions `trim`, `trimStart`, and `trimEnd` have been added for string manipulation. Additionally, `splitWords` has seen performance improvements and compatibility updates. ```javascript import { trim, trimStart, trimEnd, splitWords } from 'moderndash'; console.log(trim(' hello ')); // 'hello' console.log(trimStart(' hello ')); // 'hello ' console.log(trimEnd(' hello ')); // ' hello' console.log(splitWords('hello-world')); // ['hello', 'world'] ``` -------------------------------- ### Object Manipulation Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Functions for merging, setting values, and flattening objects. ```APIDOC ## merge ### Description Combines two or more objects into a single new object. Arrays and other types are overwritten, nested objects are merged. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { merge } from 'moderndash'; // Nested objects are merged merge({ a: 1 }, { b: 2 }, { c: 3, d: { e: 4 } }); // => { a: 1, b: 2, c: 3, d: { e: 4 } } // Other types are overwritten merge({ a: [1, 2] }, { a: [3, 4] }); // => { a: [3, 4] } merge({ a: 1 }, { a: "Yes" }); // => { a: "Yes" } ``` ### Response N/A ``` ```APIDOC ## set ### Description Sets the value at path of object. If a portion of path doesn't exist, it's created. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { set } from 'moderndash'; const obj = { a: { b: 2 } }; set(obj, 'a.c', 1); // => { a: { b: 2, c: 1 } } // Array notation set(obj, 'a.c[0]', 'hello'); // => { a: { b: 2, c: ['hello'] } } // Numbers with dots are treated as keys set(obj, 'a.c.0.d', 'world'); // => { a: { b: 2, c: { 0: { d: 'world' } } } ``` ### Response N/A ``` ```APIDOC ## flatKeys ### Description Flattens an object into a single level object with dot notation keys. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { flatKeys } from 'moderndash'; const obj = { a: { b: 2, c: [{ d: 3 }, { d: 4 }] } }; flatKeys(obj); // => { 'a.b': 2, 'a.c[0].d': 3, 'a.c[1].d': 4 } ``` ### Response N/A ``` -------------------------------- ### Object Manipulation Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Functions for creating new objects by picking or omitting specific properties from existing objects. ```APIDOC ## pick ### Description Creates an object composed of the picked object properties. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { pick } from 'moderndash'; const object = { a: 1, b: '2', c: 3 }; pick(object, ['a', 'c']); // => { a: 1, c: 3 } ``` ### Response N/A ## omit ### Description Omits specified keys from an object. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { omit } from 'moderndash'; const obj = { a: 1, b: 2, c: 3 }; omit(obj, ['a', 'b']); // => { c: 3 } ``` ### Response N/A ``` -------------------------------- ### Async Function Queue with Concurrency (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Manages a queue of asynchronous tasks, allowing a specified number of tasks to run concurrently. It provides methods for adding tasks, waiting for completion, pausing, resuming, and clearing the queue. ```typescript import { Queue } from 'moderndash'; // Create a queue that can run 3 tasks concurrently const queue = new Queue(3); queue.add(() => fetch('https://example.com')); queue.add(async () => { const response = await fetch('https://example.com'); return response.json(); }); await queue.done(); console.log("All tasks finished"); // Add an array of tasks and wait for them const results = await queue.add([ () => fetch('https://apple.com'), () => fetch('https://microsoft.com') ]); // => [Response, Response] // Queue control methods queue.pause(); queue.resume(); queue.clear(); queue.isPaused(); queue.getQueue(); ``` -------------------------------- ### String Manipulation Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Functions for transforming and manipulating strings, including case conversion, trimming, and escaping. ```APIDOC ## camelCase ### Description Converts a string to camelCase. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { camelCase } from 'moderndash'; camelCase('Foo Bar'); // => 'fooBar' camelCase('--foo-bar--'); // => 'fooBar' camelCase('__FOO_BAR__'); // => 'fooBar' ``` ### Response N/A ## pascalCase ### Description Converts a string to PascalCase. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { pascalCase } from 'moderndash'; pascalCase('Foo Bar'); // => 'FooBar' pascalCase('fooBar'); // => 'FooBar' pascalCase('__FOO_BAR__'); // => 'FooBar' ``` ### Response N/A ## kebabCase ### Description Converts a string to kebab-case. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { kebabCase } from 'moderndash'; kebabCase('Foo Bar'); // => 'foo-bar' kebabCase('fooBar'); // => 'foo-bar' kebabCase('__FOO_BAR__'); // => 'foo-bar' ``` ### Response N/A ## snakeCase ### Description Converts a string to snake_case. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { snakeCase } from 'moderndash'; snakeCase('Foo Bar'); // => 'foo_bar' snakeCase('fooBar'); // => 'foo_bar' snakeCase('--FOO-BAR--'); // => 'foo_bar' ``` ### Response N/A ## titleCase ### Description Converts a string to Title Case. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { titleCase } from 'moderndash'; titleCase('--foo-bar--'); // => 'Foo Bar' titleCase('fooBar'); // => 'Foo Bar' titleCase('HélloWorld'); // => 'Hello World' ``` ### Response N/A ## capitalize ### Description Converts the first character of a string to upper case and the remaining to lower case. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { capitalize } from 'moderndash'; capitalize('FRED'); // => 'Fred' ``` ### Response N/A ## splitWords ### Description Splits a string into words. Handles camelCase, PascalCase, and snake_case. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { splitWords } from 'moderndash'; splitWords('camelCase'); // => ['camel', 'Case'] splitWords('PascalCase'); // => ['Pascal', 'Case'] splitWords('hello_world-123'); // => ['hello', 'world', '123'] ``` ### Response N/A ## deburr ### Description Deburrs a string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { deburr } from 'moderndash'; deburr('déjà vu'); // => 'deja vu' ``` ### Response N/A ## truncate ### Description Truncates a string if it's longer than the given maximum length. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { truncate } from 'moderndash'; truncate("Hello, world!", { length: 5 }); // => "Hello..." truncate("Hello, world!", { length: 5, ellipsis: " [...]" }); // => "Hello [...]" truncate("Hello, world!", { length: 5, separator: " " }); // => "Hello, ..." ``` ### Response N/A ## trim / trimStart / trimEnd ### Description Trims specified characters from the string. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { trim, trimStart, trimEnd } from 'moderndash'; trim('$$abc$', '$'); // => 'abc' trim('!!abc_!', '_!'); // => 'abc' trimStart('$$$abc', '$'); // => 'abc' trimEnd('abc$$$', '$'); // => 'abc' ``` ### Response N/A ## replaceLast ### Description Replaces the last occurrence of a string. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { replaceLast } from 'moderndash'; replaceLast("Foo Bar Bar", "Bar", "Boo"); // => "Foo Bar Boo" ``` ### Response N/A ## escapeHtml / unescapeHtml ### Description Converts characters to/from HTML entities. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { escapeHtml, unescapeHtml } from 'moderndash'; escapeHtml('fred, barney, & pebbles'); // => 'fred, barney, & pebbles' unescapeHtml('fred, barney, & pebbles'); // => 'fred, barney, & pebbles' ``` ### Response N/A ## escapeRegExp ### Description Escapes RegExp special characters in a string. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { escapeRegExp } from 'moderndash'; escapeRegExp('[moderndash](https://moderndash.io/)'); // => '\\[moderndash\\]\\(https://moderndash\\.io/\\)' ``` ### Response N/A ``` -------------------------------- ### String Formatting - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Includes functions for formatting strings such as converting to Title Case, capitalizing the first letter, splitting strings into words, and deburring strings by removing diacritical marks. ```typescript import { titleCase, capitalize, splitWords, deburr } from 'moderndash'; titleCase('--foo-bar--'); // => 'Foo Bar' capitalize('FRED'); // => 'Fred' splitWords('camelCase'); // => ['camel', 'Case'] deburr('déjà vu'); // => 'deja vu' ``` -------------------------------- ### Create Range with ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Generates an array of numbers within a specified range, with an optional step value. It can create ascending or descending sequences. ```typescript import { range } from 'moderndash'; range(1, 5); // => [1, 2, 3, 4, 5] // Array of even numbers between 0 and 10 range(0, 10, 2); // => [0, 2, 4, 6, 8, 10] // Descending range range(5, 0, 2); // => [5, 3, 1] ``` -------------------------------- ### Memoize Decorator with TTL (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Memoizes a decorated method, caching its results to avoid redundant computations. It supports an optional Time-To-Live (TTL) to expire the cache after a certain period. This is beneficial for performance optimization of expensive function calls. ```typescript import { decMemoize } from 'moderndash'; class TestClass { @decMemoize({ ttl: 1000 }) testMethod(a: number, b: number) { return a + b; } } const instance = new TestClass(); instance.testMethod(1, 2); // => 3 instance.testMethod(1, 2); // => 3 (cached) ``` -------------------------------- ### Array Utility Functions in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md Functions like `intersection` and `difference` have been updated to allow the `compareFunc` as the last parameter and support comparing different types when a comparison function is provided. `flatKeys` has also received type corrections. ```javascript import { intersection, difference, flatKeys } from 'moderndash'; const array1 = [{ id: 1, name: 'a' }]; const array2 = [{ id: 1, name: 'b' }]; // Using compareFunc as last parameter const commonElements = intersection(array1, array2, (a, b) => a.id === b.id); console.log(commonElements); // [{ id: 1, name: 'a' }] const keys = flatKeys({ a: 1, b: { c: 2 } }); console.log(keys); // ['a', 'b.c'] ``` -------------------------------- ### String Case Conversion - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Provides functions to convert strings to various casing formats including camelCase, PascalCase, kebab-case, and snake_case. These functions handle different input formats. ```typescript import { camelCase, pascalCase, kebabCase, snakeCase } from 'moderndash'; camelCase('Foo Bar'); // => 'fooBar' pascalCase('Foo Bar'); // => 'FooBar' kebabCase('Foo Bar'); // => 'foo-bar' snakeCase('Foo Bar'); // => 'foo_bar' ``` -------------------------------- ### New Functions Added in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md New utility functions such as `replaceLast` and `move` have been introduced to extend the library's capabilities for array and string manipulation. ```javascript import { replaceLast, move } from 'moderndash'; const str = 'abcabc'; console.log(replaceLast(str, 'c', 'd')); // 'abcdab' const arr = [1, 2, 3, 4]; console.log(move(arr, 1, 3)); // [1, 3, 4, 2] ``` -------------------------------- ### Decorator Functions in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md When using decorator functions from Moderndash, ensure that the `experimentalDecorators` flag is enabled in your TypeScript configuration. ```typescript // tsconfig.json { "compilerOptions": { "experimentalDecorators": true } } ``` -------------------------------- ### Chunk Array with ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Creates an array of elements split into groups of a specified size. The last chunk contains the remaining elements if the array cannot be split evenly. ```typescript import { chunk } from 'moderndash'; chunk(['a', 'b', 'c', 'd'], 2); // => [['a', 'b'], ['c', 'd']] chunk(['a', 'b', 'c', 'd'], 3); // => [['a', 'b', 'c'], ['d']] chunk([1, 2, 3, 4, 5, 6, 7], 3); // => [[1, 2, 3], [4, 5, 6], [7]] ``` -------------------------------- ### Number Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Functions for performing calculations on arrays of numbers. ```APIDOC ## sum ### Description Calculates the sum of an array of numbers. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { sum } from 'moderndash'; sum([1, 2, 3, 4, 5]); // => 15 ``` ### Response N/A ``` ```APIDOC ## average ### Description Calculates the average of an array of numbers. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { average } from 'moderndash'; average([1, 2, 3, 4, 5]); // => 3 ``` ### Response N/A ``` ```APIDOC ## median ### Description Calculates the median of an array of numbers. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { median } from 'moderndash'; median([1, 2, 3, 4, 5]); // => 3 median([1, 2, 3, 4, 5, 6]); // => 3.5 ``` ### Response N/A ``` ```APIDOC ## round ### Description Rounds a number to the given precision. ### Method N/A (Utility function) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { round } from 'moderndash'; round(1.23456, 2); // => 1.23 round(1.235, 1); // => 1.2 round(1234.56); // => 1234.56 (default precision: 2) ``` ### Response N/A ``` -------------------------------- ### Shuffle Array with ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Randomly shuffles the elements of an array using the Fisher-Yates-Durstenfeld Shuffle algorithm, returning a new array with the elements in a random order. ```typescript import { shuffle } from 'moderndash'; shuffle([1, 2, 3, 4]); // => [4, 1, 3, 2] (random order) ``` -------------------------------- ### Performance Improvements in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md Several functions, including `unique`, `sort`, and `camelCase`, have undergone performance optimizations. These changes aim to improve benchmark results and overall library efficiency. ```javascript import { unique, sort, camelCase } from 'moderndash'; const numbers = [1, 2, 2, 3, 1, 4]; console.log(unique(numbers)); // [1, 2, 3, 4] const strings = ['c', 'a', 'b']; console.log(sort(strings)); // ['a', 'b', 'c'] console.log(camelCase('foo-bar-baz')); // 'fooBarBaz' ``` -------------------------------- ### Cryptographic Hashing (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Generates a cryptographic hash of the given data using the Web Crypto API. Supports various algorithms like SHA-256 and SHA-512, and can hash strings or objects. ```typescript import { hash } from 'moderndash'; // Hash a string using default SHA-256 await hash('hello world'); // => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a53..." // Hash an object using SHA-512 await hash({ foo: 'bar', baz: 123 }, 'SHA-512'); // => "d8f3c752c6820e580977099368083f4266b569660558..." ``` -------------------------------- ### Promise Races with Count (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Similar to `Promise.race`, but allows specifying the number of promises to wait for before resolving. It returns an array of the results from the first `n` promises that settle. ```typescript import { races } from 'moderndash'; const prom1 = Promise.resolve(1); const prom2 = new Promise(resolve => setTimeout(resolve, 100, 2)); const prom3 = Promise.resolve(3); const firstTwo = await races(2, prom1, prom2, prom3); // => [1, 3] ``` -------------------------------- ### Object Comparison and Type Checking in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md Functions like `isEmpty` and `isEqual` have been updated to support a wider range of data types, including typed arrays, buffers, and DataViews. This enhances their utility for complex data structures. ```javascript import { isEmpty, isEqual } from 'moderndash'; const typedArray = new Uint8Array([1, 2, 3]); console.log(isEmpty(typedArray)); // false const buffer = Buffer.from('test'); console.log(isEqual(buffer, Buffer.from('test'))); // true ``` -------------------------------- ### Object Path Manipulation in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md The `set` function has been improved with path autocomplete and correct return types, along with a fix for path validation. This enhances its reliability for nested object updates. ```javascript import { set } from 'moderndash'; let obj = { a: { b: 1 } }; set(obj, 'a.b', 2); console.log(obj); // { a: { b: 2 } } set(obj, 'c.d', 3); console.log(obj); // { a: { b: 2 }, c: { d: 3 } } ``` -------------------------------- ### Memoizing Function Results with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Creates a memoized version of a function. The results of previous calls are cached and returned directly if the function is called again with the same arguments. Supports an optional Time-To-Live (TTL) for cache entries and a custom resolver function to determine cache keys. This significantly improves performance for computationally expensive functions. ```typescript import { memoize } from 'moderndash'; function fibonacci(n: number): number { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } const memoizedFib = memoize(fibonacci, { ttl: 1000 }); memoizedFib(40); // => 102334155 memoizedFib(40); // => 102334155 (cache hit) setTimeout(() => memoizedFib(40), 1000); // => cache miss after TTL // Access cache directly memoizedFib.cache.get("[40]"); memoizedFib.cache.clear(); ``` -------------------------------- ### Try-Catch for Promises (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Attempts to execute a promise and returns a tuple containing either the resolved value or the caught error. This provides a convenient way to handle asynchronous operations with error checking. ```typescript import { tryCatch } from 'moderndash'; const [data, error] = await tryCatch(fetch('https://example.com/api')); if (error) { console.error(`Error: ${error.message}`); } else { console.log(data); } ``` -------------------------------- ### Function to Decorator Transformation (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Transforms a regular function into a decorator function, allowing it to be used with the @ syntax in TypeScript classes. This enables custom logic to be applied to methods. ```typescript import { toDecorator } from 'moderndash'; function log(func: Function, message: string) { return function (...args: unknown[]) { console.log(message); return func(...args); }; } const logger = toDecorator(log); class TestClass { @logger("Hello world!") testMethod() { return 1; } } const instance = new TestClass(); instance.testMethod(); // => Log "Hello World" and return 1 ``` -------------------------------- ### Calculating Median with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Finds the median value of a numerical array. The median is the middle value in a sorted list of numbers, or the average of the two middle values if the list has an even number of elements. This provides a robust measure of central tendency, less sensitive to outliers than the mean. ```typescript import { median } from 'moderndash'; median([1, 2, 3, 4, 5]); // => 3 median([1, 2, 3, 4, 5, 6]); // => 3.5 ``` -------------------------------- ### Array Manipulation Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Functions for manipulating arrays, including moving elements and conditionally dropping or taking elements. ```APIDOC ## move ### Description Moves an element within an array from one index to another. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { move } from 'moderndash'; move([1, 2, 3, 4, 5], 0, 2); // => [2, 3, 1, 4, 5] ``` ### Response N/A ## dropWhile / dropRightWhile ### Description Creates a slice of array excluding elements dropped from the beginning/end until predicate returns falsy. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { dropWhile, dropRightWhile } from 'moderndash'; const users = [ { user: 'barney', active: true }, { user: 'fred', active: true }, { user: 'pebbles', active: false } ]; dropWhile(users, user => user.active); // => [{ user: 'pebbles', active: false }] dropRightWhile(users, user => !user.active); // => [{ user: 'barney', active: true }, { user: 'fred', active: true }] ``` ### Response N/A ## takeWhile / takeRightWhile ### Description Creates a slice of array with elements taken from the beginning/end until predicate returns falsy. ### Method N/A (Function Signature) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { takeWhile, takeRightWhile } from 'moderndash'; const users = [ { user: 'barney', active: true }, { user: 'fred', active: true }, { user: 'pebbles', active: false } ]; takeWhile(users, user => user.active); // => [{ user: 'barney', active: true }, { user: 'fred', active: true }] takeRightWhile(users, user => !user.active); // => [{ user: 'pebbles', active: false }] ``` ### Response N/A ``` -------------------------------- ### String Trimming - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Provides functions to trim specified characters from the beginning, end, or both sides of a string. Supports trimming custom character sets. ```typescript import { trim, trimStart, trimEnd } from 'moderndash'; trim('$$abc$', '$'); // => 'abc' trim('!!abc_!', '_!'); // => 'abc' trimStart('$$$abc', '$'); // => 'abc' trimEnd('abc$$$', '$'); // => 'abc' ``` -------------------------------- ### Limiting Function Calls (Min) with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Creates a function that will only invoke the original function after it has been called a minimum number of times. Until the threshold is met, subsequent calls return undefined. This is useful for delaying an action until a certain number of confirmations or attempts. ```typescript import { minCalls } from 'moderndash'; const caution = () => console.log("Caution!"); const limitedCaution = minCalls(caution, 2); limitedCaution(); // => undefined limitedCaution(); // => undefined limitedCaution(); // => "Caution!" (invoked on third call) ``` -------------------------------- ### Setting Object Values by Path with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Sets a value at a specified path within an object. If any part of the path does not exist, it will be created. Supports dot notation for object properties and bracket notation for array indices. This is useful for deeply nested object updates. ```typescript import { set } from 'moderndash'; const obj = { a: { b: 2 } }; set(obj, 'a.c', 1); // => { a: { b: 2, c: 1 } } // Array notation set(obj, 'a.c[0]', 'hello'); // => { a: { b: 2, c: ['hello'] } } // Numbers with dots are treated as keys set(obj, 'a.c.0.d', 'world'); // => { a: { b: 2, c: { 0: { d: 'world' } } } ``` -------------------------------- ### Queue Class Enhancements in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md The `Queue` class now includes a `done()` function that resolves when the queue is empty. This provides a clear way to know when all queued operations have completed. ```javascript const queue = new Queue(); // ... add items to queue ... await queue.done(); // Queue is now empty and this promise resolves. ``` -------------------------------- ### isEmpty Validation Source: https://context7.com/maxdewald/moderndash/llms.txt Checks if a value is considered empty, supporting various data structures including collections and primitives. ```APIDOC ## isEmpty ### Description Checks if a value is empty. Supports strings, arrays, objects, maps, sets, and typed arrays. ### Usage `isEmpty(value: any): boolean` ### Parameters - **value** (any) - Required - The value to check for emptiness. ### Example ```typescript import { isEmpty } from 'moderndash'; isEmpty(null); // => true isEmpty([1, 2, 3]); // => false ``` ``` -------------------------------- ### Hash Function Optimization in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md The `hash` function has been optimized to only create a `TextEncoder` instance when it is actually needed, improving efficiency for scenarios where hashing is not always performed. ```javascript import { hash } from 'moderndash'; const data = 'some data'; const hashedData = hash(data); console.log(hashedData); ``` -------------------------------- ### Importing TypeScript Utility Types from ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt ModernDash provides several utility types for use in TypeScript projects, enhancing type safety and code completion. These types include definitions for arrays with minimum lengths, generic functions and objects, JSON-serializable data, and plain objects. ```typescript import type { ArrayMinLength, GenericFunction, GenericObject, Jsonifiable, PlainObject } from 'moderndash'; ``` -------------------------------- ### String Splitting with Regex in Moderndash Source: https://github.com/maxdewald/moderndash/blob/main/package/CHANGELOG.md The `splitWords` function utilizes regular expressions for improved performance and includes fallbacks for compatibility with older Safari versions. ```javascript import { splitWords } from 'moderndash'; const text = 'This is a test sentence.'; const words = splitWords(text); console.log(words); // ['This', 'is', 'a', 'test', 'sentence'] ``` -------------------------------- ### Random String Generation (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Generates a cryptographically secure random string of a specified length. An optional character set can be provided to define the pool of characters used in the generated string. ```typescript import { randomString } from 'moderndash'; randomString(8); // => "JWw1p6rD" randomString(16, 'abc'); // => "cbaacbabcabccabc" ``` -------------------------------- ### Count Array Items with ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Creates an object where keys are counts of items in an array based on a provided criteria function. This helps in summarizing array contents. ```typescript import { count } from 'moderndash'; const users = [ { user: 'barney', active: true, age: 36 }, { user: 'betty', active: false, age: 36 }, { user: 'fred', active: true, age: 40 } ]; count(users, value => value.active ? 'active' : 'inactive'); // => { 'active': 2, 'inactive': 1 } count(users, value => value.age); // => { 36: 2, 40: 1 } ``` -------------------------------- ### isEqual Deep Comparison Source: https://context7.com/maxdewald/moderndash/llms.txt Performs a deep comparison between two values to determine if they are equivalent. ```APIDOC ## isEqual ### Description Performs a deep comparison between two values. Supports primitives, arrays, objects, dates, regexes, maps, sets, buffers, and typed arrays. ### Usage `isEqual(value: any, other: any): boolean` ### Parameters - **value** (any) - Required - The first value to compare. - **other** (any) - Required - The second value to compare. ### Example ```typescript import { isEqual } from 'moderndash'; isEqual({ a: 1 }, { a: 1 }); // => true ``` ``` -------------------------------- ### Sort Array with ModernDash Source: https://context7.com/maxdewald/moderndash/llms.txt Creates a new array sorted in ascending or descending order based on single or multiple criteria. It allows for complex sorting logic using provided functions. ```typescript import { sort } from 'moderndash'; sort([1, 2, 3, 4], { order: 'desc' }); // => [4, 3, 2, 1] // Sorting by multiple properties const array = [{ a: 2, b: 1 }, { a: 1, b: 2 }, { a: 1, b: 1 }]; sort(array, { order: 'asc', by: item => item.a }, { order: 'desc', by: item => item.b } ); // => [{ a: 1, b: 2 }, { a: 1, b: 1 }, { a: 2, b: 1 }] ``` -------------------------------- ### HTML Entity Conversion - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Provides functions to convert strings to and from HTML entities. `escapeHtml` converts special characters to their HTML entity equivalents, and `unescapeHtml` reverses the process. ```typescript import { escapeHtml, unescapeHtml } from 'moderndash'; escapeHtml('fred, barney, & pebbles'); // => 'fred, barney, & pebbles' unescapeHtml('fred, barney, & pebbles'); // => 'fred, barney, & pebbles' ``` -------------------------------- ### Decorator Functions Source: https://context7.com/maxdewald/moderndash/llms.txt Decorator functions that can be applied to class methods in TypeScript. ```APIDOC ## decDebounce ### Description Debounces a decorated method. ### Method N/A (Decorator) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { decDebounce } from 'moderndash'; class TestClass { @decDebounce(100) testMethod(str: string) { console.log("Debounced:", str); } } const instance = new TestClass(); instance.testMethod("Hello"); instance.testMethod("World"); // => Only "Debounced: World" is logged after 100ms ``` ### Response N/A ``` -------------------------------- ### Throttle Decorator (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Applies throttling to a decorated method, ensuring it's called at most once within a specified time interval. This is useful for limiting the rate of function calls, such as in response to user input. ```typescript import { decThrottle } from 'moderndash'; class TestClass { @decThrottle(1000) testMethod() { console.log("Throttled!"); } } const instance = new TestClass(); instance.testMethod(); // => "Throttled!" instance.testMethod(); // => nothing happens (within throttle period) ``` -------------------------------- ### Repeating Function Execution with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Invokes a function a specified number of times, collecting the results into an array. The index of the current invocation is passed as an argument to the function. This is useful for generating arrays of data or performing repetitive tasks. ```typescript import { times } from 'moderndash'; times(index => console.log("Run", index), 3); // => "Run 0" | "Run 1" | "Run 2" times(Math.random, 3); // => [0.123, 0.456, 0.789] times(() => 0, 4); // => [0, 0, 0, 0] ``` -------------------------------- ### Random Integer Generation (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Generates a cryptographically secure random integer within a specified inclusive range. This is useful for security-sensitive applications requiring unpredictable numbers. ```typescript import { randomInt } from 'moderndash'; randomInt(1, 10); // => 5 (random integer between 1 and 10) ``` -------------------------------- ### Conditional Array Slicing (Take) - TypeScript Source: https://context7.com/maxdewald/moderndash/llms.txt Creates a new array by taking elements from the beginning or end of an array until a predicate function returns falsy. Supports both `takeWhile` and `takeRightWhile`. ```typescript import { takeWhile, takeRightWhile } from 'moderndash'; const users = [ { user: 'barney', active: true }, { user: 'fred', active: true }, { user: 'pebbles', active: false } ]; takeWhile(users, user => user.active); // => [{ user: 'barney', active: true }, { user: 'fred', active: true }] takeRightWhile(users, user => !user.active); // => [{ user: 'pebbles', active: false }] ``` -------------------------------- ### Retry Function for Promises (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Retries the execution of a given function (typically one returning a promise) until it succeeds or a maximum number of retries is reached. It supports configurable retry strategies, including backoff delays and on-retry callbacks. ```typescript import { retry } from 'moderndash'; await retry(() => fetch('https://example.com')); // Advanced example with options const fetchSite = async () => { const response = await fetch('https://example.com'); if (!response.ok) throw new Error('Failed to fetch'); }; const logger = (error: unknown, retry?: number) => console.log("Retrying", retry, error); await retry(fetchSite, { maxRetries: 3, backoff: retries => retries * 1000, onRetry: logger }); // => Retries 3 times with 1 second delay between each retry ``` -------------------------------- ### isPlainObject Validation Source: https://context7.com/maxdewald/moderndash/llms.txt Determines if a value is a plain object created by the Object constructor or an object literal. ```APIDOC ## isPlainObject ### Description Checks if the value is a plain object (created by Object constructor or object literal). ### Usage `isPlainObject(value: any): boolean` ### Parameters - **value** (any) - Required - The value to check. ### Example ```typescript import { isPlainObject } from 'moderndash'; isPlainObject({}); // => true isPlainObject(new Date()); // => false ``` ``` -------------------------------- ### Averaging Array Elements with Moderndash Source: https://context7.com/maxdewald/moderndash/llms.txt Computes the arithmetic mean (average) of the numbers in an array. This is useful for statistical analysis and understanding the central tendency of a dataset. ```typescript import { average } from 'moderndash'; average([1, 2, 3, 4, 5]); // => 3 ``` -------------------------------- ### Promise Timeout Wrapper (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Wraps a promise to reject with an error if it does not complete within a specified timeout period. This is crucial for preventing applications from hanging indefinitely due to unresponsive asynchronous operations. ```typescript import { timeout } from 'moderndash'; try { await timeout(fetch('https://example.com'), 1000); } catch (error) { console.log(error.message); // => 'Promise timed out after 1000ms' } ``` -------------------------------- ### Random Element Selection (TypeScript) Source: https://context7.com/maxdewald/moderndash/llms.txt Selects random element(s) from an array using cryptographically secure randomness. It can return a single element or multiple elements based on the provided count. ```typescript import { randomElem } from 'moderndash'; randomElem([1, 2, 3, 4]); // => 2 randomElem([1, 2, 3, 4], 2); // => [3, 1] ```