Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issues #85 #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

bluelovers
Copy link

#85

@@ -7,6 +7,7 @@
*/

var type = require('type-detect');
var compareFn = require('default-compare-with-symbol').defaultCompareWithSymbol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new dependency also introduces some other transitive dependencies which themselves seem to do the stuff we already have (kind-of looks a lot like type-detect), so I'm a little hesitant to introduce this. If anything I'd like to work on reducing the type-detect dependency as I'm not totally convinced it's necessary with modern engines.

To fix #85 issue it seems as though we could use .toString() instead, or perhaps a try/catch.

Copy link

@Tofandel Tofandel Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keithamus I'm hitting the same issue but with actual symbols, not just urls

I don't see any dependencies to default-compare-with-symbol in fact the code is also quite small
https://www.npmjs.com/package/default-compare-with-symbol?activeTab=dependencies

Worst case we can just make the function in the lib, this is exactly what the dep does:

function defaultCompare(a, b) {
    const typeA = a === null ? 'null' : typeof a;
    const typeB = b === null ? 'null' : typeof b;
    if (typeA === 'null' || typeA === 'undefined') {
        switch (typeB) {
            case typeA:
                return 0;
            case 'null':
                return -1;
            default:
                return 1;
        }
    }
    switch (true) {
        case a < b:
            return -1;
        case a > b:
            return 1;
    }

    return 0;
}

function extendedCompare(a, b) {
    const typeB = typeof b;
    if (typeof a === 'symbol') {
        return typeB === 'symbol' ? defaultCompare(String(a), String(b)) : -1;
    } else if (typeB === 'symbol') {
        return 1;
    }

    return defaultCompare(a, b)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants