@nejs/basic-extensions 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.esdoc.json +9 -0
- package/README.md +2025 -11
- package/bin/clean +6 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js +4 -0
- package/dist/@nejs/basic-extensions.bundle.1.6.1.js.map +7 -0
- package/dist/cjs/arrayextensions.js +1 -0
- package/dist/cjs/arrayextensions.js.map +1 -0
- package/dist/cjs/functionextensions.js +1 -0
- package/dist/cjs/functionextensions.js.map +1 -0
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/globals.js.map +1 -0
- package/dist/cjs/index.d.ts +10 -19
- package/dist/cjs/index.js +69 -76
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mapextensions.d.ts +2 -0
- package/dist/cjs/mapextensions.js +30 -0
- package/dist/cjs/mapextensions.js.map +1 -0
- package/dist/cjs/newClasses/asyncIterable.d.ts +123 -0
- package/dist/cjs/{asyncIterable.js → newClasses/asyncIterable.js} +7 -4
- package/dist/cjs/newClasses/asyncIterable.js.map +1 -0
- package/dist/cjs/newClasses/descriptor.d.ts +401 -0
- package/dist/cjs/{descriptor.js → newClasses/descriptor.js} +150 -80
- package/dist/cjs/newClasses/descriptor.js.map +1 -0
- package/dist/cjs/newClasses/iterable.d.ts +125 -0
- package/dist/cjs/{iterable.js → newClasses/iterable.js} +36 -10
- package/dist/cjs/newClasses/iterable.js.map +1 -0
- package/dist/cjs/newClasses/refmap.d.ts +238 -0
- package/dist/cjs/newClasses/refmap.js +433 -0
- package/dist/cjs/newClasses/refmap.js.map +1 -0
- package/dist/cjs/newClasses/refset.d.ts +186 -0
- package/dist/cjs/{refset.js → newClasses/refset.js} +18 -3
- package/dist/cjs/newClasses/refset.js.map +1 -0
- package/dist/cjs/objectextensions.d.ts +7 -6
- package/dist/cjs/objectextensions.js +85 -43
- package/dist/cjs/objectextensions.js.map +1 -0
- package/dist/cjs/reflectextensions.js +16 -12
- package/dist/cjs/reflectextensions.js.map +1 -0
- package/dist/cjs/stringextensions.js +1 -0
- package/dist/cjs/stringextensions.js.map +1 -0
- package/dist/cjs/symbolextensions.js +3 -1
- package/dist/cjs/symbolextensions.js.map +1 -0
- package/dist/cjs/weakrefextensions.js +1 -0
- package/dist/cjs/weakrefextensions.js.map +1 -0
- package/dist/mjs/arrayextensions.js +1 -0
- package/dist/mjs/arrayextensions.js.map +1 -0
- package/dist/mjs/functionextensions.js +1 -0
- package/dist/mjs/functionextensions.js.map +1 -0
- package/dist/mjs/globals.js +2 -1
- package/dist/mjs/globals.js.map +1 -0
- package/dist/mjs/index.d.ts +10 -19
- package/dist/mjs/index.js +67 -60
- package/dist/mjs/index.js.map +1 -0
- package/dist/mjs/mapextensions.d.ts +2 -0
- package/dist/mjs/mapextensions.js +27 -0
- package/dist/mjs/mapextensions.js.map +1 -0
- package/dist/mjs/newClasses/asyncIterable.d.ts +123 -0
- package/dist/mjs/{asyncIterable.js → newClasses/asyncIterable.js} +106 -105
- package/dist/mjs/newClasses/asyncIterable.js.map +1 -0
- package/dist/mjs/newClasses/descriptor.d.ts +401 -0
- package/dist/mjs/{descriptor.js → newClasses/descriptor.js} +129 -67
- package/dist/mjs/newClasses/descriptor.js.map +1 -0
- package/dist/mjs/newClasses/iterable.d.ts +125 -0
- package/dist/mjs/newClasses/iterable.js +199 -0
- package/dist/mjs/newClasses/iterable.js.map +1 -0
- package/dist/mjs/newClasses/refmap.d.ts +238 -0
- package/dist/mjs/newClasses/refmap.js +417 -0
- package/dist/mjs/newClasses/refmap.js.map +1 -0
- package/dist/mjs/newClasses/refset.d.ts +186 -0
- package/dist/mjs/{refset.js → newClasses/refset.js} +17 -3
- package/dist/mjs/newClasses/refset.js.map +1 -0
- package/dist/mjs/objectextensions.d.ts +7 -6
- package/dist/mjs/objectextensions.js +84 -42
- package/dist/mjs/objectextensions.js.map +1 -0
- package/dist/mjs/reflectextensions.js +16 -12
- package/dist/mjs/reflectextensions.js.map +1 -0
- package/dist/mjs/stringextensions.js +1 -0
- package/dist/mjs/stringextensions.js.map +1 -0
- package/dist/mjs/symbolextensions.js +3 -1
- package/dist/mjs/symbolextensions.js.map +1 -0
- package/dist/mjs/weakrefextensions.js +1 -0
- package/dist/mjs/weakrefextensions.js.map +1 -0
- package/docs/assets/anchor.js +350 -0
- package/docs/assets/bass-addons.css +12 -0
- package/docs/assets/bass.css +544 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/docs/assets/fonts/LICENSE.txt +93 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/docs/assets/fonts/source-code-pro.css +23 -0
- package/docs/assets/github.css +123 -0
- package/docs/assets/site.js +168 -0
- package/docs/assets/split.css +15 -0
- package/docs/assets/split.js +782 -0
- package/docs/assets/style.css +147 -0
- package/docs/index.html +13060 -0
- package/jsdoc-config.json +31 -0
- package/package.json +12 -3
- package/src/globals.js +1 -1
- package/src/index.js +75 -82
- package/src/mapextensions.js +30 -0
- package/src/{asyncIterable.js → newClasses/asyncIterable.js} +117 -117
- package/src/{descriptor.js → newClasses/descriptor.js} +137 -74
- package/src/newClasses/iterable.js +221 -0
- package/src/newClasses/refmap.js +483 -0
- package/src/{refset.js → newClasses/refset.js} +29 -16
- package/src/objectextensions.js +97 -46
- package/src/reflectextensions.js +16 -14
- package/src/symbolextensions.js +2 -1
- package/tests/index.test.js +1 -1
- package/tests/{asyncIterable.test.js → newClasses/asyncIterable.test.js} +3 -4
- package/tests/newClasses/descriptor.test.js +252 -0
- package/tests/{iterable.test.js → newClasses/iterable.test.js} +2 -4
- package/tests/newClasses/refmap.test.js +69 -0
- package/tests/{refset.test.js → newClasses/refset.test.js} +2 -4
- package/tests/objectextensions.test.js +128 -0
- package/tsconfig.base.json +2 -1
- package/dist/@nejs/basic-extensions.bundle.1.5.1.js +0 -2
- package/dist/@nejs/basic-extensions.bundle.1.5.1.js.map +0 -7
- package/dist/cjs/asyncIterable.d.ts +0 -3
- package/dist/cjs/descriptor.d.ts +0 -2
- package/dist/cjs/iterable.d.ts +0 -3
- package/dist/cjs/refset.d.ts +0 -2
- package/dist/mjs/asyncIterable.d.ts +0 -3
- package/dist/mjs/descriptor.d.ts +0 -2
- package/dist/mjs/iterable.d.ts +0 -3
- package/dist/mjs/iterable.js +0 -184
- package/dist/mjs/refset.d.ts +0 -2
- package/src/iterable.js +0 -203
package/README.md
CHANGED
|
@@ -9,17 +9,17 @@ additional utility methods for common tasks and improving code readability and e
|
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
* **Array Extensions**: Adds convenience methods to JavaScript arrays, like `first` and `last`,
|
|
13
|
+
for easy access to the first and last elements.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
* **Object Extensions**: Introduces utility functions to the Object class, such as methods for
|
|
16
|
+
checking object types and manipulating properties.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
* **Function Extensions**: Enriches the Function class with methods to identify function types,
|
|
19
|
+
such as arrow functions, async functions, and bound functions.
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
* **Reflect Extensions**: Extends the Reflect object with advanced property interaction methods,
|
|
22
|
+
including checks for the presence of multiple or specific keys.
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
@@ -49,10 +49,2024 @@ import { FunctionExtensions } from '@nejs/basic-extensions';
|
|
|
49
49
|
// Use the Function extensions
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
##
|
|
52
|
+
## API
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
55
|
+
|
|
56
|
+
#### Table of Contents
|
|
57
|
+
|
|
58
|
+
* [FunctionExtensions](#functionextensions)
|
|
59
|
+
* [isClass](#isclass)
|
|
60
|
+
* [Parameters](#parameters)
|
|
61
|
+
* [isFunction](#isfunction)
|
|
62
|
+
* [Parameters](#parameters-1)
|
|
63
|
+
* [isAsync](#isasync)
|
|
64
|
+
* [Parameters](#parameters-2)
|
|
65
|
+
* [isBigArrow](#isbigarrow)
|
|
66
|
+
* [Parameters](#parameters-3)
|
|
67
|
+
* [isBound](#isbound)
|
|
68
|
+
* [Parameters](#parameters-4)
|
|
69
|
+
* [ObjectExtensions](#objectextensions)
|
|
70
|
+
* [isNullDefined](#isnulldefined)
|
|
71
|
+
* [Parameters](#parameters-5)
|
|
72
|
+
* [hasStringTag](#hasstringtag)
|
|
73
|
+
* [Parameters](#parameters-6)
|
|
74
|
+
* [getStringTag](#getstringtag)
|
|
75
|
+
* [Parameters](#parameters-7)
|
|
76
|
+
* [getType](#gettype)
|
|
77
|
+
* [Parameters](#parameters-8)
|
|
78
|
+
* [isObject](#isobject)
|
|
79
|
+
* [Parameters](#parameters-9)
|
|
80
|
+
* [isPrimitive](#isprimitive)
|
|
81
|
+
* [Parameters](#parameters-10)
|
|
82
|
+
* [isValidKey](#isvalidkey)
|
|
83
|
+
* [Parameters](#parameters-11)
|
|
84
|
+
* [stripTo](#stripto)
|
|
85
|
+
* [Parameters](#parameters-12)
|
|
86
|
+
* [stripTo](#stripto-1)
|
|
87
|
+
* [Parameters](#parameters-13)
|
|
88
|
+
* [getKey](#getkey)
|
|
89
|
+
* [Parameters](#parameters-14)
|
|
90
|
+
* [ReflectExtensions](#reflectextensions)
|
|
91
|
+
* [hasAll](#hasall)
|
|
92
|
+
* [Parameters](#parameters-15)
|
|
93
|
+
* [ownDescriptors](#owndescriptors)
|
|
94
|
+
* [Parameters](#parameters-16)
|
|
95
|
+
* [hasSome](#hassome)
|
|
96
|
+
* [Parameters](#parameters-17)
|
|
97
|
+
* [entries](#entries)
|
|
98
|
+
* [Parameters](#parameters-18)
|
|
99
|
+
* [values](#values)
|
|
100
|
+
* [Parameters](#parameters-19)
|
|
101
|
+
* [StringExtensions](#stringextensions)
|
|
102
|
+
* [isString](#isstring)
|
|
103
|
+
* [Parameters](#parameters-20)
|
|
104
|
+
* [SymbolExtensions](#symbolextensions)
|
|
105
|
+
* [isSymbol](#issymbol)
|
|
106
|
+
* [Parameters](#parameters-21)
|
|
107
|
+
* [isRegistered](#isregistered)
|
|
108
|
+
* [Parameters](#parameters-22)
|
|
109
|
+
* [isNonRegistered](#isnonregistered)
|
|
110
|
+
* [Parameters](#parameters-23)
|
|
111
|
+
* [ArrayPrototypeExtensions](#arrayprototypeextensions)
|
|
112
|
+
* [contains](#contains)
|
|
113
|
+
* [Parameters](#parameters-24)
|
|
114
|
+
* [findEntry](#findentry)
|
|
115
|
+
* [Parameters](#parameters-25)
|
|
116
|
+
* [first](#first)
|
|
117
|
+
* [last](#last)
|
|
118
|
+
* [object](#object)
|
|
119
|
+
* [constructor](#constructor)
|
|
120
|
+
* [Parameters](#parameters-26)
|
|
121
|
+
* [isAccessor](#isaccessor)
|
|
122
|
+
* [isData](#isdata)
|
|
123
|
+
* [isDescriptor](#isdescriptor)
|
|
124
|
+
* [configurable](#configurable)
|
|
125
|
+
* [configurable](#configurable-1)
|
|
126
|
+
* [Parameters](#parameters-27)
|
|
127
|
+
* [enumerable](#enumerable)
|
|
128
|
+
* [enumerable](#enumerable-1)
|
|
129
|
+
* [Parameters](#parameters-28)
|
|
130
|
+
* [writable](#writable)
|
|
131
|
+
* [writable](#writable-1)
|
|
132
|
+
* [Parameters](#parameters-29)
|
|
133
|
+
* [value](#value)
|
|
134
|
+
* [value](#value-1)
|
|
135
|
+
* [Parameters](#parameters-30)
|
|
136
|
+
* [get](#get)
|
|
137
|
+
* [get](#get-1)
|
|
138
|
+
* [Parameters](#parameters-31)
|
|
139
|
+
* [boundGet](#boundget)
|
|
140
|
+
* [set](#set)
|
|
141
|
+
* [set](#set-1)
|
|
142
|
+
* [Parameters](#parameters-32)
|
|
143
|
+
* [boundSet](#boundset)
|
|
144
|
+
* [hasObject](#hasobject)
|
|
145
|
+
* [object](#object-1)
|
|
146
|
+
* [object](#object-2)
|
|
147
|
+
* [Parameters](#parameters-33)
|
|
148
|
+
* [for](#for)
|
|
149
|
+
* [Parameters](#parameters-34)
|
|
150
|
+
* [applyTo](#applyto)
|
|
151
|
+
* [Parameters](#parameters-35)
|
|
152
|
+
* [toPrimitive](#toprimitive)
|
|
153
|
+
* [Parameters](#parameters-36)
|
|
154
|
+
* [toStringTag](#tostringtag)
|
|
155
|
+
* [for](#for-1)
|
|
156
|
+
* [Parameters](#parameters-37)
|
|
157
|
+
* [getData](#getdata)
|
|
158
|
+
* [Parameters](#parameters-38)
|
|
159
|
+
* [getAccessor](#getaccessor)
|
|
160
|
+
* [Parameters](#parameters-39)
|
|
161
|
+
* [base](#base)
|
|
162
|
+
* [Parameters](#parameters-40)
|
|
163
|
+
* [accessor](#accessor)
|
|
164
|
+
* [Parameters](#parameters-41)
|
|
165
|
+
* [data](#data)
|
|
166
|
+
* [Parameters](#parameters-42)
|
|
167
|
+
* [isDescriptor](#isdescriptor-1)
|
|
168
|
+
* [Parameters](#parameters-43)
|
|
169
|
+
* [isData](#isdata-1)
|
|
170
|
+
* [Parameters](#parameters-44)
|
|
171
|
+
* [isAccessor](#isaccessor-1)
|
|
172
|
+
* [Parameters](#parameters-45)
|
|
173
|
+
* [flexible](#flexible)
|
|
174
|
+
* [enigmatic](#enigmatic)
|
|
175
|
+
* [intrinsic](#intrinsic)
|
|
176
|
+
* [transparent](#transparent)
|
|
177
|
+
* [SHARED\_KEYS](#shared_keys)
|
|
178
|
+
* [ACCESSOR\_KEYS](#accessor_keys)
|
|
179
|
+
* [DATA\_KEYS](#data_keys)
|
|
180
|
+
* [maskAs](#maskas)
|
|
181
|
+
* [Parameters](#parameters-46)
|
|
182
|
+
* [maskAsString](#maskasstring)
|
|
183
|
+
* [Parameters](#parameters-47)
|
|
184
|
+
* [maskAsNumber](#maskasnumber)
|
|
185
|
+
* [Parameters](#parameters-48)
|
|
186
|
+
* [GenericMask](#genericmask)
|
|
187
|
+
* [Parameters](#parameters-49)
|
|
188
|
+
* [StringMask](#stringmask)
|
|
189
|
+
* [Parameters](#parameters-50)
|
|
190
|
+
* [NumberMask](#numbermask)
|
|
191
|
+
* [Parameters](#parameters-51)
|
|
192
|
+
* [RefSet](#refset)
|
|
193
|
+
* [objectifying](#objectifying)
|
|
194
|
+
* [Parameters](#parameters-52)
|
|
195
|
+
* [objectifyValues](#objectifyvalues)
|
|
196
|
+
* [objectifyValues](#objectifyvalues-1)
|
|
197
|
+
* [Parameters](#parameters-53)
|
|
198
|
+
* [add](#add)
|
|
199
|
+
* [Parameters](#parameters-54)
|
|
200
|
+
* [addAll](#addall)
|
|
201
|
+
* [Parameters](#parameters-55)
|
|
202
|
+
* [clean](#clean)
|
|
203
|
+
* [entries](#entries-1)
|
|
204
|
+
* [Parameters](#parameters-56)
|
|
205
|
+
* [forEach](#foreach)
|
|
206
|
+
* [Parameters](#parameters-57)
|
|
207
|
+
* [values](#values-1)
|
|
208
|
+
* [keys](#keys)
|
|
209
|
+
* [has](#has)
|
|
210
|
+
* [Parameters](#parameters-58)
|
|
211
|
+
* [contains](#contains-1)
|
|
212
|
+
* [Parameters](#parameters-59)
|
|
213
|
+
* [filter](#filter)
|
|
214
|
+
* [Parameters](#parameters-60)
|
|
215
|
+
* [find](#find)
|
|
216
|
+
* [Parameters](#parameters-61)
|
|
217
|
+
* [map](#map)
|
|
218
|
+
* [Parameters](#parameters-62)
|
|
219
|
+
* [toStringTag](#tostringtag-1)
|
|
220
|
+
* [RefMap](#refmap)
|
|
221
|
+
* [Parameters](#parameters-63)
|
|
222
|
+
* [objectifying](#objectifying-1)
|
|
223
|
+
* [Parameters](#parameters-64)
|
|
224
|
+
* [asObject](#asobject)
|
|
225
|
+
* [objectifyValues](#objectifyvalues-2)
|
|
226
|
+
* [objectifyValues](#objectifyvalues-3)
|
|
227
|
+
* [Parameters](#parameters-65)
|
|
228
|
+
* [get](#get-2)
|
|
229
|
+
* [Parameters](#parameters-66)
|
|
230
|
+
* [set](#set-2)
|
|
231
|
+
* [Parameters](#parameters-67)
|
|
232
|
+
* [setAll](#setall)
|
|
233
|
+
* [Parameters](#parameters-68)
|
|
234
|
+
* [clean](#clean-1)
|
|
235
|
+
* [entries](#entries-2)
|
|
236
|
+
* [Parameters](#parameters-69)
|
|
237
|
+
* [forEach](#foreach-1)
|
|
238
|
+
* [Parameters](#parameters-70)
|
|
239
|
+
* [values](#values-2)
|
|
240
|
+
* [hasValue](#hasvalue)
|
|
241
|
+
* [Parameters](#parameters-71)
|
|
242
|
+
* [filter](#filter-1)
|
|
243
|
+
* [Parameters](#parameters-72)
|
|
244
|
+
* [find](#find-1)
|
|
245
|
+
* [Parameters](#parameters-73)
|
|
246
|
+
* [map](#map-1)
|
|
247
|
+
* [Parameters](#parameters-74)
|
|
248
|
+
* [iterator](#iterator)
|
|
249
|
+
* [toStringTag](#tostringtag-2)
|
|
250
|
+
* [isValidReference](#isvalidreference)
|
|
251
|
+
* [Parameters](#parameters-75)
|
|
252
|
+
* [AsyncIterable](#asynciterable)
|
|
253
|
+
* [Parameters](#parameters-76)
|
|
254
|
+
* [asyncIterator](#asynciterator)
|
|
255
|
+
* [toStringTag](#tostringtag-3)
|
|
256
|
+
* [isAsyncIterable](#isasynciterable)
|
|
257
|
+
* [Parameters](#parameters-77)
|
|
258
|
+
* [AsyncIterator](#asynciterator-1)
|
|
259
|
+
* [Parameters](#parameters-78)
|
|
260
|
+
* [asArray](#asarray)
|
|
261
|
+
* [asyncIterable](#asynciterable-1)
|
|
262
|
+
* [next](#next)
|
|
263
|
+
* [reset](#reset)
|
|
264
|
+
* [asyncIterator](#asynciterator-2)
|
|
265
|
+
* [toStringTag](#tostringtag-4)
|
|
266
|
+
* [Iterable](#iterable)
|
|
267
|
+
* [Parameters](#parameters-79)
|
|
268
|
+
* [iterator](#iterator-1)
|
|
269
|
+
* [asArray](#asarray-1)
|
|
270
|
+
* [toStringTag](#tostringtag-5)
|
|
271
|
+
* [isIterable](#isiterable)
|
|
272
|
+
* [Parameters](#parameters-80)
|
|
273
|
+
* [Iterator](#iterator-2)
|
|
274
|
+
* [Parameters](#parameters-81)
|
|
275
|
+
* [asArray](#asarray-2)
|
|
276
|
+
* [iterable](#iterable-1)
|
|
277
|
+
* [next](#next-1)
|
|
278
|
+
* [reset](#reset-1)
|
|
279
|
+
* [iterator](#iterator-3)
|
|
280
|
+
* [toStringTag](#tostringtag-6)
|
|
281
|
+
* [mapEach](#mapeach)
|
|
282
|
+
|
|
283
|
+
### FunctionExtensions
|
|
284
|
+
|
|
285
|
+
The `FunctionExtensions` class is a patch applied to the built-in JavaScript
|
|
286
|
+
`Function` constructor. It extends `Function` with additional utility methods
|
|
287
|
+
for determining the specific type or nature of function-like objects. These
|
|
288
|
+
methods allow developers to distinguish between classes, regular functions,
|
|
289
|
+
async functions, and arrow functions in a more intuitive and straightforward
|
|
290
|
+
manner. This class is part of the `@nejs/extension` library and enhances the
|
|
291
|
+
capabilities of function handling and introspection in JavaScript.
|
|
292
|
+
|
|
293
|
+
#### isClass
|
|
294
|
+
|
|
295
|
+
Determines if a given value is a class. It checks if the value is an
|
|
296
|
+
instance of `Function` and if its string representation includes the
|
|
297
|
+
keyword 'class'. This method is useful for distinguishing classes from
|
|
298
|
+
other function types in JavaScript.
|
|
299
|
+
|
|
300
|
+
##### Parameters
|
|
301
|
+
|
|
302
|
+
* `value` **any** The value to be checked.
|
|
303
|
+
|
|
304
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is a class, otherwise
|
|
305
|
+
`false`.
|
|
306
|
+
|
|
307
|
+
#### isFunction
|
|
308
|
+
|
|
309
|
+
Checks if a given value is a regular function. This method verifies if
|
|
310
|
+
the value is an instance of `Function`, which includes regular functions,
|
|
311
|
+
classes, and async functions but excludes arrow functions.
|
|
312
|
+
|
|
313
|
+
##### Parameters
|
|
314
|
+
|
|
315
|
+
* `value` **any** The value to be checked.
|
|
316
|
+
|
|
317
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is a regular function,
|
|
318
|
+
otherwise `false`.
|
|
319
|
+
|
|
320
|
+
#### isAsync
|
|
321
|
+
|
|
322
|
+
Determines if a given value is an asynchronous function. It checks if the
|
|
323
|
+
value is an instance of `Function` and if its string representation
|
|
324
|
+
includes the keyword 'Async'. This method is particularly useful for
|
|
325
|
+
identifying async functions.
|
|
326
|
+
|
|
327
|
+
##### Parameters
|
|
328
|
+
|
|
329
|
+
* `value` **any** The value to be checked.
|
|
330
|
+
|
|
331
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is an async function,
|
|
332
|
+
otherwise `false`.
|
|
333
|
+
|
|
334
|
+
#### isBigArrow
|
|
335
|
+
|
|
336
|
+
Checks if a given value is an arrow function. It verifies if the value is
|
|
337
|
+
an instance of `Function`, if its string representation includes the '=>'
|
|
338
|
+
symbol, and if it lacks a prototype, which is a characteristic of arrow
|
|
339
|
+
functions in JavaScript.
|
|
340
|
+
|
|
341
|
+
##### Parameters
|
|
342
|
+
|
|
343
|
+
* `value` **any** The value to be checked.
|
|
344
|
+
|
|
345
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is an arrow function,
|
|
346
|
+
otherwise `false`.
|
|
347
|
+
|
|
348
|
+
#### isBound
|
|
349
|
+
|
|
350
|
+
Determines if a given value is a bound function. Bound functions are
|
|
351
|
+
created using the `Function.prototype.bind` method, which allows setting
|
|
352
|
+
the `this` value at the time of binding. This method checks if the value
|
|
353
|
+
is an instance of `Function`, if its string representation starts with
|
|
354
|
+
'bound', and if it lacks a `prototype` property. These characteristics
|
|
355
|
+
are indicative of bound functions in JavaScript.
|
|
356
|
+
|
|
357
|
+
##### Parameters
|
|
358
|
+
|
|
359
|
+
* `value` **any** The value to be checked, typically a function.
|
|
360
|
+
|
|
361
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is a bound function,
|
|
362
|
+
otherwise `false`. Bound functions have a specific format in their
|
|
363
|
+
string representation and do not have their own `prototype` property.
|
|
364
|
+
|
|
365
|
+
### ObjectExtensions
|
|
366
|
+
|
|
367
|
+
`ObjectExtensions` is a patch for the JavaScript built-in `Object` class.
|
|
368
|
+
It adds utility methods to the `Object` class without modifying the global
|
|
369
|
+
namespace directly. This patch includes methods for key validation, object
|
|
370
|
+
type checking, and retrieving the string tag of an object. These methods
|
|
371
|
+
are useful for enhancing the capabilities of the standard `Object` class
|
|
372
|
+
with additional utility functions.
|
|
373
|
+
|
|
374
|
+
#### isNullDefined
|
|
375
|
+
|
|
376
|
+
The function checks if a value is either `undefined` or `null`.
|
|
377
|
+
|
|
378
|
+
##### Parameters
|
|
379
|
+
|
|
380
|
+
* `value` **any** The parameter "value" is a variable that can hold
|
|
381
|
+
any value.
|
|
382
|
+
|
|
383
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if the value is either `undefined` or `null`,
|
|
384
|
+
and `false` otherwise.
|
|
385
|
+
|
|
386
|
+
#### hasStringTag
|
|
387
|
+
|
|
388
|
+
Checks to see if the supplied `value` is both an object, and has the
|
|
389
|
+
appropriate symbol defined.
|
|
390
|
+
|
|
391
|
+
##### Parameters
|
|
392
|
+
|
|
393
|
+
* `value` **any** the value to determine if it contains a defined
|
|
394
|
+
`Symbol.toStringTag` defined.
|
|
395
|
+
|
|
396
|
+
Returns **any** true if the symbol is defined, false otherwise
|
|
397
|
+
|
|
398
|
+
#### getStringTag
|
|
399
|
+
|
|
400
|
+
Retrieves the string tag of an object. The string tag is a representation
|
|
401
|
+
of the object's type, as defined by its `Object.prototype.toString`
|
|
402
|
+
method. This utility method is helpful for getting a more descriptive
|
|
403
|
+
type of an object than what is returned by the `typeof` operator,
|
|
404
|
+
especially for custom objects.
|
|
405
|
+
|
|
406
|
+
##### Parameters
|
|
407
|
+
|
|
408
|
+
* `value` **any** The object whose string tag is to be retrieved.
|
|
409
|
+
* `strict` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if this is set to true, undefined will be
|
|
410
|
+
returned whenever a supplied object does not have a
|
|
411
|
+
`Symbol.toStringTag` defined, period. if false, the default, (optional, default `false`)
|
|
412
|
+
|
|
413
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The string tag of the object, indicating its type.
|
|
414
|
+
|
|
415
|
+
#### getType
|
|
416
|
+
|
|
417
|
+
Determines the type of the given value based on its string tag. This method
|
|
418
|
+
uses `Object.getStringTag` to obtain the string tag of the value, which
|
|
419
|
+
represents its more specific type (e.g., Array, Map, Set) rather than just
|
|
420
|
+
'object'. The method then maps this string tag to the corresponding type
|
|
421
|
+
present in the provided `owner` object, which defaults to `globalThis`.
|
|
422
|
+
This utility method is especially useful for identifying the specific
|
|
423
|
+
constructor or class of an object, beyond the basic types identified by
|
|
424
|
+
the `typeof` operator.
|
|
425
|
+
|
|
426
|
+
##### Parameters
|
|
427
|
+
|
|
428
|
+
* `value` **any** The value whose type is to be determined.
|
|
429
|
+
* `owner` **[object](#object)** The object in which to look up the
|
|
430
|
+
constructor corresponding to the string tag. Defaults to `globalThis`,
|
|
431
|
+
which covers global constructors like `Array`, `Object`, etc. (optional, default `globalThis`)
|
|
432
|
+
|
|
433
|
+
Returns **([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) | [object](#object) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** Returns the constructor or
|
|
434
|
+
type of the value based on its string tag. For 'Null' and 'Undefined',
|
|
435
|
+
it returns `null` and `undefined`, respectively. For other types, it
|
|
436
|
+
returns the corresponding constructor (e.g., `Array` for arrays) if
|
|
437
|
+
available in the `owner` object.
|
|
438
|
+
|
|
439
|
+
#### isObject
|
|
440
|
+
|
|
441
|
+
Determines if the provided value is an object. This method checks whether
|
|
442
|
+
the value is an instance of `Object` or if its type is 'object'. It's a
|
|
443
|
+
utility method for type-checking, ensuring that a value is an object
|
|
444
|
+
before performing operations that are specific to objects.
|
|
445
|
+
|
|
446
|
+
##### Parameters
|
|
447
|
+
|
|
448
|
+
* `value` **any** The value to be checked.
|
|
449
|
+
|
|
450
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is an object,
|
|
451
|
+
otherwise `false`.
|
|
452
|
+
|
|
453
|
+
#### isPrimitive
|
|
454
|
+
|
|
455
|
+
Checks to see if the supplied value is a primitive value.
|
|
456
|
+
|
|
457
|
+
##### Parameters
|
|
458
|
+
|
|
459
|
+
* `value` **any** the value to test to see if it is a primitive value type
|
|
460
|
+
|
|
461
|
+
Returns **any** true if the object is considered widely to be a primitive value,
|
|
462
|
+
false otherwise.
|
|
463
|
+
|
|
464
|
+
#### isValidKey
|
|
465
|
+
|
|
466
|
+
Checks if the given value is a valid key for an object. In JavaScript, a
|
|
467
|
+
valid key can be either a string or a symbol. This method is useful for
|
|
468
|
+
validating object keys before using them in operations like setting or
|
|
469
|
+
getting object properties.
|
|
470
|
+
|
|
471
|
+
##### Parameters
|
|
472
|
+
|
|
473
|
+
* `value` **any** The value to be checked.
|
|
474
|
+
|
|
475
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns `true` if the value is a valid object key
|
|
476
|
+
(string or symbol), otherwise `false`.
|
|
477
|
+
|
|
478
|
+
#### stripTo
|
|
479
|
+
|
|
480
|
+
Strips an object down to only the keys specified. Optionally, any
|
|
481
|
+
accessors can be made to retain their context on the source object.
|
|
482
|
+
|
|
483
|
+
##### Parameters
|
|
484
|
+
|
|
485
|
+
* `object` **[object](#object)** the object to pare down
|
|
486
|
+
* `keys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))>** the keys that should appear in the
|
|
487
|
+
final reduced object
|
|
488
|
+
* `bindAccessors` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if this value is true then any
|
|
489
|
+
accessors from the source object will continue to have their `this`
|
|
490
|
+
value bound to the source. If the getter or setter on that object is
|
|
491
|
+
defined using an arrow function, this will not work as intended. (optional, default `true`)
|
|
492
|
+
|
|
493
|
+
Returns **[object](#object)** an object containing only the keys and symbols
|
|
494
|
+
specified in the `keys` parameter.
|
|
495
|
+
|
|
496
|
+
### stripTo
|
|
497
|
+
|
|
498
|
+
Strips an object down to only the keys specified. Optionally, any
|
|
499
|
+
accessors can be made to retain their context on the source object.
|
|
500
|
+
This is a passthrough to the static [Object.stripTo](Object.stripTo) function
|
|
501
|
+
|
|
502
|
+
#### Parameters
|
|
503
|
+
|
|
504
|
+
* `keys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))>** the keys that should appear in the
|
|
505
|
+
final reduced object
|
|
506
|
+
* `bindAccessors` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if this value is true then any
|
|
507
|
+
accessors from the source object will continue to have their `this`
|
|
508
|
+
value bound to the source. If the getter or setter on that object is
|
|
509
|
+
defined using an arrow function, this will not work as intended. (optional, default `true`)
|
|
510
|
+
|
|
511
|
+
Returns **[object](#object)** an object containing only the keys and symbols
|
|
512
|
+
specified in the `keys` parameter.
|
|
513
|
+
|
|
514
|
+
### getKey
|
|
515
|
+
|
|
516
|
+
The function `getKey` returns the key associated with a given value
|
|
517
|
+
in a map.
|
|
518
|
+
|
|
519
|
+
#### Parameters
|
|
520
|
+
|
|
521
|
+
* `value` **any** The value parameter is the value that you want to
|
|
522
|
+
find the corresponding key for in the map.
|
|
523
|
+
* `strict` The "strict" parameter is a boolean value that
|
|
524
|
+
determines whether strict equality (===) or loose equality (==) should
|
|
525
|
+
be used when comparing the "value" parameter with the values in the
|
|
526
|
+
entries of the object. If "strict" is set to true, strict equality will
|
|
527
|
+
be used. (optional, default `true`)
|
|
528
|
+
|
|
529
|
+
Returns **any** the key associated with the given value. If a matching key is
|
|
530
|
+
found, it is returned. If no matching key is found, null is returned.
|
|
531
|
+
|
|
532
|
+
### ReflectExtensions
|
|
533
|
+
|
|
534
|
+
The `ReflectExtensions` class is a patch applied to the built-in JavaScript
|
|
535
|
+
`Reflect` object. It extends `Reflect` with additional utility methods that
|
|
536
|
+
enhance its capabilities. These methods provide more advanced ways of
|
|
537
|
+
interacting with object properties, such as checking for the presence of
|
|
538
|
+
multiple keys at once (`hasAll`) or verifying if at least one specified key
|
|
539
|
+
exists in an object (`hasSome`). This class is part of the `@nejs/extension`
|
|
540
|
+
library and is designed to offer these extended functionalities in a way
|
|
541
|
+
that is consistent with the existing `Reflect` API, making it intuitive for
|
|
542
|
+
developers who are already familiar with standard reflection methods in
|
|
543
|
+
JavaScript.
|
|
544
|
+
|
|
545
|
+
#### hasAll
|
|
546
|
+
|
|
547
|
+
The function checks if an object has all the specified keys.
|
|
548
|
+
|
|
549
|
+
##### Parameters
|
|
550
|
+
|
|
551
|
+
* `object` The `object` parameter is the object that we want to
|
|
552
|
+
check if it has all the specified keys.
|
|
553
|
+
* `keys` **...any** The `keys` parameter is a rest parameter, which means
|
|
554
|
+
it can accept any number of arguments. In this case, it is expected
|
|
555
|
+
to receive multiple keys as arguments.
|
|
556
|
+
|
|
557
|
+
Returns **any** a boolean value.
|
|
558
|
+
|
|
559
|
+
#### ownDescriptors
|
|
560
|
+
|
|
561
|
+
Fetches all descriptors of an object, including those mapped to a
|
|
562
|
+
symbol descriptor value.
|
|
563
|
+
|
|
564
|
+
##### Parameters
|
|
565
|
+
|
|
566
|
+
* `object` **[object](#object)** the object from whose descriptors need to be
|
|
567
|
+
retrieved.
|
|
568
|
+
|
|
569
|
+
<!---->
|
|
570
|
+
|
|
571
|
+
* Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** if the supplied `object` is null or not an object
|
|
572
|
+
a TypeError exception will be thrown
|
|
573
|
+
|
|
574
|
+
Returns **[object](#object)** with keys mapped to object descriptors
|
|
575
|
+
|
|
576
|
+
#### hasSome
|
|
577
|
+
|
|
578
|
+
The function checks if an object has at least one of the specified keys.
|
|
579
|
+
|
|
580
|
+
##### Parameters
|
|
581
|
+
|
|
582
|
+
* `object` The `object` parameter is the object that we want to check
|
|
583
|
+
for the presence of certain keys.
|
|
584
|
+
* `keys` **...any** The `keys` parameter is a rest parameter, which means it can
|
|
585
|
+
accept any number of arguments. These arguments are the keys that we want
|
|
586
|
+
to check if they exist in the `object`.
|
|
587
|
+
|
|
588
|
+
Returns **any** The function `hasSome` returns a boolean value indicating whether
|
|
589
|
+
at least one of the keys provided as arguments exists in the given object.
|
|
590
|
+
|
|
591
|
+
#### entries
|
|
592
|
+
|
|
593
|
+
Retrieves an array of \[key, descriptor] pairs for each property of the
|
|
594
|
+
provided object. This method is akin to `Object.entries` but includes
|
|
595
|
+
property descriptors instead of the property values. It's useful for cases
|
|
596
|
+
where you need detailed information about properties, including their
|
|
597
|
+
configurability, enumerability, and accessors.
|
|
598
|
+
|
|
599
|
+
##### Parameters
|
|
600
|
+
|
|
601
|
+
* `object` **[object](#object)** The object whose property entries are to be
|
|
602
|
+
retrieved.
|
|
603
|
+
|
|
604
|
+
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array of \[key, descriptor] pairs, where each pair
|
|
605
|
+
consists of the property name (key) and its descriptor. Returns an empty
|
|
606
|
+
array if the input is not a valid object.
|
|
607
|
+
|
|
608
|
+
#### values
|
|
609
|
+
|
|
610
|
+
Retrieves an array of values from the property descriptors of the given
|
|
611
|
+
object. This method works similarly to `Object.values` but operates on
|
|
612
|
+
property descriptors instead. It's useful when you need the values of
|
|
613
|
+
properties including getters, setters, and other descriptor-specific
|
|
614
|
+
attributes.
|
|
615
|
+
|
|
616
|
+
##### Parameters
|
|
617
|
+
|
|
618
|
+
* `object` **[object](#object)** The object whose property values are to be
|
|
619
|
+
retrieved.
|
|
620
|
+
|
|
621
|
+
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array of values extracted from the object's property
|
|
622
|
+
descriptors. The values correspond to the `value` attribute in each
|
|
623
|
+
property's descriptor. Returns an empty array if the input is not a valid
|
|
624
|
+
object.
|
|
625
|
+
|
|
626
|
+
### StringExtensions
|
|
627
|
+
|
|
628
|
+
`StringExtensions` is a patch for the JavaScript built-in `String` class. It
|
|
629
|
+
adds utility methods to the `String` class without modifying the global namespace
|
|
630
|
+
directly. This patch includes methods for key validation, object type checking,
|
|
631
|
+
and retrieving the string tag of an object. These methods are useful for
|
|
632
|
+
enhancing the capabilities of the standard `String` class with additional
|
|
633
|
+
utility functions.
|
|
634
|
+
|
|
635
|
+
#### isString
|
|
636
|
+
|
|
637
|
+
The `isString` method does exactly what one would it expect. It returns
|
|
638
|
+
true if the string matches typeof or instanceof as a string.
|
|
639
|
+
|
|
640
|
+
##### Parameters
|
|
641
|
+
|
|
642
|
+
* `value` **any** checks to see if the `value` is a string
|
|
643
|
+
|
|
644
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if it is a `String`, `false` otherwise
|
|
645
|
+
|
|
646
|
+
### SymbolExtensions
|
|
647
|
+
|
|
648
|
+
`SymbolExtensions` is a patch for the JavaScript built-in `Symbol` class. It
|
|
649
|
+
adds utility methods to the `Symbol` class without modifying the global namespace
|
|
650
|
+
directly. This patch includes methods for key validation, object type checking,
|
|
651
|
+
and retrieving the string tag of an object. These methods are useful for
|
|
652
|
+
enhancing the capabilities of the standard `Symbol` class with additional
|
|
653
|
+
utility functions.
|
|
654
|
+
|
|
655
|
+
#### isSymbol
|
|
656
|
+
|
|
657
|
+
The `isSymbol` method does exactly what one would it expect. It returns
|
|
658
|
+
true if the string matches typeof or instanceof as a symbol.
|
|
659
|
+
|
|
660
|
+
##### Parameters
|
|
661
|
+
|
|
662
|
+
* `value` **any** checks to see if the `value` is a string
|
|
663
|
+
|
|
664
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if it is a `Symbol`, `false` otherwise
|
|
665
|
+
|
|
666
|
+
#### isRegistered
|
|
667
|
+
|
|
668
|
+
Returns true if the supplied value is a Symbol created using
|
|
669
|
+
`Symbol.for()`.
|
|
670
|
+
|
|
671
|
+
##### Parameters
|
|
672
|
+
|
|
673
|
+
* `value` **any** assumption is that the supplied value is of type
|
|
674
|
+
'symbol' however, unless `allowOnlySymbols` is set to `true`, `false`
|
|
675
|
+
will be returned for any non-symbol values.
|
|
676
|
+
* `allowOnlySymbols` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if an error should be thrown
|
|
677
|
+
if the supplied value is not of type 'symbol' (optional, default `false`)
|
|
678
|
+
|
|
679
|
+
Returns **any** true if the symbol is registered, meaning, none of the spec
|
|
680
|
+
static symbols (`toStringTag`, `iterator`, etc...), and no symbols
|
|
681
|
+
created by passing a value directly to the Symbol function, such as
|
|
682
|
+
`Symbol('name')`
|
|
683
|
+
|
|
684
|
+
#### isNonRegistered
|
|
685
|
+
|
|
686
|
+
A function that returns true if the symbol is not registered, meaning,
|
|
687
|
+
any of the spec static symbols (`toStringTag`, `iterator`, etc...), and
|
|
688
|
+
any symbols created by passing a value directly to the `Symbol` function,
|
|
689
|
+
such as `Symbol('name')`.
|
|
690
|
+
|
|
691
|
+
##### Parameters
|
|
692
|
+
|
|
693
|
+
* `value` **any** assumption is that the supplied value is of type
|
|
694
|
+
'symbol' however, unless allowOnlySymbols is set to true, false will
|
|
695
|
+
be returned for any non-symbol values.
|
|
696
|
+
* `allowOnlySymbols` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if an error should be thrown
|
|
697
|
+
if the supplied value is not of type 'symbol' (optional, default `false`)
|
|
698
|
+
|
|
699
|
+
Returns **any** true if the symbol is not registered, meaning, any of the
|
|
700
|
+
spec static symbols (`toStringTag`, `iterator`, etc...), and any symbols
|
|
701
|
+
created by passing a value directly to the `Symbol` function, such as
|
|
702
|
+
`Symbol('name')`
|
|
703
|
+
|
|
704
|
+
Returns **any** true if the `value` in question is both a `symbol` and has
|
|
705
|
+
returns `undefined` if passed to `Symbol.keyFor`
|
|
706
|
+
|
|
707
|
+
### ArrayPrototypeExtensions
|
|
708
|
+
|
|
709
|
+
The `ArrayPrototypeExtensions` patch extends the prototype of the built-in
|
|
710
|
+
JavaScript `Array` with additional properties for convenience and improved
|
|
711
|
+
readability. By applying this patch, all array instances gain new getter
|
|
712
|
+
properties `first` and `last`, which provide quick access to the first and
|
|
713
|
+
last elements of the array, respectively. This enhancement simplifies common
|
|
714
|
+
operations on arrays and makes code more expressive and concise.
|
|
715
|
+
|
|
716
|
+
#### contains
|
|
717
|
+
|
|
718
|
+
Sometimes defining even a short function for the invocation of `find`
|
|
719
|
+
can be troublesome. This helper function performs that job for you. If
|
|
720
|
+
the specified element is in the array, `true` will be returned.
|
|
721
|
+
|
|
722
|
+
##### Parameters
|
|
723
|
+
|
|
724
|
+
* `value` **any** the value to search for. This value must triple equals
|
|
725
|
+
the array element in order to return true.
|
|
726
|
+
|
|
727
|
+
Returns **any** true if the exact element exists in the array, false otherwise
|
|
728
|
+
|
|
729
|
+
#### findEntry
|
|
730
|
+
|
|
731
|
+
The `findEntry` function searches the entries of the object and returns
|
|
732
|
+
the `[index, value]` entry array for the first matching value found.
|
|
733
|
+
|
|
734
|
+
##### Parameters
|
|
735
|
+
|
|
736
|
+
* `findFn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function that takes the element to be checked
|
|
737
|
+
and returns a boolean value
|
|
738
|
+
|
|
739
|
+
Returns **any** if `findFn` returns `true`, an array with two elements, the first
|
|
740
|
+
being the index, the second being the value, is returned.
|
|
741
|
+
|
|
742
|
+
#### first
|
|
743
|
+
|
|
744
|
+
A getter property that returns the first element of the array. If the
|
|
745
|
+
array is empty, it returns `undefined`. This property is useful for
|
|
746
|
+
scenarios where you need to quickly access the first item of an array
|
|
747
|
+
without the need for additional checks or method calls.
|
|
748
|
+
|
|
749
|
+
Returns **any** The first element of the array or `undefined` if the array
|
|
750
|
+
is empty.
|
|
751
|
+
|
|
752
|
+
#### last
|
|
753
|
+
|
|
754
|
+
A getter property that returns the last element of the array. It
|
|
755
|
+
calculates the last index based on the array's length. If the array is
|
|
756
|
+
empty, it returns `undefined`. This property is beneficial when you need
|
|
757
|
+
to access the last item in an array, improving code readability and
|
|
758
|
+
avoiding manual index calculation.
|
|
759
|
+
|
|
760
|
+
Returns **any** The last element of the array or `undefined` if the
|
|
761
|
+
array is empty.
|
|
762
|
+
|
|
763
|
+
### object
|
|
764
|
+
|
|
765
|
+
An optionally associated object, usually the parent from which
|
|
766
|
+
the descriptor was taken, or undefined if none was able to be
|
|
767
|
+
derived.
|
|
768
|
+
|
|
769
|
+
Type: [object](#object)
|
|
770
|
+
|
|
771
|
+
### constructor
|
|
772
|
+
|
|
773
|
+
Creates a new instance of Descriptor either from another object or
|
|
774
|
+
around the supplied object descriptor value.
|
|
775
|
+
|
|
776
|
+
#### Parameters
|
|
777
|
+
|
|
778
|
+
* `object` **[object](#object)** either an object descriptor or the object
|
|
779
|
+
from which to get the descriptor
|
|
780
|
+
* `key` **([symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** a valid key for accessing the descriptor
|
|
781
|
+
on the aforesupplied object.
|
|
782
|
+
|
|
783
|
+
### isAccessor
|
|
784
|
+
|
|
785
|
+
Detects whether or not this instance is an accessor object descriptor
|
|
786
|
+
|
|
787
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if this object has a getter or setter and is not
|
|
788
|
+
a data descriptor
|
|
789
|
+
|
|
790
|
+
### isData
|
|
791
|
+
|
|
792
|
+
Detects whether or not this instance is an data object descriptor
|
|
793
|
+
|
|
794
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if this object has a value property and is not
|
|
795
|
+
an accessor descriptor
|
|
796
|
+
|
|
797
|
+
### isDescriptor
|
|
798
|
+
|
|
799
|
+
Detects whether or not this instance is a valid object descriptor
|
|
800
|
+
|
|
801
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if this descriptor store is a valid descriptor
|
|
802
|
+
|
|
803
|
+
### configurable
|
|
804
|
+
|
|
805
|
+
Getter around the `configurable` object descriptor property of
|
|
806
|
+
this instance of Descriptor.
|
|
807
|
+
|
|
808
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** a boolean value or undefined if the internal
|
|
809
|
+
descriptor store is invalid.
|
|
810
|
+
|
|
811
|
+
### configurable
|
|
812
|
+
|
|
813
|
+
Sets the `configurable` value of this object. If the internal descriptor
|
|
814
|
+
store store is invalid, the value is thrown away
|
|
815
|
+
|
|
816
|
+
#### Parameters
|
|
817
|
+
|
|
818
|
+
* `value` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** the value to set for the `configurable` descriptor
|
|
819
|
+
property. If this value is not a `boolean` it will be converted to one
|
|
820
|
+
|
|
821
|
+
### enumerable
|
|
822
|
+
|
|
823
|
+
Getter around the `enumerable` object descriptor property of
|
|
824
|
+
this instance of Descriptor.
|
|
825
|
+
|
|
826
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** a boolean value or undefined if the internal
|
|
827
|
+
descriptor store is invalid.
|
|
828
|
+
|
|
829
|
+
### enumerable
|
|
830
|
+
|
|
831
|
+
Sets the `enumerable` value of this object. If the internal descriptor
|
|
832
|
+
store is invalid, the value is thrown away
|
|
833
|
+
|
|
834
|
+
#### Parameters
|
|
835
|
+
|
|
836
|
+
* `value` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** the value to set for the `enumerable` descriptor
|
|
837
|
+
property. If this value is not a `boolean` it will be converted to one
|
|
838
|
+
|
|
839
|
+
### writable
|
|
840
|
+
|
|
841
|
+
Getter around the `writable` object descriptor property of
|
|
842
|
+
this instance of Descriptor.
|
|
843
|
+
|
|
844
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** a boolean value or undefined if the internal
|
|
845
|
+
descriptor store is invalid.
|
|
846
|
+
|
|
847
|
+
### writable
|
|
848
|
+
|
|
849
|
+
Sets the `writable` value of this object. If the internal descriptor
|
|
850
|
+
store is invalid, the value is thrown away
|
|
851
|
+
|
|
852
|
+
#### Parameters
|
|
853
|
+
|
|
854
|
+
* `value` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** the value to set for the `writable` descriptor
|
|
855
|
+
property. If this value is not a `boolean` it will be converted to one
|
|
856
|
+
|
|
857
|
+
### value
|
|
858
|
+
|
|
859
|
+
Getter around the `value` object descriptor property of
|
|
860
|
+
this instance of Descriptor.
|
|
861
|
+
|
|
862
|
+
Returns **any** any value stored in this descriptor
|
|
863
|
+
|
|
864
|
+
### value
|
|
865
|
+
|
|
866
|
+
Sets the `value` value of this object. If the internal descriptor
|
|
867
|
+
store is invalid, the value is thrown away
|
|
868
|
+
|
|
869
|
+
#### Parameters
|
|
870
|
+
|
|
871
|
+
* `value` **any** the value to set for the `value` descriptor
|
|
872
|
+
property.
|
|
873
|
+
|
|
874
|
+
### get
|
|
875
|
+
|
|
876
|
+
Getter around the `get` object descriptor property of
|
|
877
|
+
this instance of Descriptor.
|
|
878
|
+
|
|
879
|
+
Returns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function if the getter for this descriptor is
|
|
880
|
+
defined or `undefined` if the internal descriptor object or the getter
|
|
881
|
+
is undefined.
|
|
882
|
+
|
|
883
|
+
### get
|
|
884
|
+
|
|
885
|
+
Sets the `get` value of this object. If the internal descriptor
|
|
886
|
+
store is invalid, the value is thrown away
|
|
887
|
+
|
|
888
|
+
#### Parameters
|
|
889
|
+
|
|
890
|
+
* `value` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the getter function for this descriptor
|
|
891
|
+
|
|
892
|
+
### boundGet
|
|
893
|
+
|
|
894
|
+
Retrieves the [get](get) function for this accessor and binds it to
|
|
895
|
+
the object from which the descriptor was derived, if that value is set.
|
|
896
|
+
Otherwise this method is identical to the [get](get) accessor.
|
|
897
|
+
|
|
898
|
+
Returns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the getter if one is defined. If possible this
|
|
899
|
+
getter will be bound the associated and previously set `object`.
|
|
900
|
+
|
|
901
|
+
### set
|
|
902
|
+
|
|
903
|
+
Getter around the `set` object descriptor property of
|
|
904
|
+
this instance of Descriptor.
|
|
905
|
+
|
|
906
|
+
Returns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** a function if the setter for this descriptor is
|
|
907
|
+
defined or `undefined` if the internal descriptor object or the setter
|
|
908
|
+
is undefined.
|
|
909
|
+
|
|
910
|
+
### set
|
|
911
|
+
|
|
912
|
+
Sets the `set` value of this object. If the internal descriptor
|
|
913
|
+
store is invalid, the value is thrown away
|
|
914
|
+
|
|
915
|
+
#### Parameters
|
|
916
|
+
|
|
917
|
+
* `value` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the setter function for this descriptor
|
|
918
|
+
|
|
919
|
+
### boundSet
|
|
920
|
+
|
|
921
|
+
Retrieves the [set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) function for this accessor and binds it to
|
|
922
|
+
the object from which the descriptor was derived, if that value is set.
|
|
923
|
+
Otherwise this method is identical to the [set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) accessor.
|
|
924
|
+
|
|
925
|
+
Returns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the setter if one is defined. If possible this
|
|
926
|
+
setter will be bound the associated and previously set `object`.
|
|
927
|
+
|
|
928
|
+
### hasObject
|
|
929
|
+
|
|
930
|
+
The function checks the descriptor's associated object has been set on this
|
|
931
|
+
instance of `Descriptor`.
|
|
932
|
+
|
|
933
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if the `object` property has been set,
|
|
934
|
+
`false` otherwise
|
|
935
|
+
|
|
936
|
+
### object
|
|
937
|
+
|
|
938
|
+
Returns the descriptor's associated `object` value. This is usually the
|
|
939
|
+
parent object from which the descriptor was derived. If the value is preset
|
|
940
|
+
it will be returned. Undefined will be returned otherwise
|
|
941
|
+
|
|
942
|
+
Returns **[object](#object)** the associated object for this descriptor or undefined
|
|
943
|
+
if it has not yet been set.
|
|
944
|
+
|
|
945
|
+
### object
|
|
946
|
+
|
|
947
|
+
Sets the descriptor's associated `object` value. This is usually the
|
|
948
|
+
parent object from which the descriptor was derived.
|
|
949
|
+
|
|
950
|
+
#### Parameters
|
|
951
|
+
|
|
952
|
+
* `value` **[object](#object)** sets the object for which this descriptor is to
|
|
953
|
+
be associated with.
|
|
954
|
+
|
|
955
|
+
### for
|
|
956
|
+
|
|
957
|
+
The function returns a string representation of a descriptor object with
|
|
958
|
+
additional information about its type when used in the NodeJS repl.
|
|
959
|
+
|
|
960
|
+
#### Parameters
|
|
961
|
+
|
|
962
|
+
* `depth` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The `depth` parameter is used to specify the
|
|
963
|
+
maximum depth to which nested objects and arrays will be formatted. If
|
|
964
|
+
the depth is exceeded, the output will be truncated with ellipses.
|
|
965
|
+
* `options` **[object](#object)** The `options` parameter is an object that
|
|
966
|
+
contains various configuration options for the `inspect` function.
|
|
967
|
+
These options can be used to customize the output of the inspection.
|
|
968
|
+
* `inspect` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The `inspect` parameter is a function that
|
|
969
|
+
is used to convert an object into a string representation. It is
|
|
970
|
+
typically used for debugging purposes or when displaying an object's
|
|
971
|
+
properties.
|
|
972
|
+
|
|
973
|
+
Returns **any** a string that represents a descriptor. The string includes the
|
|
974
|
+
type of the descriptor (either "Accessor" or "Data") and the result of
|
|
975
|
+
inspecting the descriptor object using the provided options and depth.
|
|
976
|
+
|
|
977
|
+
### applyTo
|
|
978
|
+
|
|
979
|
+
Take the descriptor defined by this objects values and apply them to
|
|
980
|
+
the specified object using the specified key.
|
|
981
|
+
|
|
982
|
+
#### Parameters
|
|
983
|
+
|
|
984
|
+
* `object` **[object](#object)** the object to apply this descriptor to
|
|
985
|
+
* `forKey` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** the string or symbol for which this
|
|
986
|
+
descriptor will abe applied
|
|
987
|
+
|
|
988
|
+
### toPrimitive
|
|
989
|
+
|
|
990
|
+
Converts this descriptor object into a base representation
|
|
991
|
+
|
|
992
|
+
#### Parameters
|
|
993
|
+
|
|
994
|
+
* `hint` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** one of `string`, `number` or default;
|
|
995
|
+
|
|
996
|
+
Returns **any** if the hint is 'string', then a string identifying the enum
|
|
997
|
+
and its type is returned. `number` will always be NaN since it is incoret
|
|
998
|
+
|
|
999
|
+
### toStringTag
|
|
1000
|
+
|
|
1001
|
+
Ensures that the constructor of this object instance's name
|
|
1002
|
+
is returned if the string tag for this instance is queried
|
|
1003
|
+
|
|
1004
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1005
|
+
|
|
1006
|
+
### for
|
|
1007
|
+
|
|
1008
|
+
Shorthand for Object.getOwnPropertyDescriptor()
|
|
1009
|
+
|
|
1010
|
+
#### Parameters
|
|
1011
|
+
|
|
1012
|
+
* `object` **[object](#object)** a non-null object instance
|
|
1013
|
+
* `key` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** a symbol or string referencing which key on the
|
|
1014
|
+
object to return a descriptor for.
|
|
1015
|
+
* `wrap` (optional, default `false`)
|
|
1016
|
+
|
|
1017
|
+
Returns **any** an object descriptor for the requested field or null
|
|
1018
|
+
|
|
1019
|
+
### getData
|
|
1020
|
+
|
|
1021
|
+
The function `getData` retrieves the value of a property from an object
|
|
1022
|
+
if it exists and is a data property.
|
|
1023
|
+
|
|
1024
|
+
#### Parameters
|
|
1025
|
+
|
|
1026
|
+
* `object` **[object](#object)** The "object" parameter is the object from which
|
|
1027
|
+
we want to retrieve data.
|
|
1028
|
+
* `property` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** The `property` parameter is the name of
|
|
1029
|
+
the property that you want to retrieve the data from.
|
|
1030
|
+
|
|
1031
|
+
Returns **any** either the value of the specified property if it exists and is
|
|
1032
|
+
a data property, or undefined if the property does not exist or is not
|
|
1033
|
+
a data property.
|
|
1034
|
+
|
|
1035
|
+
### getAccessor
|
|
1036
|
+
|
|
1037
|
+
The function `getAccessor` checks if an object has a getter/setter accessor
|
|
1038
|
+
for a given property and returns the accessor functions if found.
|
|
1039
|
+
|
|
1040
|
+
#### Parameters
|
|
1041
|
+
|
|
1042
|
+
* `object` The `object` parameter is the object from which we want to
|
|
1043
|
+
retrieve the accessor for a specific property.
|
|
1044
|
+
* `property` The `property` parameter is the name of the property for
|
|
1045
|
+
which we want to get the accessor.
|
|
1046
|
+
|
|
1047
|
+
Returns **any** an object that contains the getter and setter functions for the
|
|
1048
|
+
specified property of the given object. If the property is an accessor
|
|
1049
|
+
property (defined with a getter and/or setter), the returned object will
|
|
1050
|
+
also have additional properties such as "accessor" and "descriptor". If
|
|
1051
|
+
the property is not found or is not an accessor property, the function
|
|
1052
|
+
returns undefined.
|
|
1053
|
+
|
|
1054
|
+
### base
|
|
1055
|
+
|
|
1056
|
+
The function returns an object with enumerable and configurable properties
|
|
1057
|
+
based on the input parameters.
|
|
1058
|
+
|
|
1059
|
+
#### Parameters
|
|
1060
|
+
|
|
1061
|
+
* `enumerable` A boolean value indicating whether the property
|
|
1062
|
+
can be enumerated (listed) when iterating over the object's properties. (optional, default `false`)
|
|
1063
|
+
* `configurable` The `configurable` parameter determines
|
|
1064
|
+
whether the property can be deleted or its attributes can be modified.
|
|
1065
|
+
If `configurable` is set to `true`, the property can be deleted and its
|
|
1066
|
+
attributes can be changed. If `configurable` is set to `false`, the
|
|
1067
|
+
property cannot be deleted and (optional, default `false`)
|
|
1068
|
+
|
|
1069
|
+
Returns **any** An object with the properties `enumerable` and `configurable` is
|
|
1070
|
+
being returned. The values of these properties are determined by the
|
|
1071
|
+
arguments passed to the `base` function.
|
|
1072
|
+
|
|
1073
|
+
### accessor
|
|
1074
|
+
|
|
1075
|
+
The function "newAccessor" creates a new property descriptor object with a
|
|
1076
|
+
getter and setter function, along with optional enumerable and configurable
|
|
1077
|
+
flags.
|
|
1078
|
+
|
|
1079
|
+
#### Parameters
|
|
1080
|
+
|
|
1081
|
+
* `getter` The getter parameter is a function that will be used as the
|
|
1082
|
+
getter for the property. It will be called when the property is accessed.
|
|
1083
|
+
* `setter` The `setter` parameter is a function that will be used as
|
|
1084
|
+
the setter for the property. It will be called whenever the property is
|
|
1085
|
+
assigned a new value.
|
|
1086
|
+
* `null` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** * `getter`: A function that will be used as the getter for the
|
|
1087
|
+
property. (optional, default `Descriptor.base()`)
|
|
1088
|
+
|
|
1089
|
+
* `null.enumerable`  
|
|
1090
|
+
* `null.configurable`  
|
|
1091
|
+
|
|
1092
|
+
Returns **any** an object with properties "get", "set", "enumerable", and
|
|
1093
|
+
"configurable".
|
|
1094
|
+
|
|
1095
|
+
### data
|
|
1096
|
+
|
|
1097
|
+
The function "newData" creates a new data object with customizable
|
|
1098
|
+
properties.
|
|
1099
|
+
|
|
1100
|
+
#### Parameters
|
|
1101
|
+
|
|
1102
|
+
* `value` The value parameter represents the value that will be
|
|
1103
|
+
assigned to the property.
|
|
1104
|
+
* `writable` The `writable` parameter determines whether the
|
|
1105
|
+
value of the property can be changed. If `writable` is set to `true`, the
|
|
1106
|
+
value can be changed. If `writable` is set to `false`, the value cannot be
|
|
1107
|
+
changed. (optional, default `true`)
|
|
1108
|
+
* `null` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** * `value`: The value to be assigned to the property. (optional, default `Descriptor.base()`)
|
|
1109
|
+
|
|
1110
|
+
* `null.enumerable`  
|
|
1111
|
+
* `null.configurable`  
|
|
1112
|
+
|
|
1113
|
+
Returns **any** an object with properties `value`, `enumerable`, `writable`, and
|
|
1114
|
+
`configurable`.
|
|
1115
|
+
|
|
1116
|
+
### isDescriptor
|
|
1117
|
+
|
|
1118
|
+
The function checks if an object is a likely an object descriptor in
|
|
1119
|
+
JavaScript. This is determined as an object with some of the known
|
|
1120
|
+
descriptor keys (e.g. enumerable, configurable, value, writable, get,
|
|
1121
|
+
or set). Technically, any object could serve as a descriptor but this
|
|
1122
|
+
function only returns true if known descriptor keys are found.
|
|
1123
|
+
|
|
1124
|
+
#### Parameters
|
|
1125
|
+
|
|
1126
|
+
* `object` The `object` parameter is the object that we want to
|
|
1127
|
+
check if it is a descriptor.
|
|
1128
|
+
|
|
1129
|
+
Returns **any** a boolean value.
|
|
1130
|
+
|
|
1131
|
+
### isData
|
|
1132
|
+
|
|
1133
|
+
The function checks if a given property or descriptor is a data property.
|
|
1134
|
+
|
|
1135
|
+
brie
|
|
1136
|
+
|
|
1137
|
+
#### Parameters
|
|
1138
|
+
|
|
1139
|
+
* `object_orProp`  
|
|
1140
|
+
* `property`  
|
|
1141
|
+
* `descriptor_orProp` The `descriptor_orProp` parameter can be
|
|
1142
|
+
either a descriptor or a property name.
|
|
1143
|
+
* `object` The `object` parameter is the object that you want to
|
|
1144
|
+
check for data properties.
|
|
1145
|
+
|
|
1146
|
+
Returns **any** a boolean value. It returns `true` if the `descriptor` object
|
|
1147
|
+
has any keys that match the `DATA_KEYS` array, otherwise it returns
|
|
1148
|
+
`false`.
|
|
1149
|
+
|
|
1150
|
+
### isAccessor
|
|
1151
|
+
|
|
1152
|
+
The function checks if a given property descriptor or property of an
|
|
1153
|
+
object is an accessor.
|
|
1154
|
+
|
|
1155
|
+
#### Parameters
|
|
1156
|
+
|
|
1157
|
+
* `object_orProp` The `descriptor_orProp` parameter can be either a
|
|
1158
|
+
descriptor object or a property name.
|
|
1159
|
+
* `property` The `object` parameter is the object that you want to
|
|
1160
|
+
check for accessor properties.
|
|
1161
|
+
|
|
1162
|
+
Returns **any** a boolean value. It returns true if the descriptor or property
|
|
1163
|
+
passed as an argument is an accessor descriptor, and false otherwise.
|
|
1164
|
+
|
|
1165
|
+
### flexible
|
|
1166
|
+
|
|
1167
|
+
A base descriptor (new for each read) that is both enumerable and
|
|
1168
|
+
configurable
|
|
1169
|
+
|
|
1170
|
+
Returns **any** The method `flexible` is returning the result of calling the
|
|
1171
|
+
`base` method with the arguments `true` and `true`.
|
|
1172
|
+
|
|
1173
|
+
### enigmatic
|
|
1174
|
+
|
|
1175
|
+
A base descriptor (new for each read) that is not enumerable but is
|
|
1176
|
+
configurable
|
|
1177
|
+
|
|
1178
|
+
Returns **any** The method `enigmatic` is returning the result of calling
|
|
1179
|
+
the `base` method with the arguments `false` and `true`.
|
|
1180
|
+
|
|
1181
|
+
### intrinsic
|
|
1182
|
+
|
|
1183
|
+
A base descriptor (new for each read) that is neither enumerable
|
|
1184
|
+
nor configurable
|
|
1185
|
+
|
|
1186
|
+
Returns **any** The code is returning the result of calling the `base` method with
|
|
1187
|
+
the arguments `false` and `false`.
|
|
1188
|
+
|
|
1189
|
+
### transparent
|
|
1190
|
+
|
|
1191
|
+
A base descriptor (new for each read) that enumerable but not configurable
|
|
1192
|
+
|
|
1193
|
+
Returns **any** The method is returning the result of calling the `base`
|
|
1194
|
+
method with the arguments `true` and `false`.
|
|
1195
|
+
|
|
1196
|
+
### SHARED\_KEYS
|
|
1197
|
+
|
|
1198
|
+
The function returns an array of shared descriptor keys.
|
|
1199
|
+
|
|
1200
|
+
Returns **any** An array containing the strings 'configurable' and 'enumerable'.
|
|
1201
|
+
|
|
1202
|
+
### ACCESSOR\_KEYS
|
|
1203
|
+
|
|
1204
|
+
The function returns an array of accessor descriptor keys.
|
|
1205
|
+
|
|
1206
|
+
Returns **any** An array containing the strings 'get' and 'set' is being returned.
|
|
1207
|
+
|
|
1208
|
+
### DATA\_KEYS
|
|
1209
|
+
|
|
1210
|
+
The function returns an array of data descriptor keys.
|
|
1211
|
+
|
|
1212
|
+
Returns **any** An array containing the strings 'value' and 'writable' is being
|
|
1213
|
+
returned.
|
|
1214
|
+
|
|
1215
|
+
### maskAs
|
|
1216
|
+
|
|
1217
|
+
Transforms an object to mimic a specified prototype, altering its type
|
|
1218
|
+
conversion and inspection behaviors. This function is especially useful
|
|
1219
|
+
for creating objects that need to behave like different primitive types
|
|
1220
|
+
under various operations.
|
|
1221
|
+
|
|
1222
|
+
#### Parameters
|
|
1223
|
+
|
|
1224
|
+
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The object to be transformed.
|
|
1225
|
+
* `classPrototype`  
|
|
1226
|
+
* `options`  
|
|
1227
|
+
* `prototype` **([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** The prototype or
|
|
1228
|
+
class to emulate. If a function is provided, its prototype is used.
|
|
1229
|
+
Defaults to String.prototype. (optional, default `String.prototype`)
|
|
1230
|
+
* `toPrimitive` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A function
|
|
1231
|
+
defining how the object should be converted to a primitive value. It
|
|
1232
|
+
receives a type hint ('number', 'string', or 'default') and the object,
|
|
1233
|
+
returning the primitive value. (optional, default `(hint,val)=>String(val)`)
|
|
1234
|
+
|
|
1235
|
+
Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | null)** The transformed object, or null if neither a class
|
|
1236
|
+
nor a prototype could be derived from the provided prototype parameter.
|
|
1237
|
+
|
|
1238
|
+
### maskAsString
|
|
1239
|
+
|
|
1240
|
+
Masks an object as a string-like object by setting its prototype to
|
|
1241
|
+
String and defining how it converts to primitive types. This is
|
|
1242
|
+
particularly useful when an object needs to behave like a string in
|
|
1243
|
+
certain contexts, such as type coercion or logging.
|
|
1244
|
+
|
|
1245
|
+
#### Parameters
|
|
1246
|
+
|
|
1247
|
+
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The object to be masked as a string.
|
|
1248
|
+
* `stringKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The object property key used for
|
|
1249
|
+
the string representation. Defaults to 'value'. (optional, default `'value'`)
|
|
1250
|
+
* `toPrimitive` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** Optional custom function for primitive
|
|
1251
|
+
conversion. If omitted, a default function handling various conversion
|
|
1252
|
+
hints is used.
|
|
1253
|
+
|
|
1254
|
+
Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | null)** The string-masked object, or null if the object
|
|
1255
|
+
doesn't have the specified stringKey property.
|
|
1256
|
+
|
|
1257
|
+
### maskAsNumber
|
|
1258
|
+
|
|
1259
|
+
Masks an object as a number-like object. This allows the object to
|
|
1260
|
+
behave like a number in operations like arithmetic and type coercion.
|
|
1261
|
+
It sets the prototype to Number and defines custom conversion behavior.
|
|
1262
|
+
|
|
1263
|
+
#### Parameters
|
|
1264
|
+
|
|
1265
|
+
* `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The object to be masked as a number
|
|
1266
|
+
representation. Defaults to 'value'.
|
|
1267
|
+
* `numberKey`  
|
|
1268
|
+
* `toPrimitive` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** Optional custom function for primitive
|
|
1269
|
+
conversion. If not provided, a default function handling different
|
|
1270
|
+
conversion hints is used.
|
|
1271
|
+
|
|
1272
|
+
Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | null)** The number-masked object, or null if the object
|
|
1273
|
+
doesn't have the specified numberKey property.
|
|
1274
|
+
|
|
1275
|
+
### GenericMask
|
|
1276
|
+
|
|
1277
|
+
Generates options for generic masking of an object, providing defaults for
|
|
1278
|
+
prototype and toPrimitive function if not specified.
|
|
1279
|
+
|
|
1280
|
+
#### Parameters
|
|
1281
|
+
|
|
1282
|
+
* `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The options object including prototype,
|
|
1283
|
+
targetKey, and toPrimitive function.
|
|
1284
|
+
|
|
1285
|
+
* `options.prototype`  
|
|
1286
|
+
* `options.targetKey` (optional, default `'value'`)
|
|
1287
|
+
* `options.toPrimitive`  
|
|
1288
|
+
|
|
1289
|
+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The options object with defaults applied as necessary.
|
|
1290
|
+
|
|
1291
|
+
### StringMask
|
|
1292
|
+
|
|
1293
|
+
Generates options for string masking of an object, providing a default
|
|
1294
|
+
toPrimitive function if not specified.
|
|
1295
|
+
|
|
1296
|
+
#### Parameters
|
|
1297
|
+
|
|
1298
|
+
* `targetKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The object property key for string
|
|
1299
|
+
representation.
|
|
1300
|
+
* `toPrimitive` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Custom function for primitive conversion.
|
|
1301
|
+
|
|
1302
|
+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for string masking.
|
|
1303
|
+
|
|
1304
|
+
### NumberMask
|
|
1305
|
+
|
|
1306
|
+
Generates options for number masking of an object, providing a default
|
|
1307
|
+
toPrimitive function if not specified.
|
|
1308
|
+
|
|
1309
|
+
#### Parameters
|
|
1310
|
+
|
|
1311
|
+
* `targetKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The object property key for number
|
|
1312
|
+
representation.
|
|
1313
|
+
* `toPrimitive` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Custom function for primitive conversion.
|
|
1314
|
+
|
|
1315
|
+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for number masking.
|
|
1316
|
+
|
|
1317
|
+
### RefSet
|
|
1318
|
+
|
|
1319
|
+
**Extends Set**
|
|
1320
|
+
|
|
1321
|
+
RefSet class extends the standard Set object to manage a collection of
|
|
1322
|
+
WeakRef objects. It provides additional functionality such as objectification
|
|
1323
|
+
of values and various utility methods.
|
|
1324
|
+
|
|
1325
|
+
Unlike standard Sets or Arrays, RefSet stores weak references to objects,
|
|
1326
|
+
allowing them to be garbage-collected if there are no other references to
|
|
1327
|
+
them. This behavior is different from Arrays and standard Sets, which
|
|
1328
|
+
maintain strong references to their elements.
|
|
1329
|
+
|
|
1330
|
+
#### objectifying
|
|
1331
|
+
|
|
1332
|
+
Method to control whether the RefSet should objectify its values. When
|
|
1333
|
+
objectifying, primitive values (number, string, boolean, bigint) are
|
|
1334
|
+
converted to their respective object types, which allows them to be used as
|
|
1335
|
+
WeakRef targets.
|
|
1336
|
+
|
|
1337
|
+
##### Parameters
|
|
1338
|
+
|
|
1339
|
+
* `setObjectification` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Flag to enable or disable
|
|
1340
|
+
objectification. (optional, default `true`)
|
|
1341
|
+
|
|
1342
|
+
Returns **[RefSet](#refset)** The current RefSet instance to allow method chaining.
|
|
1343
|
+
|
|
1344
|
+
#### objectifyValues
|
|
1345
|
+
|
|
1346
|
+
Returns the state indicating whether or not `RefSet` will attempt to
|
|
1347
|
+
convert non-valid primitives into targets that are valid input for
|
|
1348
|
+
new `WeakRef` object instances. If this value is `false` then no
|
|
1349
|
+
*objectification* will occur.
|
|
1350
|
+
|
|
1351
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** The current state of objectifyValues.
|
|
1352
|
+
|
|
1353
|
+
#### objectifyValues
|
|
1354
|
+
|
|
1355
|
+
Setting this value to true, will cause all added values to the Set to
|
|
1356
|
+
be analyzed for validity as a candidate to be wrapped in a `WeakRef`
|
|
1357
|
+
object. If true, and if possible, the object will be turned into an
|
|
1358
|
+
`Object` variant first. This will also enable less rigid variable
|
|
1359
|
+
comparison in the `.has()` method (i.e. `==` instead of `===`).
|
|
1360
|
+
|
|
1361
|
+
##### Parameters
|
|
1362
|
+
|
|
1363
|
+
* `value` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** The new state to set for objectifyValues.
|
|
1364
|
+
|
|
1365
|
+
#### add
|
|
1366
|
+
|
|
1367
|
+
Overrides the add method of Set. Adds a value to the RefSet, converting it
|
|
1368
|
+
to a WeakRef. Throws an error if the value is not a valid WeakRef target
|
|
1369
|
+
(e.g., null, undefined, or a registered symbol). If `objectifyValues` is
|
|
1370
|
+
enabled, an attempt to convert primitives to their object variants will be
|
|
1371
|
+
made. These are numbers, strings, boolean values and big integers.
|
|
1372
|
+
|
|
1373
|
+
##### Parameters
|
|
1374
|
+
|
|
1375
|
+
* `value` **any** The value to be added to the RefSet.
|
|
1376
|
+
|
|
1377
|
+
<!---->
|
|
1378
|
+
|
|
1379
|
+
* Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** If the value is not a valid WeakRef target.
|
|
1380
|
+
|
|
1381
|
+
#### addAll
|
|
1382
|
+
|
|
1383
|
+
Adds multiple values to the RefSet. The supplied `values` should be
|
|
1384
|
+
iterable and truthy. This function defers to `.add()` for its logic so
|
|
1385
|
+
each value from the supplied collection of values will also be subject
|
|
1386
|
+
to the criteria of that function.
|
|
1387
|
+
|
|
1388
|
+
##### Parameters
|
|
1389
|
+
|
|
1390
|
+
* `values` **[Iterable](#iterable)** An iterable of values to add to the RefSet.
|
|
1391
|
+
|
|
1392
|
+
<!---->
|
|
1393
|
+
|
|
1394
|
+
* Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** If the supplied values are falsey or non-iterable.
|
|
1395
|
+
|
|
1396
|
+
#### clean
|
|
1397
|
+
|
|
1398
|
+
Removes all elements from the RefSet that have been garbage collected
|
|
1399
|
+
(i.e., their WeakRef no longer points to an object).
|
|
1400
|
+
|
|
1401
|
+
Returns **[RefSet](#refset)** The current RefSet instance to allow method chaining.
|
|
1402
|
+
|
|
1403
|
+
#### entries
|
|
1404
|
+
|
|
1405
|
+
Executes a provided function once for each value in the RefSet. The callback
|
|
1406
|
+
function receives the dereferenced value, the value again (as RefSet doesn't
|
|
1407
|
+
use keys), and the RefSet itself. This method provides a way to iterate over
|
|
1408
|
+
and apply operations to the values stored in the RefSet, taking into account
|
|
1409
|
+
that they are weak references and may have been garbage-collected.
|
|
1410
|
+
|
|
1411
|
+
##### Parameters
|
|
1412
|
+
|
|
1413
|
+
* `forEachFn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to execute for each element. It
|
|
1414
|
+
takes three arguments: element, element (again, as RefSet has no key), and
|
|
1415
|
+
the RefSet itself.
|
|
1416
|
+
* `thisArg` **any** Value to use as `this` when executing `forEachFn`.
|
|
1417
|
+
|
|
1418
|
+
#### forEach
|
|
1419
|
+
|
|
1420
|
+
Iterate over the items in the set and pass them to the supplied
|
|
1421
|
+
function ala `Array.prototype.forEach`. Note however, there are no
|
|
1422
|
+
indexes on Sets and as such, the index parameter of the callback
|
|
1423
|
+
will always be `NaN`. Subsequently the `array` or third parameter
|
|
1424
|
+
will receive the set instance rather than an array.
|
|
1425
|
+
|
|
1426
|
+
##### Parameters
|
|
1427
|
+
|
|
1428
|
+
* `forEachFn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to use for each element in
|
|
1429
|
+
the set.
|
|
1430
|
+
* `thisArg` **[object](#object)** the `this` argument to be applied to each
|
|
1431
|
+
invocation of the `forEachFn` callback. Note, this value is unable
|
|
1432
|
+
to be applied if the `forEachFn` is a big arrow function
|
|
1433
|
+
|
|
1434
|
+
#### values
|
|
1435
|
+
|
|
1436
|
+
Returns an iterator for the values in the RefSet. Each value is
|
|
1437
|
+
dereferenced from its WeakRef before being returned. This method allows
|
|
1438
|
+
iterating over he set's values, similar to how one would iterate over
|
|
1439
|
+
values in a standard Set or Array, but with the understanding that the
|
|
1440
|
+
values are weakly referenced and may no longer exist (in which case
|
|
1441
|
+
they are skipped).
|
|
1442
|
+
|
|
1443
|
+
Returns **[Iterator](#iterator)** An iterator for the values.
|
|
1444
|
+
|
|
1445
|
+
#### keys
|
|
1446
|
+
|
|
1447
|
+
Returns an iterator for the keys of the RefSet. In RefSet, keys and
|
|
1448
|
+
values are identical, so this method behaves the same as `values()`. It
|
|
1449
|
+
provides compatibility with the standard Set interface and allows use in
|
|
1450
|
+
contexts where keys are expected, despite RefSet not differentiating
|
|
1451
|
+
between keys and values.
|
|
1452
|
+
|
|
1453
|
+
Returns **[Iterator](#iterator)** An iterator for the keys.
|
|
1454
|
+
|
|
1455
|
+
#### has
|
|
1456
|
+
|
|
1457
|
+
Determines whether an element with the specified value exists in the
|
|
1458
|
+
`RefSet`. For non-objectified sets, this method checks if the dereferenced
|
|
1459
|
+
values of the set include the specified value.
|
|
1460
|
+
|
|
1461
|
+
For objectified sets, it uses the `contains` method which accounts for
|
|
1462
|
+
the objectification. This method differs from standard Set `has` in that
|
|
1463
|
+
it works with weak references and considers objectification settings.
|
|
1464
|
+
|
|
1465
|
+
##### Parameters
|
|
1466
|
+
|
|
1467
|
+
* `value` **any** The value to check for presence in the RefSet.
|
|
1468
|
+
|
|
1469
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True if an element with the specified value exists
|
|
1470
|
+
in the RefSet, false otherwise.
|
|
1471
|
+
|
|
1472
|
+
#### contains
|
|
1473
|
+
|
|
1474
|
+
Checks if the RefSet contains a value that is equal to the specified
|
|
1475
|
+
value. This method is used primarily in objectified RefSets to determine
|
|
1476
|
+
the presence of a value, taking into account objectification. It differs
|
|
1477
|
+
from the `has` method in that it's tailored for sets that have
|
|
1478
|
+
transformed their primitive values into objects, whereas `has` is more
|
|
1479
|
+
general-purpose.
|
|
1480
|
+
|
|
1481
|
+
##### Parameters
|
|
1482
|
+
|
|
1483
|
+
* `value` **any** The value to search for in the RefSet.
|
|
1484
|
+
|
|
1485
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True if the RefSet contains the value, false otherwise.
|
|
1486
|
+
|
|
1487
|
+
#### filter
|
|
1488
|
+
|
|
1489
|
+
Creates a new array with all elements that pass the test implemented by
|
|
1490
|
+
the provided function. This method iterates over each element,
|
|
1491
|
+
dereferences it, and applies the filter function. Unlike Array `filter`,
|
|
1492
|
+
the callback receives the dereferenced value and not an index or array,
|
|
1493
|
+
reflecting the non-indexed nature of RefSet. Useful for selectively
|
|
1494
|
+
creating arrays from the set based on certain conditions, especially when
|
|
1495
|
+
dealing with weak references.
|
|
1496
|
+
|
|
1497
|
+
##### Parameters
|
|
1498
|
+
|
|
1499
|
+
* `filterFn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to test each element of the RefSet.
|
|
1500
|
+
The function receives the dereferenced value.
|
|
1501
|
+
* `thisArg` **any** Value to use as `this` when executing `filterFn`.
|
|
1502
|
+
|
|
1503
|
+
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** A new array with the elements that pass the test.
|
|
1504
|
+
|
|
1505
|
+
#### find
|
|
1506
|
+
|
|
1507
|
+
Returns the value of the first element in the RefSet that satisfies the
|
|
1508
|
+
provided testing function. Similar to Array `find`, this method iterates
|
|
1509
|
+
over the RefSet, dereferencing each value and applying the testing
|
|
1510
|
+
function. The non-indexed nature of RefSet is considered, as the
|
|
1511
|
+
callback does not receive an index. This method is useful for finding a
|
|
1512
|
+
specific element based on a condition.
|
|
1513
|
+
|
|
1514
|
+
##### Parameters
|
|
1515
|
+
|
|
1516
|
+
* `findFn`  
|
|
1517
|
+
* `thisArg` **any** Value to use as this when executing findFn.
|
|
1518
|
+
|
|
1519
|
+
Returns **any** The value of the first element in the RefSet that satisfies
|
|
1520
|
+
the testing function, or undefined if none found.
|
|
1521
|
+
|
|
1522
|
+
Returns **any** the dereferenced value if found, or undefined otherwise
|
|
1523
|
+
|
|
1524
|
+
#### map
|
|
1525
|
+
|
|
1526
|
+
Creates a new array or `RefSet` with the results of calling a provided
|
|
1527
|
+
function on every element in the calling `RefSet`. This method dereferences
|
|
1528
|
+
each value, applies the `mapFn`, and collects the results. If `toRefSet` is
|
|
1529
|
+
`true`, a new `RefSet` is returned; otherwise, an array. This method
|
|
1530
|
+
differs from `Array.map` in handling weak references and the potential to
|
|
1531
|
+
return a new `RefSet` instead of an array.
|
|
1532
|
+
|
|
1533
|
+
##### Parameters
|
|
1534
|
+
|
|
1535
|
+
* `mapFn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function that produces an element of the new
|
|
1536
|
+
array or `RefSet`, taking three arguments.
|
|
1537
|
+
* `thisArg` **any** Value to use as this when executing mapFn.
|
|
1538
|
+
* `toRefSet` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Determines if the output should be a new
|
|
1539
|
+
`RefSet` (`true`) or an array (`false`).
|
|
1540
|
+
* `mirrorObjectification` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If `true` and `toRefSet` is
|
|
1541
|
+
`true`, the new `RefSet` mirrors the objectification setting of the
|
|
1542
|
+
original.
|
|
1543
|
+
|
|
1544
|
+
Returns **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [RefSet](#refset))** A new array or `RefSet` with each element being
|
|
1545
|
+
the result of the `mapFn`.
|
|
1546
|
+
|
|
1547
|
+
#### toStringTag
|
|
1548
|
+
|
|
1549
|
+
Ensures that the constructor of this object instance's name
|
|
1550
|
+
is returned if the string tag for this instance is queried
|
|
1551
|
+
|
|
1552
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1553
|
+
|
|
1554
|
+
### RefMap
|
|
1555
|
+
|
|
1556
|
+
**Extends Map**
|
|
1557
|
+
|
|
1558
|
+
RefMap class extends the standard Map object to manage a collection of
|
|
1559
|
+
WeakRef values mapped to strong keys. It provides additional functionality
|
|
1560
|
+
such as objectification of values and various utility methods.
|
|
1561
|
+
|
|
1562
|
+
Unlike standard Maps or Objects, RefMap stores weak references to objects,
|
|
1563
|
+
allowing them to be garbage-collected if there are no other references to
|
|
1564
|
+
them. This behavior is different from Maps and standard Objects, which
|
|
1565
|
+
maintain strong references to their elements.
|
|
1566
|
+
|
|
1567
|
+
#### Parameters
|
|
1568
|
+
|
|
1569
|
+
* `args` **...any** 
|
|
1570
|
+
|
|
1571
|
+
#### objectifying
|
|
1572
|
+
|
|
1573
|
+
Method to control whether the RefMap should objectify its values. When
|
|
1574
|
+
objectifying, primitive values (number, string, boolean, bigint) are
|
|
1575
|
+
converted to their respective object types, which allows them to be used as
|
|
1576
|
+
WeakRef targets.
|
|
1577
|
+
|
|
1578
|
+
##### Parameters
|
|
1579
|
+
|
|
1580
|
+
* `setObjectification` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Flag to enable or disable
|
|
1581
|
+
objectification. (optional, default `true`)
|
|
1582
|
+
|
|
1583
|
+
Returns **[RefMap](#refmap)** The current RefMap instance to allow method chaining.
|
|
1584
|
+
|
|
1585
|
+
#### asObject
|
|
1586
|
+
|
|
1587
|
+
The function converts a JavaScript Map object into a regular JavaScript
|
|
1588
|
+
object, handling invalid keys by converting them to strings.
|
|
1589
|
+
|
|
1590
|
+
Returns **[object](#object)** an object; keys that are not either a `String` or a
|
|
1591
|
+
`Symbol` will be converted to a string.
|
|
1592
|
+
|
|
1593
|
+
#### objectifyValues
|
|
1594
|
+
|
|
1595
|
+
Returns the state indicating whether or not `RefMap` will attempt to
|
|
1596
|
+
convert non-valid primitives into targets that are valid input for
|
|
1597
|
+
new `WeakRef` object instances. If this value is `false` then no
|
|
1598
|
+
*objectification* will occur.
|
|
1599
|
+
|
|
1600
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** The current state of objectifyValues.
|
|
1601
|
+
|
|
1602
|
+
#### objectifyValues
|
|
1603
|
+
|
|
1604
|
+
Setting this value to true, will cause all set values to the Map to
|
|
1605
|
+
be analyzed for validity as a candidate to be wrapped in a `WeakRef`
|
|
1606
|
+
object. If true, and if possible, the object will be turned into an
|
|
1607
|
+
`Object` variant first.
|
|
1608
|
+
|
|
1609
|
+
##### Parameters
|
|
1610
|
+
|
|
1611
|
+
* `value` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** The new state to set for objectifyValues.
|
|
1612
|
+
|
|
1613
|
+
#### get
|
|
1614
|
+
|
|
1615
|
+
The `get` function retrieves a value from a map and returns it, or returns a
|
|
1616
|
+
default value if the value is null or undefined. The actual retrieved value
|
|
1617
|
+
is a dereferenced `WeakRef`. If the result is `undefined` and this is not the
|
|
1618
|
+
expected response, it is likely the value has been garbage collected.
|
|
1619
|
+
|
|
1620
|
+
##### Parameters
|
|
1621
|
+
|
|
1622
|
+
* `key` **any** The key parameter is the key of the value you want to
|
|
1623
|
+
retrieve from the data structure.
|
|
1624
|
+
* `defaultValue` **any** The `defaultValue` parameter is the value that
|
|
1625
|
+
will be returned if the key does not exist in the map or if the value
|
|
1626
|
+
associated with the key has been garbage collected (i.e., it no longer
|
|
1627
|
+
exists).
|
|
1628
|
+
|
|
1629
|
+
Returns **any** The method is returning the value associated with the given key.
|
|
1630
|
+
If the value is not found or if it has been garbage collected (deref()
|
|
1631
|
+
returns null), then the defaultValue is returned.
|
|
1632
|
+
|
|
1633
|
+
#### set
|
|
1634
|
+
|
|
1635
|
+
Overrides the set method of `Map`. Adds a value to the `RefMap`,
|
|
1636
|
+
converting it to a `WeakRef`. Throws an error if the value is not a
|
|
1637
|
+
valid `WeakRef` target (e.g., `null`, `undefined`, or a registered
|
|
1638
|
+
`symbol`). If [objectifyValues](objectifyValues) is enabled, an attempt to convert
|
|
1639
|
+
primitives to their object variants will be made. These are `numbers`,
|
|
1640
|
+
`strings`, `boolean` values and `bigint`s.
|
|
1641
|
+
|
|
1642
|
+
##### Parameters
|
|
1643
|
+
|
|
1644
|
+
* `key` **any** The `key` to be set on the `RefMap`
|
|
1645
|
+
* `value` **any** The value to be associated with the `key`
|
|
1646
|
+
|
|
1647
|
+
<!---->
|
|
1648
|
+
|
|
1649
|
+
* Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** If the value is not a valid WeakRef target.
|
|
1650
|
+
|
|
1651
|
+
#### setAll
|
|
1652
|
+
|
|
1653
|
+
Sets multiple values at a single time. The format is an array of array
|
|
1654
|
+
or rather an array of [Object.entries](Object.entries) (for example,
|
|
1655
|
+
`[[key1,value1], [key2,value2]]`). For each entry pair, if the length
|
|
1656
|
+
is not 2, either missing a key or value, it will be skipped.
|
|
1657
|
+
|
|
1658
|
+
##### Parameters
|
|
1659
|
+
|
|
1660
|
+
* `entries`  
|
|
1661
|
+
* `values` **[Iterable](#iterable)** An iterable of values to add to the RefMap.
|
|
1662
|
+
|
|
1663
|
+
<!---->
|
|
1664
|
+
|
|
1665
|
+
* Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** If the supplied values are falsey or non-iterable.
|
|
1666
|
+
|
|
1667
|
+
Returns **RepMap** returns `this` to allow for chaining
|
|
1668
|
+
|
|
1669
|
+
#### clean
|
|
1670
|
+
|
|
1671
|
+
Removes all elements from the RefMap that have been garbage collected
|
|
1672
|
+
(i.e., their WeakRef no longer points to an object).
|
|
1673
|
+
|
|
1674
|
+
Returns **[RefMap](#refmap)** The current RefMap instance to allow method chaining.
|
|
1675
|
+
|
|
1676
|
+
#### entries
|
|
1677
|
+
|
|
1678
|
+
Executes a provided function once for each value in the RefMap. The callback
|
|
1679
|
+
function receives the dereferenced value, the value again (as RefMap doesn't
|
|
1680
|
+
use keys), and the RefMap itself. This method provides a way to iterate over
|
|
1681
|
+
and apply operations to the values stored in the RefMap, taking into account
|
|
1682
|
+
that they are weak references and may have been garbage-collected.
|
|
1683
|
+
|
|
1684
|
+
##### Parameters
|
|
1685
|
+
|
|
1686
|
+
* `forEachFn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to execute for each element. It
|
|
1687
|
+
takes three arguments: element, element (again, as RefMap has no key), and
|
|
1688
|
+
the RefMap itself.
|
|
1689
|
+
* `thisArg` **any** Value to use as `this` when executing `forEachFn`.
|
|
1690
|
+
|
|
1691
|
+
#### forEach
|
|
1692
|
+
|
|
1693
|
+
Iterate over the items in the map and pass them to the supplied
|
|
1694
|
+
function ala `Map.prototype.forEach`. Note however, there are no
|
|
1695
|
+
indexes on Maps and as such, the index parameter of the callback
|
|
1696
|
+
will always be the value's key. Subsequently the `array` or third
|
|
1697
|
+
parameter will receive the map instance rather than an array.
|
|
1698
|
+
|
|
1699
|
+
##### Parameters
|
|
1700
|
+
|
|
1701
|
+
* `forEachFn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the function to use for each element in
|
|
1702
|
+
the set.
|
|
1703
|
+
* `thisArg` **[object](#object)** the `this` argument to be applied to each
|
|
1704
|
+
invocation of the `forEachFn` callback. Note, this value is unable
|
|
1705
|
+
to be applied if the `forEachFn` is a big arrow function
|
|
1706
|
+
|
|
1707
|
+
#### values
|
|
1708
|
+
|
|
1709
|
+
Returns an iterator for the values in the RefMap. Each value is
|
|
1710
|
+
dereferenced from its WeakRef before being returned. This method allows
|
|
1711
|
+
iterating over he set's values, similar to how one would iterate over
|
|
1712
|
+
values in a standard Map or Array, but with the understanding that the
|
|
1713
|
+
values are weakly referenced and may no longer exist (in which case
|
|
1714
|
+
they are skipped).
|
|
1715
|
+
|
|
1716
|
+
Returns **[Iterator](#iterator)** An iterator for the values.
|
|
1717
|
+
|
|
1718
|
+
#### hasValue
|
|
1719
|
+
|
|
1720
|
+
Determines whether an element with the specified value exists in the
|
|
1721
|
+
`RefMap`. For non-objectified sets, this method checks if the dereferenced
|
|
1722
|
+
values of the map include the specified value.
|
|
1723
|
+
|
|
1724
|
+
For objectified sets, strict is set to false which uses loose
|
|
1725
|
+
equality to allow for things like `Object(5)` to equal `5`. This is important
|
|
1726
|
+
because otherwise primitives could not be weakly referenced. In the grand
|
|
1727
|
+
scheme of things, this is only useful if the objectified value is the
|
|
1728
|
+
one being referenced.
|
|
1729
|
+
|
|
1730
|
+
##### Parameters
|
|
1731
|
+
|
|
1732
|
+
* `value` **any** The value to check for presence in the RefMap.
|
|
1733
|
+
* `strict` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if `true`, the default, then the supplied value
|
|
1734
|
+
is hard compared to the dereferenced value (`===`). If `false`, then a
|
|
1735
|
+
loose comparison is used (`==`) (optional, default `true`)
|
|
1736
|
+
|
|
1737
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True if an element with the specified value exists
|
|
1738
|
+
in the RefMap, false otherwise.
|
|
1739
|
+
|
|
1740
|
+
#### filter
|
|
1741
|
+
|
|
1742
|
+
The `filter` function filters the entries of a `RefMap` object based on
|
|
1743
|
+
a given filter function. The dereferenced entries of the values of the map
|
|
1744
|
+
will be passed to the function rather than a `WeakRef` itself.
|
|
1745
|
+
|
|
1746
|
+
A new resulting entry set will be generated and a new `RefMap` will be made
|
|
1747
|
+
from these entries and returned. Note that this function never returns
|
|
1748
|
+
`null`
|
|
1749
|
+
|
|
1750
|
+
##### Parameters
|
|
1751
|
+
|
|
1752
|
+
* `filterFn` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The `filterFn` parameter is a function that
|
|
1753
|
+
will be used to filter the entries in the `RefMap`. It will be called with
|
|
1754
|
+
three arguments: the value of the current entry, the key of the current
|
|
1755
|
+
entry, and the `RefMap` itself. The function should return `true`
|
|
1756
|
+
* `thisArg` **[object](#object)** The `thisArg` parameter is an optional argument
|
|
1757
|
+
that specifies the value to be used as `this` when executing the
|
|
1758
|
+
`filterFn` function. It allows you to explicitly set the context in which
|
|
1759
|
+
the `filterFn` function is called. If `thisArg` is not provided, \`this
|
|
1760
|
+
|
|
1761
|
+
Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** The `filter` method is returning an array of filtered map
|
|
1762
|
+
entries
|
|
1763
|
+
|
|
1764
|
+
#### find
|
|
1765
|
+
|
|
1766
|
+
The `find` function iterates over a map and calls a given function on
|
|
1767
|
+
each value, returning the first value for which the function returns
|
|
1768
|
+
a truthy value.
|
|
1769
|
+
|
|
1770
|
+
The function signature of `findFn` is
|
|
1771
|
+
|
|
1772
|
+
function findFn(value, key, map)
|
|
1773
|
+
|
|
1774
|
+
'value' is passed to findFn up to two times; first with the `WeakRef`
|
|
1775
|
+
value, second with the result of [WeakRef.deref](WeakRef.deref). If `findFn`
|
|
1776
|
+
returns true for either of these the dereferenced value will be
|
|
1777
|
+
returned from the call to [RefMap.find](RefMap.find).
|
|
1778
|
+
`key` represents the key object that the value is mapped to.
|
|
1779
|
+
`map` is simply a reference to `this` map.
|
|
1780
|
+
|
|
1781
|
+
##### Parameters
|
|
1782
|
+
|
|
1783
|
+
* `findFn` `findFn` is a function that will be called for each
|
|
1784
|
+
element in the map. It takes three arguments: `ref`, `key`, and `map`;
|
|
1785
|
+
where `ref` is the value of the current element in the map, `key` is
|
|
1786
|
+
the key of the current element, and `map` is a reference to the instance
|
|
1787
|
+
being searched.
|
|
1788
|
+
* `thisArg` The `thisArg` parameter is the value to be used as
|
|
1789
|
+
the `this` value when executing the `findFn` function. It allows you
|
|
1790
|
+
to specify the context in which the `findFn` function should be called.
|
|
1791
|
+
|
|
1792
|
+
Returns **any** the first dereferenced value that satisfies the condition
|
|
1793
|
+
specified by the `findFn` function. If no value satisfies the condition,
|
|
1794
|
+
it returns `null`.
|
|
1795
|
+
|
|
1796
|
+
#### map
|
|
1797
|
+
|
|
1798
|
+
Creates a new array or `RefMap` with the results of calling a provided
|
|
1799
|
+
function on every element in the calling `RefMap`. This method dereferences
|
|
1800
|
+
each value, applies the `mapFn`, and collects the results. If `toRefMap` is
|
|
1801
|
+
`true`, a new `RefMap` is returned; otherwise, an array. This method
|
|
1802
|
+
differs from `Array.map` in handling weak references and the potential to
|
|
1803
|
+
return a new `RefMap` instead of an array.
|
|
1804
|
+
|
|
1805
|
+
##### Parameters
|
|
1806
|
+
|
|
1807
|
+
* `mapFn` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function that produces an element of the new
|
|
1808
|
+
array or `RefMap`, taking three arguments.
|
|
1809
|
+
* `thisArg` **any** Value to use as this when executing mapFn.
|
|
1810
|
+
* `toRefMap` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Determines if the output should be a new
|
|
1811
|
+
`RefMap` (`true`) or an array (`false`).
|
|
1812
|
+
* `mirrorObjectification` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If `true` and `toRefMap` is
|
|
1813
|
+
`true`, the new `RefMap` mirrors the objectification setting of the
|
|
1814
|
+
original.
|
|
1815
|
+
|
|
1816
|
+
Returns **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) | [RefMap](#refmap))** A new array or `RefMap` with each element being
|
|
1817
|
+
the result of the `mapFn`.
|
|
1818
|
+
|
|
1819
|
+
#### iterator
|
|
1820
|
+
|
|
1821
|
+
The function returns an iterator that iterates over the entries of an object,
|
|
1822
|
+
dereferencing any weak references.
|
|
1823
|
+
|
|
1824
|
+
Returns **[Iterator](#iterator)** A new iterator object is being returned.
|
|
1825
|
+
|
|
1826
|
+
#### toStringTag
|
|
1827
|
+
|
|
1828
|
+
Ensures that the constructor of this object instance's name
|
|
1829
|
+
is returned if the string tag for this instance is queried
|
|
1830
|
+
|
|
1831
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1832
|
+
|
|
1833
|
+
### isValidReference
|
|
1834
|
+
|
|
1835
|
+
A static method to check if a given value is a valid target for a WeakRef.
|
|
1836
|
+
|
|
1837
|
+
#### Parameters
|
|
1838
|
+
|
|
1839
|
+
* `value` **any** The value to check for validity as a WeakRef target.
|
|
1840
|
+
|
|
1841
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True if the value is a valid WeakRef target,
|
|
1842
|
+
false otherwise.
|
|
1843
|
+
|
|
1844
|
+
### AsyncIterable
|
|
1845
|
+
|
|
1846
|
+
The AsyncIterable class extends the concept of Iterable to asynchronous
|
|
1847
|
+
operations. It allows creating iterable objects where each element can be
|
|
1848
|
+
an asynchronous entity, like a Promise. This class is particularly useful
|
|
1849
|
+
when dealing with asynchronous data sources, such as API responses, file
|
|
1850
|
+
reading in chunks, or any other data that is not immediately available but
|
|
1851
|
+
arrives over time.
|
|
1852
|
+
|
|
1853
|
+
#### Parameters
|
|
1854
|
+
|
|
1855
|
+
* `elementsOrFirstElement` **([Iterable](#iterable) | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) | any)** An iterable object,
|
|
1856
|
+
a Promise, or the first element.
|
|
1857
|
+
* `moreElements` **...([Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) | any)** Additional elements if the first
|
|
1858
|
+
argument is not an iterable.
|
|
1859
|
+
|
|
1860
|
+
#### asyncIterator
|
|
1861
|
+
|
|
1862
|
+
Implements the async iterable protocol. When an instance of AsyncIterable
|
|
1863
|
+
is used in a `for await...of` loop, this async generator function is
|
|
1864
|
+
invoked. It yields each element as a Promise, allowing asynchronous
|
|
1865
|
+
iteration. Elements that are not Promises are automatically wrapped in
|
|
1866
|
+
a resolved Promise to ensure consistency.
|
|
1867
|
+
|
|
1868
|
+
Returns **AsyncGenerator** An async generator that yields each element as
|
|
1869
|
+
a Promise.
|
|
1870
|
+
|
|
1871
|
+
#### toStringTag
|
|
1872
|
+
|
|
1873
|
+
Ensures that the constructor of this object instance's name
|
|
1874
|
+
is returned if the string tag for this instance is queried
|
|
1875
|
+
|
|
1876
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1877
|
+
|
|
1878
|
+
#### isAsyncIterable
|
|
1879
|
+
|
|
1880
|
+
Checks if a given value is an async iterable. This method determines if
|
|
1881
|
+
the provided value has a `Symbol.asyncIterator` property that is an async
|
|
1882
|
+
generator function. It's a precise way to identify if the value conforms
|
|
1883
|
+
to the async iterable protocol using an async generator function.
|
|
1884
|
+
|
|
1885
|
+
Note: This method specifically checks for async generator functions. Some
|
|
1886
|
+
async iterables might use regular async functions that return an async
|
|
1887
|
+
iterator, which this method won't identify.
|
|
1888
|
+
|
|
1889
|
+
##### Parameters
|
|
1890
|
+
|
|
1891
|
+
* `value` **any** The value to be checked for async iterability.
|
|
1892
|
+
|
|
1893
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if the value is an async iterable
|
|
1894
|
+
implemented using an async generator function, false otherwise.
|
|
1895
|
+
|
|
1896
|
+
### AsyncIterator
|
|
1897
|
+
|
|
1898
|
+
Being able to create a compliant `AsyncIterator` around any type of
|
|
1899
|
+
iterable object. This can be wrapped around any type of object that
|
|
1900
|
+
has a `[Symbol.asyncIterator]` property assigned to a generator
|
|
1901
|
+
function.
|
|
1902
|
+
|
|
1903
|
+
#### Parameters
|
|
1904
|
+
|
|
1905
|
+
* `asyncIterable` **[object](#object)** any object that has a
|
|
1906
|
+
`[Symbol.asyncIterable]` property assigned to a generator function.
|
|
1907
|
+
|
|
1908
|
+
#### asArray
|
|
1909
|
+
|
|
1910
|
+
Returns a new `Array` derived from the iterable this object
|
|
1911
|
+
wraps.
|
|
1912
|
+
|
|
1913
|
+
Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** a new `Array` generated from the wrapped
|
|
1914
|
+
iterable. The method is generated from using an async for of
|
|
1915
|
+
loop.
|
|
1916
|
+
|
|
1917
|
+
#### asyncIterable
|
|
1918
|
+
|
|
1919
|
+
Returns the actual iterable object passed to the constructor that
|
|
1920
|
+
created this instance.
|
|
1921
|
+
|
|
1922
|
+
Returns **[object](#object)** the object containing the `[Symbol.iterator]`
|
|
1923
|
+
|
|
1924
|
+
#### next
|
|
1925
|
+
|
|
1926
|
+
The function retrieves the next value in the iterator. If the
|
|
1927
|
+
the iterator has run its course, `reset()` can be invoked to
|
|
1928
|
+
reset the pointer to the beginning of the iteration.
|
|
1929
|
+
|
|
1930
|
+
Returns **any** the next value
|
|
1931
|
+
|
|
1932
|
+
#### reset
|
|
1933
|
+
|
|
1934
|
+
Resets the async iterator to the beginning allowing it to be
|
|
1935
|
+
iterated over again.
|
|
1936
|
+
|
|
1937
|
+
#### asyncIterator
|
|
1938
|
+
|
|
1939
|
+
The existence of this symbol on the object instances, indicates that
|
|
1940
|
+
it can be used in `for(.. of ..)` loops and its values can be
|
|
1941
|
+
extracted from calls to `Array.from()`
|
|
1942
|
+
|
|
1943
|
+
Returns **[AsyncIterable](#asynciterable)** this is returned since this object is already
|
|
1944
|
+
conforming to the expected JavaScript AsyncIterator interface
|
|
1945
|
+
|
|
1946
|
+
#### toStringTag
|
|
1947
|
+
|
|
1948
|
+
Ensures that the constructor of this object instance's name
|
|
1949
|
+
is returned if the string tag for this instance is queried
|
|
1950
|
+
|
|
1951
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1952
|
+
|
|
1953
|
+
### Iterable
|
|
1954
|
+
|
|
1955
|
+
The Iterable class is designed to provide a convenient way to create synchronous
|
|
1956
|
+
iterable objects. It can be initialized with either an array or individual elements.
|
|
1957
|
+
This class implements the iterable protocol, allowing instances to be used with
|
|
1958
|
+
`for...of` loops and other standard JavaScript iteration mechanisms.
|
|
1959
|
+
|
|
1960
|
+
#### Parameters
|
|
1961
|
+
|
|
1962
|
+
* `elementsOrFirstElement` **([Iterable](#iterable) | any)** An iterable object or the
|
|
1963
|
+
first element.
|
|
1964
|
+
* `moreElements` **...any** Additional elements if the first argument is
|
|
1965
|
+
not an iterable.
|
|
1966
|
+
|
|
1967
|
+
#### iterator
|
|
1968
|
+
|
|
1969
|
+
Implements the iterable protocol. When an instance of Iterable is used
|
|
1970
|
+
in a `for...of` loop or spread syntax, this generator function is invoked
|
|
1971
|
+
to yield the elements one by one in a synchronous manner.
|
|
1972
|
+
|
|
1973
|
+
Returns **Generator** A generator that yields each element of the iterable.
|
|
1974
|
+
|
|
1975
|
+
#### asArray
|
|
1976
|
+
|
|
1977
|
+
Provides access to the elements as a standard array. Useful for scenarios
|
|
1978
|
+
where array methods and behaviors are needed.
|
|
1979
|
+
|
|
1980
|
+
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array containing all the elements of the iterable.
|
|
1981
|
+
|
|
1982
|
+
#### toStringTag
|
|
1983
|
+
|
|
1984
|
+
Ensures that the constructor of this object instance's name
|
|
1985
|
+
is returned if the string tag for this instance is queried
|
|
1986
|
+
|
|
1987
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
1988
|
+
|
|
1989
|
+
#### isIterable
|
|
1990
|
+
|
|
1991
|
+
Checks if a given value is an iterable. This method determines if the
|
|
1992
|
+
provided value has a `Symbol.iterator` property that is a generator
|
|
1993
|
+
function. It's a precise way to identify if the value conforms to the
|
|
1994
|
+
iterable protocol using a generator function.
|
|
1995
|
+
|
|
1996
|
+
Note: This method specifically checks for generator functions. Some
|
|
1997
|
+
iterables might use regular functions that return an iterator, which
|
|
1998
|
+
this method won't identify.
|
|
1999
|
+
|
|
2000
|
+
##### Parameters
|
|
2001
|
+
|
|
2002
|
+
* `value` **any** The value to be checked for iterability.
|
|
2003
|
+
|
|
2004
|
+
Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if the value is an iterable implemented
|
|
2005
|
+
using a generator function, false otherwise.
|
|
2006
|
+
|
|
2007
|
+
### Iterator
|
|
2008
|
+
|
|
2009
|
+
Being able to create a compliant `Iterator` around any type of iterable
|
|
2010
|
+
object. This can be wrapped around any type of object that has a
|
|
2011
|
+
`[Symbol.iterator]` property assigned to a generator function.
|
|
2012
|
+
|
|
2013
|
+
#### Parameters
|
|
2014
|
+
|
|
2015
|
+
* `iterable` **[object](#object)** any object that has a `[Symbol.iterator]`
|
|
2016
|
+
property assigned to a generator function.
|
|
2017
|
+
* `mapEach` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** when provided `mapEach` is a callback that
|
|
2018
|
+
takes an entry as input and receives one as output.
|
|
2019
|
+
|
|
2020
|
+
#### asArray
|
|
2021
|
+
|
|
2022
|
+
Returns a new `Array` derived from the iterable this object
|
|
2023
|
+
wraps.
|
|
2024
|
+
|
|
2025
|
+
Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** a new `Array` generated from the wrapped
|
|
2026
|
+
iterable. The method is generated from `Array.from()`
|
|
2027
|
+
|
|
2028
|
+
#### iterable
|
|
2029
|
+
|
|
2030
|
+
Returns the actual iterable object passed to the constructor that
|
|
2031
|
+
created this instance.
|
|
2032
|
+
|
|
2033
|
+
Returns **[object](#object)** the object containing the `[Symbol.iterator]`
|
|
2034
|
+
|
|
2035
|
+
#### next
|
|
2036
|
+
|
|
2037
|
+
The function retrieves the next value in the iterator. If the
|
|
2038
|
+
the iterator has run its course, `reset()` can be invoked to
|
|
2039
|
+
reset the pointer to the beginning of the iteration.
|
|
2040
|
+
|
|
2041
|
+
Returns **any** the next value
|
|
2042
|
+
|
|
2043
|
+
#### reset
|
|
2044
|
+
|
|
2045
|
+
Resets the iterator to the beginning allowing it to be
|
|
2046
|
+
iterated over again.
|
|
2047
|
+
|
|
2048
|
+
#### iterator
|
|
2049
|
+
|
|
2050
|
+
The existence of this symbol on the object instances, indicates that
|
|
2051
|
+
it can be used in `for(.. of ..)` loops and its values can be
|
|
2052
|
+
extracted from calls to `Array.from()`
|
|
2053
|
+
|
|
2054
|
+
Returns **[Iterator](#iterator)** this is returned since this object is already
|
|
2055
|
+
conforming to the expected JavaScript Iterator interface
|
|
2056
|
+
|
|
2057
|
+
#### toStringTag
|
|
2058
|
+
|
|
2059
|
+
Ensures that the constructor of this object instance's name
|
|
2060
|
+
is returned if the string tag for this instance is queried
|
|
2061
|
+
|
|
2062
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the class
|
|
2063
|
+
|
|
2064
|
+
### mapEach
|
|
2065
|
+
|
|
2066
|
+
A private function that when provided has the following signature:
|
|
2067
|
+
`function mapEach(entry) -> entry`. This allows any changes to be made
|
|
2068
|
+
to each element, conditionally and programmatically, as needed before
|
|
2069
|
+
they are returned to the called code.
|
|
56
2070
|
|
|
57
2071
|
## Contributing
|
|
58
2072
|
|