|
| 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 | +Symbol.make("sym1") |
| 21 | +->Symbol.description |
| 22 | +->assertEqual(Some("sym1")) |
| 23 | +``` |
| 24 | +*/ |
| 25 | +@val |
| 26 | +external make: string => t = "Symbol" |
| 27 | + |
| 28 | +/** |
| 29 | +`getFor(key)` |
| 30 | + |
| 31 | +Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. |
| 32 | +Otherwise a new Symbol gets created and registered with key. |
| 33 | + |
| 34 | +## Examples |
| 35 | + |
| 36 | +```rescript |
| 37 | +Symbol.getFor("sym1")->assertEqual(Symbol.getFor("sym1")) |
| 38 | +``` |
| 39 | +*/ |
| 40 | +@val |
| 41 | +@scope("Symbol") |
| 42 | +external getFor: string => option<t> = "for" |
| 43 | + |
| 44 | +/** |
| 45 | +`keyFor(key)` |
| 46 | + |
| 47 | +Retrieves a shared Symbol key from the global Symbol registry for the given Symbol. |
| 48 | + |
| 49 | +## Examples |
| 50 | + |
| 51 | +```rescript |
| 52 | +let globalSym = Symbol.getFor("sym1") // Global symbol |
| 53 | + |
| 54 | +globalSym->Option.flatMap(Symbol.description)->assertEqual(Some("sym1")) |
| 55 | +``` |
| 56 | +*/ |
| 57 | +@val |
| 58 | +@scope("Symbol") |
| 59 | +external keyFor: t => option<string> = "keyFor" |
| 60 | + |
| 61 | +/** |
| 62 | +`description` |
| 63 | + |
| 64 | +Returns `Some(string)` containing the description of this symbol, or `None` if the symbol has no description. |
| 65 | +## Examples |
| 66 | + |
| 67 | +```rescript |
| 68 | +let sym = Symbol.make("sym1") |
| 69 | +Symbol.description(sym)->assertEqual(Some("sym1")) |
| 70 | +``` |
| 71 | +*/ |
| 72 | +@get |
| 73 | +external description: t => option<string> = "description" |
| 74 | + |
| 75 | +/** |
| 76 | +`toString` |
| 77 | + |
| 78 | +// Returns a string representing this symbol value. |
| 79 | + |
| 80 | +## Examples |
| 81 | + |
| 82 | +```rescript |
| 83 | +let sym = Symbol.make("sym1") |
| 84 | + |
| 85 | +Symbol.toString(sym)->assertEqual("Symbol(sym1)") |
| 86 | +``` |
| 87 | +*/ |
| 88 | +@send |
| 89 | +external toString: t => string = "toString" |
| 90 | + |
| 91 | +@val @scope("Symbol") |
| 92 | +external asyncIterator: t = "asyncIterator" |
| 93 | +@val @scope("Symbol") |
| 94 | +external hasInstance: t = "hasInstance" |
| 95 | +@val @scope("Symbol") external isConcatSpreadable: t = "isConcatSpreadable" |
| 96 | +@val @scope("Symbol") external iterator: t = "iterator" |
| 97 | +@val @scope("Symbol") external match: t = "match" |
| 98 | +@val @scope("Symbol") external matchAll: t = "matchAll" |
| 99 | +@val @scope("Symbol") external replace: t = "replace" |
| 100 | +@val @scope("Symbol") external search: t = "search" |
| 101 | +@val @scope("Symbol") external species: t = "species" |
| 102 | +@val @scope("Symbol") external split: t = "split" |
| 103 | +@val @scope("Symbol") external toPrimitive: t = "toPrimitive" |
| 104 | +@val @scope("Symbol") external toStringTag: t = "toStringTag" |
| 105 | +@val @scope("Symbol") external unscopables: t = "unscopables" |
0 commit comments