alii / pathcat

Simply path/URL building in JavaScript
https://npm.im/pathcat
The Unlicense
173 stars 1 forks source link

feat: add array support for query value (#1) #2

Closed AntoineKM closed 2 months ago

AntoineKM commented 2 months ago

What did I change? I've separated ParamValue and QueryValue, which can be an array.

We can now do:

pathcat("https://example.com", "/:id", {
    id: "123",
    foo: ["b", "a", "r"],
});
// => 'https://example.com/123?foo=b&foo=a&foo=r'

And typescript will throw an error if used this way:

pathcat("https://example.com", "/:id", {
    id: ["1", "2", "3"], // cannot be an array
    foo: ["b", "a", "r"], // can be an array
});

Why did I change it? This package is great, but it's true that query params can be arrays, and it can be interesting in some cases to be able to benefit from these advantages.

alii commented 2 months ago

Super thank you, do you think you would be able to add something to the README as well just to explain that arrays are supported? Glad you are able to make good use of the lib :)

AntoineKM commented 2 months ago

Of course, it should be good now 😁

alii commented 2 months ago

Perfect, will release this now. thanks so much for the contribution!