-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwell_known.ts
167 lines (152 loc) · 7.81 KB
/
well_known.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* @nevware21/ts-utils
* https://github.com/nevware21/ts-utils
*
* Copyright (c) 2022 NevWare21 Solutions LLC
* Licensed under the MIT license.
*/
import { createEnumKeyMap } from "../helpers/enum";
/**
* Identifies the Symbol static properties which are symbols themselves as a constant
* enum to aid in minification when fetching them from the global symbol implementation.
*
* See: [Well Known Symbols](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol#well-known_symbols)
* @group Symbol
*/
export const enum WellKnownSymbols {
/**
* The Symbol.asyncIterator symbol is a builtin symbol that is used to access an
* object's `Symbol.asyncIterator` method. In order for an object to be async iterable,
* it must have a Symbol.asyncIterator key.
*
* See: [Symbol.asyncIterator](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
*/
asyncIterator = 0,
/**
* The `Symbol.hasInstance` well-known symbol is used to determine if a constructor
* object recognizes an object as its instance. The instanceof operator's behavior
* can be customized by this symbol.
*
* See: [Symbol.hasInstance](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
*/
hasInstance = 1,
/**
* The `Symbol.isConcatSpreadable` symbol (Symbol.isConcatSpreadable) can be defined as an
* own or inherited property and its value is a boolean. It can control behavior for
* arrays and array-like objects:
* - For array objects, the default behavior is to spread (flatten) elements.
* Symbol.isConcatSpreadable can avoid flattening in these cases.
* - For array-like objects, the default behavior is no spreading or flattening.
* Symbol.isConcatSpreadable can force flattening in these cases.
*
* See: [Symbol.isConcatSpreadable](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
*/
isConcatSpreadable = 2,
/**
* Whenever an object needs to be iterated (such as at the beginning of a for..of loop),
* its `Symbol.iterator` method is called with no arguments, and the returned iterator is used
* to obtain the values to be iterated.
*
* See: [Symbol.iterator](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
*/
iterator = 3,
/**
* This function is also used to identify if objects have the behavior of regular expressions.
* For example, the methods String.prototype.startsWith(), String.prototype.endsWith() and
* String.prototype.includes(), check if their first argument is a regular expression and
* will throw a TypeError if they are. Now, if the match symbol is set to false (or a Falsy
* value), it indicates that the object is not intended to be used as a regular expression object.
*
* See: [Symbol.match](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
*/
match = 4,
/**
* The `Symbol.matchAll` well-known symbol returns an iterator, that yields matches of the regular
* expression against a string. This function is called by the String.prototype.matchAll() method.
*
* See: [Symbol.matchAll](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/matchAll)
*/
matchAll = 5,
/**
* The `Symbol.replace` well-known symbol specifies the method that replaces matched substrings
* of a string. This function is called by the String.prototype.replace() method.
*
* For more information, [RegExp.prototype[Symbol.replace]](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp/\@\@replace)()
* and [String.prototype.replace](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/replace)().
*
* See: [Symbol.replace](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
*/
replace = 6,
/**
* The `Symbol.search` well-known symbol specifies the method that returns the index within a
* string that matches the regular expression. This function is called by the
* [String.prototype.search()](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/search)
* method.
*
* For more information, see [RegExp.prototype[\@\@search]](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp/\@\@search)()
* and [String.prototype.search()](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/search).
*
* See: [Symbol.species](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
*/
search = 7,
/**
* The well-known symbol `Symbol.species` specifies a function-valued property that the constructor
* function uses to create derived objects.
* See: [Symbol.species](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
*/
species = 8,
/**
* The `Symbol.split` well-known symbol specifies the method that splits a string at the indices
* that match a regular expression. This function is called by the String.prototype.split() method.
*
* For more information, see [RegExp.prototype[\@\@split]](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp/\@\@split)()
* and [String.prototype.split()](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/split).
* See: [Symbol.split](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
*/
split = 9,
/**
* With the help of the `Symbol.toPrimitive` property (used as a function value), an object can be
* converted to a primitive value. The function is called with a string argument hint, which
* specifies the preferred type of the result primitive value. The hint argument can be one of
* "number", "string", and "default".
*
* See: [Symbol.toPrimitive](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
*/
toPrimitive = 10,
/**
* The `Symbol.toStringTag` well-known symbol is a string valued property that is used in the
* creation of the default string description of an object. It is accessed internally by the
* [Object.prototype.toString](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)()
* method.
*
* See: [Symbol.toStringTag](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag)
*/
toStringTag = 11,
/**
* The `Symbol.unscopables` well-known symbol is used to specify an object value of whose own
* and inherited property names are excluded from the with environment bindings of the associated
* object.
*
* See: [Symbol.unscopables](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
*/
unscopables = 12
}
/**
* @ignore
* @internal
*/
export const _wellKnownSymbolMap = /*#__PURE__*/createEnumKeyMap<typeof WellKnownSymbols>({
asyncIterator: WellKnownSymbols.asyncIterator,
hasInstance: WellKnownSymbols.hasInstance,
isConcatSpreadable: WellKnownSymbols.isConcatSpreadable,
iterator: WellKnownSymbols.iterator,
match: WellKnownSymbols.match,
matchAll: WellKnownSymbols.matchAll,
replace: WellKnownSymbols.replace,
search: WellKnownSymbols.search,
species: WellKnownSymbols.species,
split: WellKnownSymbols.split,
toPrimitive: WellKnownSymbols.toPrimitive,
toStringTag: WellKnownSymbols.toStringTag,
unscopables: WellKnownSymbols.unscopables
});