]> Lady’s Gitweb - Pisces/blob - object.js
Simplify implementation of defineOwnProperties
[Pisces] / object.js
1 // ♓🌟 Piscēs ∷ object.js
2 // ====================================================================
3 //
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
5 //
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9
10 import {
11 bind,
12 call,
13 createArrowFunction,
14 toFunctionName,
15 } from "./function.js";
16 import {
17 ITERATOR,
18 SPECIES,
19 toLength,
20 toPrimitive,
21 type,
22 } from "./value.js";
23
24 /**
25 * An object whose properties are lazy‐loaded from the methods on the
26 * own properties of the provided object.
27 *
28 * This is useful when you are looking to reference properties on
29 * objects which, due to module dependency graphs, cannot be guaranteed
30 * to have been initialized yet.
31 *
32 * The resulting properties will have the same attributes (regarding
33 * configurability, enumerability, and writability) as the
34 * corresponding properties on the methods object. If a property is
35 * marked as writable, the method will never be called if it is set
36 * before it is gotten. By necessity, the resulting properties are all
37 * configurable before they are accessed for the first time.
38 *
39 * Methods will be called with the resulting object as their this
40 * value.
41 *
42 * `LazyLoader` objects have the same prototype as the passed methods
43 * object.
44 */
45 export class LazyLoader extends null {
46 /**
47 * Constructs a new `LazyLoader` object.
48 *
49 * ☡ This function throws if the provided value is not an object.
50 */
51 constructor(loadMethods) {
52 if (type(loadMethods) !== "object") {
53 // The provided value is not an object; throw an error.
54 throw new TypeError(
55 `Piscēs: Cannot construct LazyLoader: Provided argument is not an object: ${loadMethods}.`,
56 );
57 } else {
58 // The provided value is an object; process it and build the
59 // result.
60 const result = objectCreate(getPrototype(loadMethods));
61 const methodKeys = getOwnPropertyKeys(loadMethods);
62 for (let index = 0; index < methodKeys.length; ++index) {
63 // Iterate over the property keys of the provided object and
64 // define getters and setters appropriately on the result.
65 const methodKey = methodKeys[index];
66 const { configurable, enumerable, writable } =
67 getOwnPropertyDescriptor(loadMethods, methodKey);
68 defineOwnProperty(result, methodKey, {
69 configurable: true,
70 enumerable,
71 get: defineOwnProperty(
72 () => {
73 const value = call(loadMethods[methodKey], result, []);
74 defineOwnProperty(result, methodKey, {
75 configurable,
76 enumerable,
77 value,
78 writable,
79 });
80 return value;
81 },
82 "name",
83 { value: toFunctionName(methodKey, "get") },
84 ),
85 set: writable
86 ? defineOwnProperty(
87 ($) =>
88 defineOwnProperty(result, methodKey, {
89 configurable,
90 enumerable,
91 value: $,
92 writable,
93 }),
94 "name",
95 { value: toFunctionName(methodKey, "set") },
96 )
97 : void {},
98 });
99 }
100 return result;
101 }
102 }
103 }
104
105 /**
106 * A property descriptor object.
107 *
108 * Actually constructing a property descriptor object using this class
109 * is only necessary if you need strict guarantees about the types of
110 * its properties; the resulting object is proxied to ensure the types
111 * match what one would expect from composing FromPropertyDescriptor
112 * and ToPropertyDescriptor in the Ecmascript specification.
113 *
114 * Otherwise, the instance properties and methods are generic.
115 */
116 export const { PropertyDescriptor } = (() => {
117 class PropertyDescriptor extends null {
118 /**
119 * Constructs a new property descriptor object from the provided
120 * object.
121 *
122 * The resulting object is proxied to enforce types (for example,
123 * its `.enumerable` property, if defined, will always be a
124 * boolean).
125 */
126 constructor(O) {
127 if (type(O) !== "object") {
128 // The provided value is not an object.
129 throw new TypeError(
130 `Piscēs: Cannot convert primitive to property descriptor: ${O}.`,
131 );
132 } else {
133 // The provided value is an object.
134 const desc = objectCreate(propertyDescriptorPrototype);
135 if ("enumerable" in O) {
136 // An enumerable property is specified.
137 desc.enumerable = !!O.enumerable;
138 } else {
139 // An enumerable property is not specified.
140 /* do nothing */
141 }
142 if ("configurable" in O) {
143 // A configurable property is specified.
144 desc.configurable = !!O.configurable;
145 } else {
146 // A configurable property is not specified.
147 /* do nothing */
148 }
149 if ("value" in O) {
150 // A value property is specified.
151 desc.value = O.value;
152 } else {
153 // A value property is not specified.
154 /* do nothing */
155 }
156 if ("writable" in O) {
157 // A writable property is specified.
158 desc.writable = !!O.writable;
159 } else {
160 // A writable property is not specified.
161 /* do nothing */
162 }
163 if ("get" in O) {
164 // A get property is specified.
165 const getter = O.get;
166 if (getter !== undefined && typeof getter !== "function") {
167 // The getter is not callable.
168 throw new TypeError("Piscēs: Getters must be callable.");
169 } else {
170 // The getter is callable.
171 desc.get = getter;
172 }
173 } else {
174 // A get property is not specified.
175 /* do nothing */
176 }
177 if ("set" in O) {
178 // A set property is specified.
179 const setter = O.set;
180 if (setter !== undefined && typeof setter !== "function") {
181 // The setter is not callable.
182 throw new TypeError("Piscēs: Setters must be callable.");
183 } else {
184 // The setter is callable.
185 desc.set = setter;
186 }
187 } else {
188 // A set property is not specified.
189 /* do nothing */
190 }
191 if (
192 ("get" in desc || "set" in desc) &&
193 ("value" in desc || "writable" in desc)
194 ) {
195 // Both accessor and data attributes have been defined.
196 throw new TypeError(
197 "Piscēs: Property descriptors cannot specify both accessor and data attributes.",
198 );
199 } else {
200 // The property descriptor is valid.
201 return new Proxy(desc, propertyDescriptorProxyHandler);
202 }
203 }
204 }
205
206 /**
207 * Completes this property descriptor by setting missing values to
208 * their defaults.
209 *
210 * This method modifies this object and returns undefined.
211 */
212 complete() {
213 if (this !== undefined && !("get" in this || "set" in this)) {
214 // This is a generic or data descriptor.
215 if (!("value" in this)) {
216 // `value` is not defined on this.
217 this.value = undefined;
218 } else {
219 // `value` is already defined on this.
220 /* do nothing */
221 }
222 if (!("writable" in this)) {
223 // `writable` is not defined on this.
224 this.writable = false;
225 } else {
226 // `writable` is already defined on this.
227 /* do nothing */
228 }
229 } else {
230 // This is not a generic or data descriptor.
231 if (!("get" in this)) {
232 // `get` is not defined on this.
233 this.get = undefined;
234 } else {
235 // `get` is already defined on this.
236 /* do nothing */
237 }
238 if (!("set" in this)) {
239 // `set` is not defined on this.
240 this.set = undefined;
241 } else {
242 // `set` is already defined on this.
243 /* do nothing */
244 }
245 }
246 if (!("enumerable" in this)) {
247 // `enumerable` is not defined on this.
248 this.enumerable = false;
249 } else {
250 // `enumerable` is already defined on this.
251 /* do nothing */
252 }
253 if (!("configurable" in this)) {
254 // `configurable` is not defined on this.
255 this.configurable = false;
256 } else {
257 // `configurable` is already defined on this.
258 /* do nothing */
259 }
260 }
261
262 /** Gets whether this is an accessor descrtiptor. */
263 get isAccessorDescriptor() {
264 return this !== undefined && ("get" in this || "set" in this);
265 }
266
267 /** Gets whether this is a data descrtiptor. */
268 get isDataDescriptor() {
269 return this !== undefined &&
270 ("value" in this || "writable" in this);
271 }
272
273 /** Gets whether this is a fully‐populated property descriptor. */
274 get isFullyPopulated() {
275 return this !== undefined &&
276 ("value" in this && "writable" in this ||
277 "get" in this && "set" in this) &&
278 "enumerable" in this && "configurable" in this;
279 }
280
281 /**
282 * Gets whether this is a generic (not accessor or data)
283 * descrtiptor.
284 */
285 get isGenericDescriptor() {
286 return this !== undefined &&
287 !("get" in this || "set" in this || "value" in this ||
288 "writable" in this);
289 }
290 }
291
292 const coercePropertyDescriptorValue = (P, V) => {
293 switch (P) {
294 case "configurable":
295 case "enumerable":
296 case "writable":
297 return !!V;
298 case "value":
299 return V;
300 case "get":
301 if (V !== undefined && typeof V !== "function") {
302 throw new TypeError(
303 "Piscēs: Getters must be callable.",
304 );
305 } else {
306 return V;
307 }
308 case "set":
309 if (V !== undefined && typeof V !== "function") {
310 throw new TypeError(
311 "Piscēs: Setters must be callable.",
312 );
313 } else {
314 return V;
315 }
316 default:
317 return V;
318 }
319 };
320
321 const {
322 prototype: propertyDescriptorPrototype,
323 } = PropertyDescriptor;
324
325 const propertyDescriptorProxyHandler = Object.assign(
326 Object.create(null),
327 {
328 defineProperty(O, P, Desc) {
329 if (
330 P === "configurable" || P === "enumerable" ||
331 P === "writable" || P === "value" ||
332 P === "get" || P === "set"
333 ) {
334 // P is a property descriptor attribute.
335 const desc = new PropertyDescriptor(Desc);
336 if ("get" in desc || "set" in desc) {
337 // Desc is an accessor property descriptor.
338 throw new TypeError(
339 "Piscēs: Property descriptor attributes must be data properties.",
340 );
341 } else if ("value" in desc || !(P in O)) {
342 // Desc has a value or P does not already exist on O.
343 desc.value = coercePropertyDescriptorValue(P, desc.value);
344 } else {
345 // Desc is not an accessor property descriptor and has no
346 // value.
347 /* do nothing */
348 }
349 const isAccessorDescriptor = "get" === P || "set" === P ||
350 "get" in O || "set" in O;
351 const isDataDescriptor = "value" === P || "writable" === P ||
352 "value" in O || "writable" in O;
353 if (isAccessorDescriptor && isDataDescriptor) {
354 // Both accessor and data attributes will be present on O
355 // after defining P.
356 throw new TypeError(
357 "Piscēs: Property descriptors cannot specify both accessor and data attributes.",
358 );
359 } else {
360 // P can be safely defined on O.
361 return defineOwnProperty(O, P, desc);
362 }
363 } else {
364 // P is not a property descriptor attribute.
365 return defineOwnProperty(O, P, Desc);
366 }
367 },
368 set(O, P, V, Receiver) {
369 if (
370 P === "configurable" || P === "enumerable" ||
371 P === "writable" || P === "value" ||
372 P === "get" || P === "set"
373 ) {
374 // P is a property descriptor attribute.
375 const newValue = coercePropertyDescriptorValue(P, V);
376 const isAccessorDescriptor = "get" === P || "set" === P ||
377 "get" in O || "set" in O;
378 const isDataDescriptor = "value" === P || "writable" === P ||
379 "value" in O || "writable" in O;
380 if (isAccessorDescriptor && isDataDescriptor) {
381 // Both accessor and data attributes will be present on O
382 // after defining P.
383 throw new TypeError(
384 "Piscēs: Property descriptors cannot specify both accessor and data attributes.",
385 );
386 } else {
387 // P can be safely defined on O.
388 //
389 // ☡ Receiver will be the *proxied* object, so passing it
390 // through to setPropertyValue here would produce an
391 // infinite loop.
392 //
393 // ☡ This has implications on objects with a proxied
394 // PropertyDescriptor in their prototype.
395 return setPropertyValue(O, P, newValue, O);
396 }
397 } else {
398 return setPropertyValue(O, P, V, Receiver);
399 }
400 },
401 setPrototypeOf(O, V) {
402 if (V !== propertyDescriptorPrototype) {
403 // V is not the property descriptor prototype.
404 return false;
405 } else {
406 // V is the property descriptor prototype.
407 return setPrototype(O, V);
408 }
409 },
410 },
411 );
412
413 return { PropertyDescriptor };
414 })();
415
416 /**
417 * Defines an own property on the provided object on the provided
418 * property key using the provided property descriptor.
419 *
420 * ※ This is effectively an alias for `Object.defineProperty`.
421 */
422 export const defineOwnProperty = createArrowFunction(
423 Object.defineProperty,
424 { name: "defineOwnProperty" },
425 );
426
427 export const {
428 /**
429 * Defines own properties on the provided object using the
430 * descriptors on the enumerable own properties of the provided
431 * additional objects.
432 *
433 * ※ This differs from `Object.defineProperties` in that it can take
434 * multiple source objects.
435 */
436 defineOwnProperties,
437
438 /**
439 * Returns a new frozen shallow copy of the enumerable own properties
440 * of the provided object, according to the following rules :—
441 *
442 * - For data properties, create a nonconfigurable, nonwritable
443 * property with the same value.
444 *
445 * - For accessor properties, create a nonconfigurable accessor
446 * property with the same getter *and* setter.
447 *
448 * The prototype for the resulting object will be taken from the
449 * `.prototype` property of the provided constructor, or the
450 * `.prototype` of the `.constructor` of the provided object if the
451 * provided constructor is undefined. If the used constructor has a
452 * nonnullish `.[Symbol.species]`, that will be used instead. If the
453 * used constructor or species is nullish or does not have a
454 * `.prototype` property, the prototype is set to null.
455 *
456 * ※ The prototype of the provided object itself is ignored.
457 */
458 frozenCopy,
459
460 /**
461 * Returns whether the provided object is frozen.
462 *
463 * ※ This function returns false for nonobjects.
464 *
465 * ※ This is effectively an alias for `!Object.isFrozen`.
466 */
467 isUnfrozenObject,
468
469 /**
470 * Returns whether the provided object is sealed.
471 *
472 * ※ This function returns false for nonobjects.
473 *
474 * ※ This is effectively an alias for `!Object.isSealed`.
475 */
476 isUnsealedObject,
477
478 /**
479 * Sets the prototype of the provided object to the provided value
480 * and returns the object.
481 *
482 * ※ This is effectively an alias for `Object.setPrototypeOf`.
483 */
484 setPrototype,
485
486 /**
487 * Returns the provided value converted to an object.
488 *
489 * Existing objects are returned with no modification.
490 *
491 * ☡ This function throws if its argument is null or undefined.
492 */
493 toObject,
494 } = (() => {
495 const createObject = Object;
496 const {
497 create,
498 defineProperties,
499 getPrototypeOf,
500 isFrozen,
501 isSealed,
502 setPrototypeOf,
503 } = Object;
504 const {
505 next: generatorIteratorNext,
506 } = getPrototypeOf(function* () {}.prototype);
507 const propertyDescriptorEntryIterablePrototype = {
508 [ITERATOR]() {
509 return {
510 next: bind(generatorIteratorNext, this.generator(), []),
511 };
512 },
513 };
514 const propertyDescriptorEntryIterable = ($) =>
515 create(propertyDescriptorEntryIterablePrototype, {
516 generator: { value: $ },
517 });
518
519 return {
520 defineOwnProperties: (O, ...sources) => {
521 const { length } = sources;
522 for (let index = 0; index < length; ++index) {
523 defineProperties(O, sources[index]);
524 }
525 return O;
526 },
527 frozenCopy: (O, constructor = O?.constructor) => {
528 if (O == null) {
529 // O is null or undefined.
530 throw new TypeError(
531 "Piscēs: Cannot copy properties of null or undefined.",
532 );
533 } else {
534 // O is not null or undefined.
535 //
536 // (If not provided, the constructor will be the value of
537 // getting the `.constructor` property of O.)
538 const species = constructor?.[SPECIES] ?? constructor;
539 return preventExtensions(
540 objectCreate(
541 species == null || !("prototype" in species)
542 ? null
543 : species.prototype,
544 objectFromEntries(
545 propertyDescriptorEntryIterable(function* () {
546 const ownPropertyKeys = getOwnPropertyKeys(O);
547 for (
548 let i = 0;
549 i < ownPropertyKeys.length;
550 ++i
551 ) {
552 const P = ownPropertyKeys[i];
553 const Desc = getOwnPropertyDescriptor(O, P);
554 if (Desc.enumerable) {
555 // P is an enumerable property.
556 yield [
557 P,
558 "get" in Desc || "set" in Desc
559 ? {
560 configurable: false,
561 enumerable: true,
562 get: Desc.get,
563 set: Desc.set,
564 }
565 : {
566 configurable: false,
567 enumerable: true,
568 value: Desc.value,
569 writable: false,
570 },
571 ];
572 } else {
573 // P is not an enumerable property.
574 /* do nothing */
575 }
576 }
577 }),
578 ),
579 ),
580 );
581 }
582 },
583 isUnfrozenObject: (O) => !isFrozen(O),
584 isUnsealedObject: (O) => !isSealed(O),
585 setPrototype: (O, proto) => {
586 const obj = toObject(O);
587 if (O === obj) {
588 // The provided value is an object; set its prototype normally.
589 return setPrototypeOf(O, proto);
590 } else {
591 // The provided value is not an object; attempt to set the
592 // prototype on a coerced version with extensions prevented,
593 // then return the provided value.
594 //
595 // This will throw if the given prototype does not match the
596 // existing one on the coerced object.
597 setPrototypeOf(preventExtensions(obj), proto);
598 return O;
599 }
600 },
601 toObject: ($) => {
602 if ($ == null) {
603 // The provided value is nullish; this is an error.
604 throw new TypeError(
605 `Piscēs: Cannot convert ${$} into an object.`,
606 );
607 } else {
608 // The provided value is not nullish; coerce it to an object.
609 return createObject($);
610 }
611 },
612 };
613 })();
614
615 export const {
616 /**
617 * Removes the provided property key from the provided object and
618 * returns the object.
619 *
620 * ※ This function differs from `Reflect.deleteProperty` and the
621 * `delete` operator in that it throws if the deletion is
622 * unsuccessful.
623 *
624 * ☡ This function throws if the first argument is not an object.
625 */
626 deleteOwnProperty,
627
628 /**
629 * Returns an array of property keys on the provided object.
630 *
631 * ※ This is effectively an alias for `Reflect.ownKeys`, except that
632 * it does not require that the argument be an object.
633 */
634 getOwnPropertyKeys,
635
636 /**
637 * Returns the value of the provided property key on the provided
638 * object.
639 *
640 * ※ This is effectively an alias for `Reflect.get`, except that it
641 * does not require that the argument be an object.
642 */
643 getPropertyValue,
644
645 /**
646 * Returns whether the provided property key exists on the provided
647 * object.
648 *
649 * ※ This is effectively an alias for `Reflect.has`, except that it
650 * does not require that the argument be an object.
651 *
652 * ※ This includes properties present on the prototype chain.
653 */
654 hasProperty,
655
656 /**
657 * Sets the provided property key to the provided value on the
658 * provided object and returns the object.
659 *
660 * ※ This function differs from `Reflect.set` in that it throws if
661 * the setting is unsuccessful.
662 *
663 * ☡ This function throws if the first argument is not an object.
664 */
665 setPropertyValue,
666 } = (() => {
667 const { deleteProperty, get, has, ownKeys, set } = Reflect;
668
669 return {
670 deleteOwnProperty: (O, P) => {
671 if (type(O) !== "object") {
672 throw new TypeError(
673 `Piscēs: Tried to set property but provided value was not an object: ${V}`,
674 );
675 } else if (!deleteProperty(O, P)) {
676 throw new TypeError(
677 `Piscēs: Tried to delete property from object but [[Delete]] returned false: ${P}`,
678 );
679 } else {
680 return O;
681 }
682 },
683 getOwnPropertyKeys: (O) => ownKeys(toObject(O)),
684 getPropertyValue: (O, P, Receiver = O) =>
685 get(toObject(O), P, Receiver),
686 hasProperty: (O, P) => has(toObject(O), P),
687 setPropertyValue: (O, P, V, Receiver = O) => {
688 if (type(O) !== "object") {
689 throw new TypeError(
690 `Piscēs: Tried to set property but provided value was not an object: ${V}`,
691 );
692 } else if (!set(O, P, V, Receiver)) {
693 throw new TypeError(
694 `Piscēs: Tried to set property on object but [[Set]] returned false: ${P}`,
695 );
696 } else {
697 return O;
698 }
699 },
700 };
701 })();
702
703 /**
704 * Marks the provided object as non·extensible and marks all its
705 * properties as nonconfigurable and (if data properties) nonwritable,
706 * and returns the object.
707 *
708 * ※ This is effectively an alias for `Object.freeze`.
709 */
710 export const freeze = createArrowFunction(Object.freeze);
711
712 /**
713 * Returns the function on the provided value at the provided property
714 * key.
715 *
716 * ☡ This function throws if the provided property key does not have an
717 * associated value which is callable.
718 */
719 export const getMethod = (V, P) => {
720 const func = getPropertyValue(V, P);
721 if (func == null) {
722 return undefined;
723 } else if (typeof func !== "function") {
724 throw new TypeError(`Piscēs: Method not callable: ${P}`);
725 } else {
726 return func;
727 }
728 };
729
730 /**
731 * Returns the property descriptor for the own property with the
732 * provided property key on the provided object, or null if none
733 * exists.
734 *
735 * ※ This is effectively an alias for
736 * `Object.getOwnPropertyDescriptor`.
737 */
738 export const getOwnPropertyDescriptor = createArrowFunction(
739 Object.getOwnPropertyDescriptor,
740 );
741
742 /**
743 * Returns the property descriptors for the own properties on the
744 * provided object.
745 *
746 * ※ This is effectively an alias for
747 * `Object.getOwnPropertyDescriptors`.
748 */
749 export const getOwnPropertyDescriptors = createArrowFunction(
750 Object.getOwnPropertyDescriptors,
751 );
752
753 /**
754 * Returns an array of string‐valued own property keys on the
755 * provided object.
756 *
757 * ☡ This includes both enumerable and non·enumerable properties.
758 *
759 * ※ This is effectively an alias for `Object.getOwnPropertyNames`.
760 */
761 export const getOwnPropertyStrings = createArrowFunction(
762 Object.getOwnPropertyNames,
763 { name: "getOwnPropertyStrings" },
764 );
765
766 /**
767 * Returns an array of symbol‐valued own property keys on the
768 * provided object.
769 *
770 * ☡ This includes both enumerable and non·enumerable properties.
771 *
772 * ※ This is effectively an alias for
773 * `Object.getOwnPropertySymbols`.
774 */
775 export const getOwnPropertySymbols = createArrowFunction(
776 Object.getOwnPropertySymbols,
777 );
778
779 /**
780 * Returns the prototype of the provided object.
781 *
782 * ※ This is effectively an alias for `Object.getPrototypeOf`.
783 */
784 export const getPrototype = createArrowFunction(
785 Object.getPrototypeOf,
786 { name: "getPrototype" },
787 );
788
789 /**
790 * Returns whether the provided object has an own property with the
791 * provided property key.
792 *
793 * ※ This is effectively an alias for `Object.hasOwn`.
794 */
795 export const hasOwnProperty = createArrowFunction(Object.hasOwn, {
796 name: "hasOwnProperty",
797 });
798
799 /** Returns whether the provided value is an arraylike object. */
800 export const isArraylikeObject = ($) => {
801 if (type($) !== "object") {
802 return false;
803 } else {
804 try {
805 lengthOfArraylike($); // throws if not arraylike
806 return true;
807 } catch {
808 return false;
809 }
810 }
811 };
812
813 /**
814 * Returns whether the provided object is extensible.
815 *
816 * ※ This function returns false for nonobjects.
817 *
818 * ※ This is effectively an alias for `Object.isExtensible`.
819 */
820 export const isExtensibleObject = createArrowFunction(
821 Object.isExtensible,
822 { name: "isExtensibleObject" },
823 );
824
825 /**
826 * Returns the length of the provided arraylike value.
827 *
828 * This can produce larger lengths than can actually be stored in
829 * arrays, because no such restrictions exist on arraylike methods.
830 *
831 * ☡ This function throws if the provided value is not arraylike.
832 */
833 export const lengthOfArraylike = ({ length }) => toLength(length);
834
835 /**
836 * Returns an array of key~value pairs for the enumerable,
837 * string‐valued property keys on the provided object.
838 *
839 * ※ This is effectively an alias for `Object.entries`.
840 */
841 export const namedEntries = createArrowFunction(Object.entries, {
842 name: "namedEntries",
843 });
844
845 /**
846 * Returns an array of the enumerable, string‐valued property keys on
847 * the provided object.
848 *
849 * ※ This is effectively an alias for `Object.keys`.
850 */
851 export const namedKeys = createArrowFunction(Object.keys, {
852 name: "namedKeys",
853 });
854
855 /**
856 * Returns an array of property values for the enumerable,
857 * string‐valued property keys on the provided object.
858 *
859 * ※ This is effectively an alias for `Object.values`.
860 */
861 export const namedValues = createArrowFunction(Object.values, {
862 name: "namedValues",
863 });
864
865 /**
866 * Returns a new object with the provided prototype and property
867 * descriptors.
868 *
869 * ※ This is effectively an alias for `Object.create`.
870 */
871 export const objectCreate = createArrowFunction(Object.create, {
872 name: "objectCreate",
873 });
874
875 /**
876 * Returns a new object with the provided property keys and values.
877 *
878 * ※ This is effectively an alias for `Object.fromEntries`.
879 */
880 export const objectFromEntries = createArrowFunction(
881 Object.fromEntries,
882 { name: "objectFromEntries" },
883 );
884
885 /**
886 * Marks the provided object as non·extensible, and returns the
887 * object.
888 *
889 * ※ This is effectively an alias for `Object.preventExtensions`.
890 */
891 export const preventExtensions = createArrowFunction(
892 Object.preventExtensions,
893 );
894
895 /**
896 * Marks the provided object as non·extensible and marks all its
897 * properties as nonconfigurable, and returns the object.
898 *
899 * ※ This is effectively an alias for `Object.seal`.
900 */
901 export const seal = createArrowFunction(Object.seal);
902
903 /**
904 * Sets the values of the enumerable own properties of the provided
905 * additional objects on the provided object.
906 *
907 * ※ This is effectively an alias for `Object.assign`.
908 */
909 export const setPropertyValues = createArrowFunction(Object.assign, {
910 name: "setPropertyValues",
911 });
912
913 /**
914 * Returns the property key (symbol or string) corresponding to the
915 * provided value.
916 */
917 export const toPropertyKey = ($) => {
918 const key = toPrimitive($, "string");
919 return typeof key === "symbol" ? key : `${key}`;
920 };
This page took 0.57738 seconds and 5 git commands to generate.