diff --git a/src/Core__String.res b/src/Core__String.res index 4d75467b..22db37b5 100644 --- a/src/Core__String.res +++ b/src/Core__String.res @@ -13,6 +13,7 @@ let compare = (a: string, b: string) => @get external length: string => int = "length" @get_index external get: (string, int) => option = "" +@get_index external getUnsafe: (string, int) => string = "" @send external charAt: (string, int) => string = "charAt" @send external charCodeAt: (string, int) => float = "charCodeAt" diff --git a/src/Core__String.resi b/src/Core__String.resi index 98b24971..7558adf8 100644 --- a/src/Core__String.resi +++ b/src/Core__String.resi @@ -150,6 +150,22 @@ String.get(`JS`, 4) == None @get_index external get: (string, int) => option = "" +/** +`getUnsafe(str, index)` returns an `string` at the given `index` number. + +This is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `string`. + +Use `String.getUnsafe` only when you are sure the `index` exists. +## Examples + +```rescript +String.getUnsafe("ReScript", 0) == "R" +String.getUnsafe("Hello", 4) == "o" +``` +*/ +@get_index +external getUnsafe: (string, int) => string = "" + /** `charAt(str, index)` gets the character at `index` within string `str`. If `index` is negative or greater than the length of `str`, it returns the empty