Skip to content

Add missing docstring for String #7571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion runtime/Stdlib_String.resi
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,30 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
@variadic @val
external fromCodePointMany: array<int> => string = "String.fromCodePoint"

/**
`equal(str1, str2)` checks if two strings are equal.

## Examples

```rescript
String.equal("hello", "hello") == true
String.equal("hello", "world") == false
String.equal("", "") == true
```
*/
external equal: (string, string) => bool = "%equal"

/**
`compare(str1, str2)` compares two strings, returns an `Ordering.t` value.

## Examples

```rescript
String.compare("hello", "hello") == Ordering.equal
String.compare("apple", "banana") == Ordering.less
String.compare("zebra", "apple") == Ordering.greater
```
*/
external compare: (string, string) => Stdlib_Ordering.t = "%compare"

/**
Expand Down Expand Up @@ -1090,9 +1112,48 @@ String.padEnd("abc", 1, "") == "abc"
@send
external padEnd: (string, int, string) => string = "padEnd"

// TODO: add docs
/**
`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`.
Returns `None` if the symbol property doesn't exist.

## Examples

```rescript
let h = String.make("hello")
let symbol = String.getSymbol(h, Symbol.iterator)
Option.isSome(symbol) == true
```
*/
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""

/**
`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string.

This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist.

## Examples

```rescript
let h = String.make("hello")
// This does required direct access to the symbol property
// Storing the iterator in a variable first, will not work.
String.getSymbolUnsafe(h, Symbol.iterator)()->Iterator.toArray->Array.length == 5
```
*/
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""

/**
`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.

## Examples

```rescript
let mySymbol = Symbol.make("test")
let h = %raw(`new String("hello")`)
String.setSymbol(h, mySymbol, 42)
String.getSymbol(h, mySymbol) == Some(42)
```
*/
@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = ""

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ Path s
"kind": 12,
"tags": [],
"detail": "(string, Symbol.t, 'a) => unit",
"documentation": null,
"documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = %raw(`new String(\"hello\")`)\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"},
"sortText": "setSymbol",
"insertText": "->String.setSymbol",
"additionalTextEdits": [{
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/core/Test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function print(value) {
} else if (match === "string") {
return Stdlib_Option.getExn(JSON.stringify(value), undefined);
} else {
return String(value);
return new String(value);
}
}

Expand Down
Loading