Skip to content

Commit 3ece36f

Browse files
authored
Merge pull request #101 from stephanoskomnenos/main
Update `URLSearchParams`
2 parents 5b1bcfb + 22f07df commit 3ece36f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/FetchAPI/URLSearchParams.res

+28
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ Deletes the given search parameter, and its associated value, from the list of a
3333
@send
3434
external delete: (urlSearchParams, ~name: string, ~value: string=?) => unit = "delete"
3535

36+
/**
37+
Returns key/value pairs in the same order as they appear in the query string.
38+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries)
39+
*/
40+
@send
41+
external entries: urlSearchParams => Iterator.t<(string, string)> = "entries"
42+
3643
/**
3744
Returns the first value associated to the given search parameter.
3845
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/get)
@@ -54,6 +61,13 @@ Returns a Boolean indicating if such a search parameter exists.
5461
@send
5562
external has: (urlSearchParams, ~name: string, ~value: string=?) => bool = "has"
5663

64+
/**
65+
Returns an iterator allowing iteration through all keys contained in this object.
66+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys)
67+
*/
68+
@send
69+
external keys: urlSearchParams => Iterator.t<string> = "keys"
70+
5771
/**
5872
Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
5973
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/set)
@@ -66,3 +80,17 @@ external set: (urlSearchParams, ~name: string, ~value: string) => unit = "set"
6680
*/
6781
@send
6882
external sort: urlSearchParams => unit = "sort"
83+
84+
/**
85+
Returns the query string suitable for use in a URL, without the question mark.
86+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/toString)
87+
*/
88+
@send
89+
external toString: urlSearchParams => string = "toString"
90+
91+
/**
92+
Returns an iterator allowing iteration through all values contained in this object.
93+
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams/values)
94+
*/
95+
@send
96+
external values: urlSearchParams => Iterator.t<string> = "values"

tests/FetchAPI/URLSearchParams__test.js

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let params1 = URLSearchParams.make3(~init="foo=1&bar=2")
2+
params1->URLSearchParams.keys->Iterator.toArray->Array.forEach(Console.log)
3+
4+
let params2 = URLSearchParams.make3(~init="?foo=1&bar=b")
5+
params2->URLSearchParams.values->Iterator.toArray->Array.forEach(Console.log)
6+
7+
let params3 = URLSearchParams.make3(~init="?foo=1&bar=b")
8+
params3
9+
->URLSearchParams.entries
10+
->Iterator.toArray
11+
->Array.forEach(((key, value)) => Console.log2(key, value))
12+
13+
let paramStr = params3->URLSearchParams.toString

0 commit comments

Comments
 (0)