Neurophysiologically Pseudoscientific Manatee

    alphanum-compare
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    alphanum-compare

    npm version Node.js CI codecov Known Vulnerabilities FOSSA Status

    Compare function extrated from alphanum-sort. It can be used as compareFunction in Array.prototype.sort().

    Install

    yarn add alphanum-compare

    Usage

    import compareFn from "alphanum-compare";
    
    console.log("5".localeCompare("10")); // 1, NO GOOD
    console.log(compareFn("5", "10")); // -1, GOOD
    
    console.log(compareFn("-5", "5")); // 1, NO GOOD
    console.log(compareFn("-5", "5", { sign: true })); // -1, GOOD
    
    console.log(["item20", "item19", "item1", "item10", "item2"].sort(compareFn));
    // ['item1', 'item2', 'item10', 'item19', 'item20']

    CodeSandbox

    compareFn(a: number | string, b: number | string, opts?: Options): number

    It returns a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise.

    Options

    • insensitive?: boolean

      Compares items case insensitively. (Default: false)

    • sign?: boolean

      Allows + and - characters before numbers. (Default: false)

    License

    FOSSA Status

    Install

    npm i alphanum-compare

    DownloadsWeekly Downloads

    5

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    8.81 kB

    Total Files

    7

    Last publish

    Collaborators

    • tsekityam