Skip to content

Commit a991569

Browse files
committed
Add missing docstring for String
1 parent 75afc52 commit a991569

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

runtime/Stdlib_String.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type t = string
22

3-
@val external make: 'a => string = "String"
3+
@new external make: 'a => string = "String"
44

55
@val external fromCharCode: int => string = "String.fromCharCode"
66
@variadic @val external fromCharCodeMany: array<int> => string = "String.fromCharCode"

runtime/Stdlib_String.resi

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ String.make(3.5) == "3.5"
4242
String.make([1, 2, 3]) == "1,2,3"
4343
```
4444
*/
45-
@val
45+
@new
4646
external make: 'a => string = "String"
4747

4848
/**
@@ -121,8 +121,30 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
121121
@variadic @val
122122
external fromCodePointMany: array<int> => string = "String.fromCodePoint"
123123

124+
/**
125+
`equal(str1, str2)` checks if two strings are equal.
126+
127+
## Examples
128+
129+
```rescript
130+
String.equal("hello", "hello") == true
131+
String.equal("hello", "world") == false
132+
String.equal("", "") == true
133+
```
134+
*/
124135
external equal: (string, string) => bool = "%equal"
125136

137+
/**
138+
`compare(str1, str2)` compares two strings, returns an `Ordering.t` value.
139+
140+
## Examples
141+
142+
```rescript
143+
String.compare("hello", "hello") == Ordering.equal
144+
String.compare("apple", "banana") == Ordering.less
145+
String.compare("zebra", "apple") == Ordering.greater
146+
```
147+
*/
126148
external compare: (string, string) => Stdlib_Ordering.t = "%compare"
127149

128150
/**
@@ -1090,9 +1112,49 @@ String.padEnd("abc", 1, "") == "abc"
10901112
@send
10911113
external padEnd: (string, int, string) => string = "padEnd"
10921114

1093-
// TODO: add docs
1115+
/**
1116+
`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`.
1117+
Returns `None` if the symbol property doesn't exist.
1118+
1119+
## Examples
1120+
1121+
```rescript
1122+
let mySymbol = Symbol.make("test")
1123+
let h = String.make("hello")
1124+
String.setSymbol(h, mySymbol, 42)
1125+
String.getSymbol(h, mySymbol) == Some(42)
1126+
```
1127+
*/
10941128
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""
1129+
1130+
/**
1131+
`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string.
1132+
1133+
This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist.
1134+
1135+
## Examples
1136+
1137+
```rescript
1138+
let mySymbol = Symbol.make("test")
1139+
let h = String.make("hello")
1140+
String.setSymbol(h, mySymbol, 43)
1141+
String.getSymbolUnsafe(h, mySymbol) == 43
1142+
```
1143+
*/
10951144
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""
1145+
1146+
/**
1147+
`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.
1148+
1149+
## Examples
1150+
1151+
```rescript
1152+
let mySymbol = Symbol.make("test")
1153+
let h = String.make("hello")
1154+
String.setSymbol(h, mySymbol, 42)
1155+
String.getSymbol(h, mySymbol) == Some(42)
1156+
```
1157+
*/
10961158
@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = ""
10971159

10981160
/**

0 commit comments

Comments
 (0)