From 388be3e0e1fcd5cfc184c2f41bb5e0a171b59097 Mon Sep 17 00:00:00 2001 From: Jang Rush Date: Sun, 18 Sep 2022 04:43:56 +0000 Subject: [PATCH] Update Js.String[2].match_ return type `Js.String2.match_` and `Js.String.match_` return type was changed in rescript-lang/rescript-compiler#5070 and released on 10.0.0. This commit updates the API documentation. close #551 --- pages/docs/manual/latest/api/js/string-2.mdx | 17 +++++++++-------- pages/docs/manual/latest/api/js/string.mdx | 10 +++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pages/docs/manual/latest/api/js/string-2.mdx b/pages/docs/manual/latest/api/js/string-2.mdx index 7d88129c4..fd007efd1 100644 --- a/pages/docs/manual/latest/api/js/string-2.mdx +++ b/pages/docs/manual/latest/api/js/string-2.mdx @@ -315,22 +315,23 @@ Js.String2.localeCompare("CAT", "cat") > 0.0 ## match ```res sig -let match_: (t, Js_re.t) => option> +let match_: (t, Js_re.t) => option>> ``` -`match(str, regexp)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: +`match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. +For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example -Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some(["bet"]) -Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some(["bet", "bat"]) -Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) == - Some(["2018-04-05", "2018", "04", "05"]) -Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None +Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")]) +Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")]) +Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) +Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None ``` + ## normalize ```res sig diff --git a/pages/docs/manual/latest/api/js/string.mdx b/pages/docs/manual/latest/api/js/string.mdx index 7e4eb846d..706eb1e35 100644 --- a/pages/docs/manual/latest/api/js/string.mdx +++ b/pages/docs/manual/latest/api/js/string.mdx @@ -315,19 +315,19 @@ Js.String.localeCompare("cat", "CAT") > 0.0 ## match ```res sig -let match_: (Js_re.t, t) => option> +let match_: (Js_re.t, t) => option>> ``` `match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains: - The entire matched string - Any capture groups if the regexp had parentheses -For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. +For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN. ```res example -Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"]) -Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"]) +Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")]) +Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")]) Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") == - Some(["2018-04-05", "2018", "04", "05"]) + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None ```