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: Revert "feat: replace qs node API with URLSearchParams web api" #485

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

t-col
Copy link
Contributor

@t-col t-col commented Jul 3, 2024

This reverts commit 8020f4e.

URLSearchParams does not stringify nested objects

@t-col t-col requested a review from a team as a code owner July 3, 2024 22:49
@t-col t-col changed the title Revert "feat: replace qs node API with URLSearchParams web api" fix: Revert "feat: replace qs node API with URLSearchParams web api" Jul 3, 2024
@t-col t-col merged commit 538983a into master Jul 3, 2024
4 of 5 checks passed
@t-col t-col deleted the fix/paramsSerializer branch July 3, 2024 22:50
t-col added a commit that referenced this pull request Jul 3, 2024
This reverts commit 8020f4e.

URLSearchParams does not stringify nested objects
@wojtekmaj
Copy link

wojtekmaj commented Jul 10, 2024

Maybe we could give this another go? It shouldn't be too complex to build something of our own. For example:

function stringify(obj) {
    function stringifyInner(obj, parentKey) {
        return Object.entries(obj).flatMap(([key, value]) => {
            const fullKey = `${parentKey}[${key}]`;
            if (typeof value === 'object') return stringifyInner(value, fullKey)
            return [[fullKey, value]]
        })
    }

    return new URLSearchParams(Object.entries(obj).flatMap(([k, v]) => {
        if (typeof v === 'object') return stringifyInner(v, k)
        return [[k, v]]
    }));
}

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.

2 participants