@metreeca/core - v0.9.11
    Preparing search index...

    Module order

    Composable comparison functions and combinators for sorting operations.

    Provides composable comparison functions for use with Array.sort() and other comparator-based operations.

    Usage

    import { ascending, descending, by, compound, nullish } from '@metreeca/core/comparators';

    // Basic sorting

    const numbers = [3, 1, 4, 1, 5];
    numbers.sort(ascending); // [1, 1, 3, 4, 5]
    numbers.sort(descending); // [5, 4, 3, 1, 1]

    // Sort by property

    const users = [
    { name: 'Bob', age: 25 },
    { name: 'Alice', age: 30 }
    ];

    users.sort(by(user => user.name)); // Sort by name ascending
    users.sort(by(user => user.age, descending)); // Sort by age descending

    // Combine multiple criteria

    const data = [
    { category: 'B', priority: 2 },
    { category: 'A', priority: 1 },
    { category: 'A', priority: 3 }
    ];

    data.sort(compound(
    by(item => item.category), // First by category
    by(item => item.priority) // Then by priority
    ));

    // Handle null/undefined values

    const values = [3, null, 1, undefined, 2];
    values.sort(nullish(ascending)); // [null, undefined, 1, 2, 3]

    Comparators

    Basic comparison functions for ascending and descending order.

    ascending

    Compares values in ascending order.

    descending

    Compares values in descending order.

    Factories

    Functions that create new comparators from selectors or transformations.

    by

    Creates a comparator that compares values by a selected key.

    Combinators

    Functions that modify or combine existing comparators.

    reverse

    Reverses the order of a comparator.

    nullish

    Wraps a comparator to handle null and undefined values.

    defined

    Wraps a comparator to handle null and undefined values.

    compound

    Combines multiple comparators into a single comparator.