|
| 1 | +/*** |
| 2 | +A built-in object that serves as a namespace for globally-unique identifiers. |
| 3 | +
|
| 4 | +Compiles to a regular JavaScript Symbol. |
| 5 | +*/ |
| 6 | + |
| 7 | +/** |
| 8 | +Type representing a Symbol. |
| 9 | +*/ |
| 10 | +type t |
| 11 | + |
| 12 | +/** |
| 13 | +`make(key)` |
| 14 | +
|
| 15 | +Makes a new unique Symbol value. |
| 16 | +
|
| 17 | +## Examples |
| 18 | +
|
| 19 | +```rescript |
| 20 | +let sym = Symbol.make("foo") |
| 21 | +``` |
| 22 | +*/ |
| 23 | +@val |
| 24 | +external make: string => t = "Symbol" |
| 25 | + |
| 26 | +/** |
| 27 | +`getFor(key)` |
| 28 | +
|
| 29 | +Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. |
| 30 | +Otherwise a new Symbol gets created and registered with key. |
| 31 | +
|
| 32 | +## Examples |
| 33 | +
|
| 34 | +```rescript |
| 35 | +let sym = Symbol.getFor("foo") |
| 36 | +``` |
| 37 | +*/ |
| 38 | +@val |
| 39 | +external getFor: string => t = "Symbol.for" |
| 40 | + |
| 41 | +/** |
| 42 | +`keyFor(key)` |
| 43 | +
|
| 44 | +Retrieves a shared Symbol key from the global Symbol registry for the given Symbol. |
| 45 | +
|
| 46 | +## Examples |
| 47 | +
|
| 48 | +```rescript |
| 49 | +let globalSym = Symbol.getFor("sym1") // Global symbol |
| 50 | +
|
| 51 | +Console.log(Symbol.keyFor(globalSym)) |
| 52 | +// Expected output: "sym1" |
| 53 | +
|
| 54 | +let localSym = Symbol.make("sym2") // Local symbol |
| 55 | +
|
| 56 | +Console.log(Symbol.keyFor(localSym)) |
| 57 | +// Expected output: undefined |
| 58 | +``` |
| 59 | +*/ |
| 60 | +@val |
| 61 | +external keyFor: t => option<string> = "Symbol.keyFor" |
| 62 | + |
| 63 | +/** |
| 64 | +`description` |
| 65 | +
|
| 66 | +Returns `Some(string)` containing the description of this symbol, or `None` if the symbol has no description. |
| 67 | +## Examples |
| 68 | +
|
| 69 | +```rescript |
| 70 | +let sym = Symbol.make("foo") |
| 71 | +Console.log(sym->Symbol.description) |
| 72 | +``` |
| 73 | +*/ |
| 74 | +@get |
| 75 | +external description: t => option<string> = "description" |
| 76 | + |
| 77 | +/** |
| 78 | +`toString` |
| 79 | +
|
| 80 | +// Returns a string representing this symbol value. |
| 81 | +
|
| 82 | +## Examples |
| 83 | +
|
| 84 | +```rescript |
| 85 | +let sym = Symbol.make("foo") |
| 86 | +Console.log(sym->Symbol.toString) |
| 87 | +// Expected output: "Symbol(foo)" |
| 88 | +``` |
| 89 | +*/ |
| 90 | +@send |
| 91 | +external toString: t => string = "toString" |
| 92 | + |
| 93 | +@val |
| 94 | +external asyncIterator: t = "Symbol.asyncIterator" |
| 95 | +@val |
| 96 | +external hasInstance: t = "Symbol.hasInstance" |
| 97 | +@val external isConcatSpreadable: t = "Symbol.isConcatSpreadable" |
| 98 | +@val external iterator: t = "Symbol.iterator" |
| 99 | +@val external match: t = "Symbol.match" |
| 100 | +@val external matchAll: t = "Symbol.matchAll" |
| 101 | +@val external replace: t = "Symbol.replace" |
| 102 | +@val external search: t = "Symbol.search" |
| 103 | +@val external species: t = "Symbol.species" |
| 104 | +@val external split: t = "Symbol.split" |
| 105 | +@val external toPrimitive: t = "Symbol.toPrimitive" |
| 106 | +@val external toStringTag: t = "Symbol.toStringTag" |
| 107 | +@val external unscopables: t = "Symbol.unscopables" |
0 commit comments