@nejs/basic-extensions 2.9.0 → 2.11.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.
Files changed (176) hide show
  1. package/dist/@nejs/basic-extensions.bundle.2.11.0.js +19 -0
  2. package/dist/@nejs/basic-extensions.bundle.2.11.0.js.map +7 -0
  3. package/dist/cjs/array.extensions.js +174 -0
  4. package/dist/cjs/array.extensions.js.map +1 -1
  5. package/dist/cjs/big.int.extension.js +1 -0
  6. package/dist/cjs/big.int.extension.js.map +1 -1
  7. package/dist/cjs/classes/descriptor.d.ts +67 -155
  8. package/dist/cjs/classes/descriptor.js +185 -278
  9. package/dist/cjs/classes/descriptor.js.map +1 -1
  10. package/dist/cjs/classes/index.d.ts +1 -0
  11. package/dist/cjs/classes/index.js +3 -0
  12. package/dist/cjs/classes/index.js.map +1 -1
  13. package/dist/cjs/classes/iterable.d.ts +44 -0
  14. package/dist/cjs/classes/iterable.js +64 -0
  15. package/dist/cjs/classes/iterable.js.map +1 -1
  16. package/dist/cjs/classes/param.parser.d.ts +10 -10
  17. package/dist/cjs/classes/property.d.ts +86 -0
  18. package/dist/cjs/classes/property.js +284 -0
  19. package/dist/cjs/classes/property.js.map +1 -0
  20. package/dist/cjs/classes/symkeys.d.ts +68 -11
  21. package/dist/cjs/classes/symkeys.js +103 -17
  22. package/dist/cjs/classes/symkeys.js.map +1 -1
  23. package/dist/cjs/classes/type.d.ts +4 -4
  24. package/dist/cjs/function.extensions.js +1 -0
  25. package/dist/cjs/function.extensions.js.map +1 -1
  26. package/dist/cjs/global.this.js +29 -0
  27. package/dist/cjs/global.this.js.map +1 -1
  28. package/dist/cjs/index.d.ts +3 -0
  29. package/dist/cjs/index.js +19 -0
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/json.extensions.js +19 -18
  32. package/dist/cjs/json.extensions.js.map +1 -1
  33. package/dist/cjs/map.extensions.js +1 -0
  34. package/dist/cjs/map.extensions.js.map +1 -1
  35. package/dist/cjs/number.extension.js +1 -0
  36. package/dist/cjs/number.extension.js.map +1 -1
  37. package/dist/cjs/object.extensions.d.ts +0 -29
  38. package/dist/cjs/object.extensions.js +218 -255
  39. package/dist/cjs/object.extensions.js.map +1 -1
  40. package/dist/cjs/set.extensions.js +1 -0
  41. package/dist/cjs/set.extensions.js.map +1 -1
  42. package/dist/cjs/string.extensions.js +474 -469
  43. package/dist/cjs/string.extensions.js.map +1 -1
  44. package/dist/cjs/symbol.extensions.js +387 -32
  45. package/dist/cjs/symbol.extensions.js.map +1 -1
  46. package/dist/cjs/utils/copy.object.d.ts +408 -0
  47. package/dist/cjs/utils/copy.object.js +720 -0
  48. package/dist/cjs/utils/copy.object.js.map +1 -0
  49. package/dist/cjs/utils/descriptor.utils.d.ts +146 -0
  50. package/dist/cjs/utils/descriptor.utils.js +614 -0
  51. package/dist/cjs/utils/descriptor.utils.js.map +1 -0
  52. package/dist/cjs/utils/index.d.ts +60 -0
  53. package/dist/cjs/utils/index.js +52 -0
  54. package/dist/cjs/utils/index.js.map +1 -0
  55. package/dist/cjs/utils/toolkit.d.ts +1898 -0
  56. package/dist/cjs/utils/toolkit.js +1378 -0
  57. package/dist/cjs/utils/toolkit.js.map +1 -0
  58. package/dist/mjs/array.extensions.js +174 -0
  59. package/dist/mjs/array.extensions.js.map +1 -1
  60. package/dist/mjs/big.int.extension.js +1 -0
  61. package/dist/mjs/big.int.extension.js.map +1 -1
  62. package/dist/mjs/classes/descriptor.d.ts +67 -155
  63. package/dist/mjs/classes/descriptor.js +185 -278
  64. package/dist/mjs/classes/descriptor.js.map +1 -1
  65. package/dist/mjs/classes/index.d.ts +1 -0
  66. package/dist/mjs/classes/index.js +3 -0
  67. package/dist/mjs/classes/index.js.map +1 -1
  68. package/dist/mjs/classes/iterable.d.ts +44 -0
  69. package/dist/mjs/classes/iterable.js +64 -0
  70. package/dist/mjs/classes/iterable.js.map +1 -1
  71. package/dist/mjs/classes/param.parser.d.ts +10 -10
  72. package/dist/mjs/classes/property.d.ts +86 -0
  73. package/dist/mjs/classes/property.js +280 -0
  74. package/dist/mjs/classes/property.js.map +1 -0
  75. package/dist/mjs/classes/symkeys.d.ts +68 -11
  76. package/dist/mjs/classes/symkeys.js +103 -17
  77. package/dist/mjs/classes/symkeys.js.map +1 -1
  78. package/dist/mjs/classes/type.d.ts +4 -4
  79. package/dist/mjs/function.extensions.js +1 -0
  80. package/dist/mjs/function.extensions.js.map +1 -1
  81. package/dist/mjs/global.this.js +6 -0
  82. package/dist/mjs/global.this.js.map +1 -1
  83. package/dist/mjs/index.d.ts +3 -0
  84. package/dist/mjs/index.js +5 -0
  85. package/dist/mjs/index.js.map +1 -1
  86. package/dist/mjs/json.extensions.js +19 -18
  87. package/dist/mjs/json.extensions.js.map +1 -1
  88. package/dist/mjs/map.extensions.js +1 -0
  89. package/dist/mjs/map.extensions.js.map +1 -1
  90. package/dist/mjs/number.extension.js +1 -0
  91. package/dist/mjs/number.extension.js.map +1 -1
  92. package/dist/mjs/object.extensions.d.ts +0 -29
  93. package/dist/mjs/object.extensions.js +215 -251
  94. package/dist/mjs/object.extensions.js.map +1 -1
  95. package/dist/mjs/set.extensions.js +1 -0
  96. package/dist/mjs/set.extensions.js.map +1 -1
  97. package/dist/mjs/string.extensions.js +474 -469
  98. package/dist/mjs/string.extensions.js.map +1 -1
  99. package/dist/mjs/symbol.extensions.js +387 -32
  100. package/dist/mjs/symbol.extensions.js.map +1 -1
  101. package/dist/mjs/utils/copy.object.d.ts +408 -0
  102. package/dist/mjs/utils/copy.object.js +702 -0
  103. package/dist/mjs/utils/copy.object.js.map +1 -0
  104. package/dist/mjs/utils/descriptor.utils.d.ts +146 -0
  105. package/dist/mjs/utils/descriptor.utils.js +606 -0
  106. package/dist/mjs/utils/descriptor.utils.js.map +1 -0
  107. package/dist/mjs/utils/index.d.ts +60 -0
  108. package/dist/mjs/utils/index.js +36 -0
  109. package/dist/mjs/utils/index.js.map +1 -0
  110. package/dist/mjs/utils/toolkit.d.ts +1898 -0
  111. package/dist/mjs/utils/toolkit.js +1373 -0
  112. package/dist/mjs/utils/toolkit.js.map +1 -0
  113. package/package.json +29 -37
  114. package/repl.bootstrap.js +12 -1
  115. package/src/array.extensions.js +191 -1
  116. package/src/big.int.extension.js +3 -1
  117. package/src/classes/descriptor.js +206 -305
  118. package/src/classes/index.js +4 -0
  119. package/src/classes/iterable.js +74 -0
  120. package/src/classes/property.js +333 -0
  121. package/src/classes/symkeys.js +120 -19
  122. package/src/function.extensions.js +2 -0
  123. package/src/global.this.js +8 -0
  124. package/src/index.js +6 -0
  125. package/src/json.extensions.js +18 -19
  126. package/src/map.extensions.js +3 -1
  127. package/src/number.extension.js +3 -1
  128. package/src/object.extensions.js +240 -277
  129. package/src/set.extensions.js +3 -1
  130. package/src/string.extensions.js +512 -506
  131. package/src/symbol.extensions.js +413 -30
  132. package/src/utils/copy.object.js +780 -0
  133. package/src/utils/descriptor.utils.js +707 -0
  134. package/src/utils/index.js +74 -0
  135. package/src/utils/toolkit.js +1473 -0
  136. package/tests/arrayextensions.test.js +2 -0
  137. package/tests/index.test.js +1 -0
  138. package/tests/newClasses/asyncIterable.test.js +2 -0
  139. package/tests/newClasses/deferred.test.js +5 -3
  140. package/tests/newClasses/descriptor.test.js +6 -8
  141. package/tests/newClasses/iterable.test.js +2 -0
  142. package/tests/newClasses/refmap.test.js +2 -1
  143. package/tests/newClasses/refset.test.js +2 -0
  144. package/tests/objectextensions.test.js +2 -0
  145. package/tests/setextensions.test.js +2 -0
  146. package/tests/stringextensions.test.js +1 -0
  147. package/tests/utils/toolkit.test.js +223 -0
  148. package/tsconfig.base.json +1 -1
  149. package/vitest.config.js +7 -0
  150. package/dist/@nejs/basic-extensions.bundle.2.8.0.js +0 -19
  151. package/dist/@nejs/basic-extensions.bundle.2.8.0.js.map +0 -7
  152. package/docs/assets/anchor.js +0 -350
  153. package/docs/assets/bass-addons.css +0 -12
  154. package/docs/assets/bass.css +0 -544
  155. package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
  156. package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
  157. package/docs/assets/fonts/LICENSE.txt +0 -93
  158. package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
  159. package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
  160. package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
  161. package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
  162. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
  163. package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
  164. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
  165. package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
  166. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
  167. package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
  168. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
  169. package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
  170. package/docs/assets/fonts/source-code-pro.css +0 -23
  171. package/docs/assets/github.css +0 -123
  172. package/docs/assets/site.js +0 -168
  173. package/docs/assets/split.css +0 -15
  174. package/docs/assets/split.js +0 -782
  175. package/docs/assets/style.css +0 -147
  176. package/docs/index.html +0 -35485
@@ -1 +1 @@
1
- {"version":3,"file":"number.extension.js","sourceRoot":"","sources":["../../src/number.extension.js"],"names":[],"mappings":";;;AAAA,+CAAuC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,gBAAgB,GAAG,IAAI,iBAAK,CAAC,MAAM,EAAE;IAChD,CAAC,iBAAK,CAAC,cAAc,CAAC,EAAE;QACtB;;;;;;;;;;;;;;;;;;WAkBG;QACH,QAAQ,CAAC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AC,KAAK,IAAI,OAAO,KAAK,KAAK,UAAU,CAAA,CAAC,CAAC;IAE1D,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnE,IAAI,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;QACrE,CAAC;QAAC,OAAO,EAAE,IAAI,KAAK,CAAC;IACvB,CAAC;IAAC,OAAO,EAAE,CAAA;AACb,CAAC"}
@@ -1,32 +1,3 @@
1
- /**
2
- * Creates a deep or shallow copy of the provided source objects and merges
3
- * them into the destination object. The function uses a Set to keep track
4
- * of visited objects to avoid circular references.
5
- *
6
- * @function
7
- * @name copyObject
8
- * @param {boolean} deep - If true, performs a deep copy, otherwise performs
9
- * a shallow copy.
10
- * @param {object} destination - The object to which properties will be copied.
11
- * @param {...object} sources - The source object(s) from which properties
12
- * will be copied.
13
- * @returns {object} The destination object with the copied properties.
14
- *
15
- * @example
16
- * // Shallow copy
17
- * const obj1 = { a: 1, b: { c: 2 } };
18
- * const obj2 = { b: { d: 3 }, e: 4 };
19
- * const result = copyObject(false, obj1, obj2);
20
- * console.log(result); // Output: { a: 1, b: { d: 3 }, e: 4 }
21
- *
22
- * @example
23
- * // Deep copy
24
- * const obj1 = { a: 1, b: { c: 2 } };
25
- * const obj2 = { b: { d: 3 }, e: 4 };
26
- * const result = copyObject(true, obj1, obj2);
27
- * console.log(result); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }
28
- */
29
- export function copyObject(deep: boolean, destination: object, ...sources: object[]): object;
30
1
  /**
31
2
  * `ObjectExtensions` is a constant that applies a patch to the global
32
3
  * `Object` constructor. This patch extends the `Object` with additional
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyObject = exports.ObjectPrototypeExtensions = exports.ObjectExtensions = void 0;
3
+ exports.ObjectPrototypeExtensions = exports.ObjectExtensions = void 0;
4
4
  const extension_1 = require("@nejs/extension");
5
5
  const symbol_extensions_js_1 = require("./symbol.extensions.js");
6
6
  const descriptor_js_1 = require("./classes/descriptor.js");
7
+ const property_js_1 = require("./classes/property.js");
8
+ const toolkit_js_1 = require("./utils/toolkit.js");
9
+ const copy_object_js_1 = require("./utils/copy.object.js");
7
10
  const { keys: symkeys } = symbol_extensions_js_1.SymbolExtensions.patches;
8
- // Avoid circular dependencies; rewrite here for brevity
9
- const isFn = o => typeof o === 'function' || o instanceof Function;
10
- const isStr = o => typeof o === 'string' || o instanceof String;
11
- const isBool = o => typeof o === 'boolean';
12
- const isTrue = o => isBool(o) && o === true;
13
- const isTruthy = o => isTrue(!!o);
14
- const isFalse = o => isBool(o) && o === false;
15
- const isFalsy = o => isFalse(!!o);
16
11
  /**
17
12
  * `ObjectExtensions` is a constant that applies a patch to the global
18
13
  * `Object` constructor. This patch extends the `Object` with additional
@@ -27,6 +22,112 @@ const isFalsy = o => isFalse(!!o);
27
22
  */
28
23
  exports.ObjectExtensions = new extension_1.Patch(Object, {
29
24
  [extension_1.Patch.kMutablyHidden]: {
25
+ add(...args) {
26
+ const { isDescriptor } = descriptor_js_1.Descriptor;
27
+ const { isObject: isObj } = this;
28
+ const { kDescriptorStore } = this;
29
+ let obj, key, value, _get, _set, storage, storageKey;
30
+ let _type, _flag, _desc;
31
+ // Check to see if we received multiple arguments or an object
32
+ if (args.length && isObj(args[0])) {
33
+ ({
34
+ to: obj,
35
+ key,
36
+ value,
37
+ get: _get,
38
+ set: _set,
39
+ storage,
40
+ storageKey,
41
+ type: _type = ['accessor', 'data'][1],
42
+ flag: _flag = undefined,
43
+ descriptorBase: _desc = undefined,
44
+ } = args[0]);
45
+ }
46
+ else if (args.length > 1) {
47
+ ([
48
+ to,
49
+ _type,
50
+ key,
51
+ getOrValue,
52
+ _set,
53
+ storage,
54
+ storageKey,
55
+ _flag,
56
+ _desc,
57
+ ] = args);
58
+ obj = to;
59
+ _type = (['accessor', 'data'].includes(_type.toLowerCase())
60
+ ? _type.toLowerCase() : 'data');
61
+ _get = _type === 'accessor' ? getOrValue : undefined;
62
+ _value = _type === 'data' ? getOrValue : undefined;
63
+ }
64
+ if (!this.isObject(obj)) {
65
+ console.warn('Object.add() must receive an object for `toObject`');
66
+ return obj;
67
+ }
68
+ const more = isDescriptor(_desc) ? _desc : {};
69
+ const flag = _flag || Object.definitionType.mutablyVisible;
70
+ const props = { ...extension_1.Patch.getDescriptorOverridesFromSymbol(flag), ...more };
71
+ const type = (['accessor', 'data'].includes(_type)
72
+ ? String(_type).toLowerCase() : 'data');
73
+ switch (type) {
74
+ case 'accessor':
75
+ let store = storage;
76
+ let storeKey = storageKey || key;
77
+ let makeStore = false;
78
+ let get = _get;
79
+ let set = _set;
80
+ if (!toolkit_js_1.is.truthy(get) && !toolkit_js_1.is.function(get)) {
81
+ get = undefined;
82
+ }
83
+ if (!toolkit_js_1.is.truthy(set) && !toolkit_js_1.is.function(set)) {
84
+ set = undefined;
85
+ }
86
+ if (isObj(store) || toolkit_js_1.is.true(store) || toolkit_js_1.is.function(store)) {
87
+ makeStore = toolkit_js_1.is.true(store);
88
+ store = toolkit_js_1.is.fn(store) ? store() : store;
89
+ store = toolkit_js_1.is.object(store) ? store : (makeStore && {} || undefined);
90
+ }
91
+ // store should be defined by here: object or undefined
92
+ if ((!get && !set) && makeStore) {
93
+ // being lazy here, someone has defined we make an accessor but
94
+ // wants the default accessor behaviors with an associated store
95
+ // made by us.
96
+ Object.defineProperty(obj, kDescriptorStore, {
97
+ value: symkeys.add('descriptor.store', store),
98
+ configurable: true,
99
+ enumerable: false,
100
+ writable: true,
101
+ });
102
+ get = () => this[kDescriptorStore]?.data?.[storeKey];
103
+ set = (value) => { this[kDescriptorStore].data[storeKey] = value; };
104
+ }
105
+ else if (get?.length && set?.length > 1 && store) {
106
+ // if we received a get or set that takes more arguments than
107
+ // expected, assume the last argument should be the store variable
108
+ // so we execute the supplied function with the storage and its
109
+ // results or byproducts are the result to the get/set we define
110
+ const innerGet = get;
111
+ const innerSet = set;
112
+ get = () => innerGet(store);
113
+ set = (value) => innerSet(value, store);
114
+ }
115
+ // get and set should be in their final state by here
116
+ Object.defineProperty(obj, key, { ...props, get, set });
117
+ break;
118
+ case 'data':
119
+ Object.defineProperty(obj, key, { ...props, value });
120
+ break;
121
+ }
122
+ return obj;
123
+ },
124
+ addAccessor(to, key, getter, setter, storage) {
125
+ const store = storage ?? (!getter && !setter) ? true : undefined;
126
+ return this.add({ to, key, get: getter, set: setter, storage: store });
127
+ },
128
+ addData(to, key, value) {
129
+ return this.add({ to, key, value });
130
+ },
30
131
  /**
31
132
  * Creates a shallow copy of the provided object(s).
32
133
  *
@@ -53,7 +154,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
53
154
  * console.log(result); // Output: { a: 1, b: 3, c: 4 }
54
155
  */
55
156
  copy(destination, ...sources) {
56
- return copyObject(false, destination, ...sources);
157
+ return (0, copy_object_js_1.copyObject)(false, destination, ...sources);
57
158
  },
58
159
  /**
59
160
  * Creates a deep copy of the provided object(s).
@@ -80,7 +181,34 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
80
181
  * console.log(result); // Output: { a: 1, b: { d: 3 }, e: 4 }
81
182
  */
82
183
  deepCopy(destination, ...sources) {
83
- return copyObject(true, destination, ...sources);
184
+ return (0, copy_object_js_1.copyObject)(true, destination, ...sources);
185
+ },
186
+ /**
187
+ * Defines a new property on an object with a specified value and
188
+ * visibility/mutability flag. The flag determines the visibility and
189
+ * mutability of the property. By default, the property is defined as
190
+ * mutably hidden.
191
+ *
192
+ * @param {object} object - The object on which to define the property.
193
+ * @param {string} key - The name of the property to be defined.
194
+ * @param {any} value - The value of the property to be defined.
195
+ * @param {symbol} [flag=Object.definitionType.mutablyHidden] - The
196
+ * visibility/mutability flag for the property. This should be one of the
197
+ * symbols available in `ObjectExtensions.definitionType`.
198
+ * @returns {object} The object with the newly defined property.
199
+ *
200
+ * @example
201
+ * // Define a new mutably hidden property on an object
202
+ * const myObject = {};
203
+ * const myValue = 'Hello, world!';
204
+ * const hiddenSymbol = Object.definitionType.mutablyHidden;
205
+ * Object.define(myObject, 'myProperty', myValue, hiddenSymbol);
206
+ * // myObject now has a mutably hidden property 'myProperty' with value
207
+ * // 'Hello, world!'
208
+ */
209
+ define(object, key, value, flag = Object.definitionType.mutablyHidden) {
210
+ const properties = extension_1.Patch.getDescriptorOverridesFromSymbol(flag);
211
+ return Object.defineProperty(object, key, { ...properties, value });
84
212
  },
85
213
  /**
86
214
  * A getter property that provides access to the definition types used
@@ -113,33 +241,6 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
113
241
  get immutablyVisible() { return extension_1.Patch.kImmutablyVisible; },
114
242
  };
115
243
  },
116
- /**
117
- * Defines a new property on an object with a specified value and
118
- * visibility/mutability flag. The flag determines the visibility and
119
- * mutability of the property. By default, the property is defined as
120
- * mutably hidden.
121
- *
122
- * @param {object} object - The object on which to define the property.
123
- * @param {string} key - The name of the property to be defined.
124
- * @param {any} value - The value of the property to be defined.
125
- * @param {symbol} [flag=Object.definitionType.mutablyHidden] - The
126
- * visibility/mutability flag for the property. This should be one of the
127
- * symbols available in `ObjectExtensions.definitionType`.
128
- * @returns {object} The object with the newly defined property.
129
- *
130
- * @example
131
- * // Define a new mutably hidden property on an object
132
- * const myObject = {};
133
- * const myValue = 'Hello, world!';
134
- * const hiddenSymbol = Object.definitionType.mutablyHidden;
135
- * Object.define(myObject, 'myProperty', myValue, hiddenSymbol);
136
- * // myObject now has a mutably hidden property 'myProperty' with value
137
- * // 'Hello, world!'
138
- */
139
- define(object, key, value, flag = Object.definitionType.mutablyHidden) {
140
- const properties = extension_1.Patch.getDescriptorOverridesFromSymbol(flag);
141
- return Object.defineProperty(object, key, { ...properties, value });
142
- },
143
244
  /**
144
245
  * Defines a new accessor property on an object with specified getter and
145
246
  * setter functions and a visibility/mutability flag. The flag determines
@@ -173,112 +274,6 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
173
274
  const properties = extension_1.Patch.getDescriptorOverridesFromSymbol(flag);
174
275
  return Object.defineProperty(object, key, { ...properties, get, set });
175
276
  },
176
- addAccessor(to, key, getter, setter, storage) {
177
- const store = storage ?? (!getter && !setter) ? true : undefined;
178
- return this.add({ to, key, get: getter, set: setter, storage: store });
179
- },
180
- addData(to, key, value) {
181
- return this.add({ to, key, value });
182
- },
183
- add(...args) {
184
- const { isDescriptor } = descriptor_js_1.Descriptor;
185
- const { isObject: isObj } = this;
186
- const { kDescriptorStore } = this;
187
- let obj, key, value, _get, _set, storage, storageKey;
188
- let _type, _flag, _desc;
189
- // Check to see if we received multiple arguments or an object
190
- if (args.length && isObj(args[0])) {
191
- ({
192
- to: obj,
193
- key,
194
- value,
195
- get: _get,
196
- set: _set,
197
- storage,
198
- storageKey,
199
- type: _type = ['accessor', 'data'][1],
200
- flag: _flag = undefined,
201
- descriptorBase: _desc = undefined,
202
- } = args[0]);
203
- }
204
- else if (args.length > 1) {
205
- ([
206
- to,
207
- _type,
208
- key,
209
- getOrValue,
210
- _set,
211
- storage,
212
- storageKey,
213
- _flag,
214
- _desc,
215
- ] = args);
216
- obj = to;
217
- _type = (['accessor', 'data'].includes(_type.toLowerCase())
218
- ? _type.toLowerCase() : 'data');
219
- _get = _type === 'accessor' ? getOrValue : undefined;
220
- _value = _type === 'data' ? getOrValue : undefined;
221
- }
222
- if (!this.isObject(obj)) {
223
- console.warn('Object.add() must receive an object for `toObject`');
224
- return obj;
225
- }
226
- const more = isDescriptor(_desc) ? _desc : {};
227
- const flag = _flag || Object.definitionType.mutablyVisible;
228
- const props = { ...extension_1.Patch.getDescriptorOverridesFromSymbol(flag), ...more };
229
- const type = (['accessor', 'data'].includes(_type)
230
- ? String(_type).toLowerCase() : 'data');
231
- switch (type) {
232
- case 'accessor':
233
- let store = storage;
234
- let storeKey = storageKey || key;
235
- let makeStore = false;
236
- let get = _get;
237
- let set = _set;
238
- if (!isTruthy(get) && !isFn(get)) {
239
- get = undefined;
240
- }
241
- if (!isTruthy(set) && !isFn(set)) {
242
- set = undefined;
243
- }
244
- if (isObj(store) || isTrue(store) || isFn(store)) {
245
- makeStore = isTrue(store);
246
- store = isFn(store) ? store() : store;
247
- store = isObj(store) ? store : (makeStore && {} || undefined);
248
- }
249
- // store should be defined by here: object or undefined
250
- if ((!get && !set) && makeStore) {
251
- // being lazy here, someone has defined we make an accessor but
252
- // wants the default accessor behaviors with an associated store
253
- // made by us.
254
- Object.defineProperty(obj, kDescriptorStore, {
255
- value: symkeys.add('descriptor.store', store),
256
- configurable: true,
257
- enumerable: false,
258
- writable: true,
259
- });
260
- get = () => this[kDescriptorStore]?.data?.[storeKey];
261
- set = (value) => { this[kDescriptorStore].data[storeKey] = value; };
262
- }
263
- else if (get?.length && set?.length > 1 && store) {
264
- // if we received a get or set that takes more arguments than
265
- // expected, assume the last argument should be the store variable
266
- // so we execute the supplied function with the storage and its
267
- // results or byproducts are the result to the get/set we define
268
- const innerGet = get;
269
- const innerSet = set;
270
- get = () => innerGet(store);
271
- set = (value) => innerSet(value, store);
272
- }
273
- // get and set should be in their final state by here
274
- Object.defineProperty(obj, key, { ...props, get, set });
275
- break;
276
- case 'data':
277
- Object.defineProperty(obj, key, { ...props, value });
278
- break;
279
- }
280
- return obj;
281
- },
282
277
  /**
283
278
  * Creates a new object from an array of key-value pairs (entries), with an
284
279
  * optional prototype and reducer function. If no prototype is provided,
@@ -313,10 +308,10 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
313
308
  * // with prototype { foo: 'bar' }
314
309
  */
315
310
  fromEntriesUsing(entries, prototype = Object.prototype, reducer = undefined) {
316
- if (!Array.isArray(entries)) {
311
+ if (!toolkit_js_1.is.array(entries)) {
317
312
  return undefined;
318
313
  }
319
- const entriesToUse = entries.filter(entry => Array.isArray(entry) && entry.length >= 2);
314
+ const entriesToUse = entries.filter(entry => toolkit_js_1.is.array(entry) && entry.length >= 2);
320
315
  if (!entriesToUse.length) {
321
316
  return undefined;
322
317
  }
@@ -376,7 +371,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
376
371
  * @returns {string} - The string tag of the object, indicating its type.
377
372
  */
378
373
  getStringTag(value, strict = false) {
379
- if (Object.hasStringTag(value)) {
374
+ if (toolkit_js_1.has.stringTag(value)) {
380
375
  return value[Symbol.toStringTag];
381
376
  }
382
377
  if (strict) {
@@ -425,7 +420,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
425
420
  * @returns true if the symbol is defined, false otherwise
426
421
  */
427
422
  hasStringTag(value) {
428
- return Object.isObject(value) && Reflect.has(value, Symbol.toStringTag);
423
+ return toolkit_js_1.has.stringTag(value);
429
424
  },
430
425
  /**
431
426
  * The function checks if a value is either `undefined` or `null`.
@@ -436,7 +431,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
436
431
  * and `false` otherwise.
437
432
  */
438
433
  isNullDefined(value) {
439
- return value === undefined || value === null;
434
+ return toolkit_js_1.is.nullish(value);
440
435
  },
441
436
  /**
442
437
  * The `ifNullDefined` function checks if a given value is either `null` or
@@ -471,7 +466,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
471
466
  * );
472
467
  */
473
468
  ifNullDefined(value, thenValue, elseValue) {
474
- return isThenElse(this.isNullDefined(value), thenValue, elseValue);
469
+ return isThenElse(toolkit_js_1.is.nullish(value), thenValue, elseValue);
475
470
  },
476
471
  /**
477
472
  * Checks if the provided value is an object.
@@ -495,22 +490,31 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
495
490
  * console.log(isObject(null)); // Output: false
496
491
  */
497
492
  isObject(value) {
498
- return value instanceof Object || value && typeof value === 'object';
493
+ return toolkit_js_1.is.object(value);
499
494
  },
500
495
  /**
501
- * Determines if the provided value is an object. This method checks whether
502
- * the value is an instance of `Object` or if its type is 'object'. It's a
503
- * utility method for type-checking, ensuring that a value is an object
504
- * before performing operations that are specific to objects.
496
+ * Executes a conditional function based on whether the provided value
497
+ * is an object or not. This method first checks if the value is an
498
+ * object using the `is.object` method from the toolkit. If it is, it
499
+ * returns the `thenValue`, otherwise it returns the `elseValue`.
505
500
  *
506
- * @param {*} value - The value to be checked.
507
- * @returns {boolean} - Returns `true` if the value is an object,
508
- * otherwise `false`.
509
- },
510
- isObject(value) {
511
- return value && (value instanceof Object || typeof value === 'object');
501
+ * @param {any} value - The value to be checked.
502
+ * @param {function | any} thenValue - The value to return if `value`
503
+ * is an object.
504
+ * @param {function | any} elseValue - The value to return if `value`
505
+ * is not an object.
506
+ * @returns {*} - Returns `thenValue` if the value is an object,
507
+ * otherwise `elseValue`.
508
+ *
509
+ * @example
510
+ * // returns 'Is Object'
511
+ * ifObject({}, 'Is Object', 'Not Object')
512
+ * // returns 'Not Object'
513
+ * ifObject(42, 'Is Object', 'Not Object')
514
+ */
515
+ ifObject(value, thenValue, elseValue) {
516
+ return isThenElse(toolkit_js_1.is.object(value), thenValue, elseValue);
512
517
  },
513
-
514
518
  /**
515
519
  * Checks to see if the supplied value is a primitive value.
516
520
  *
@@ -519,23 +523,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
519
523
  * false otherwise.
520
524
  */
521
525
  isPrimitive(value) {
522
- // Check for null as a special case because typeof null
523
- // is 'object'
524
- if (value === null) {
525
- return true;
526
- }
527
- // Check for other primitives
528
- switch (typeof value) {
529
- case 'string':
530
- case 'number':
531
- case 'bigint':
532
- case 'boolean':
533
- case 'undefined':
534
- case 'symbol':
535
- return true;
536
- default:
537
- return false;
538
- }
526
+ return toolkit_js_1.is.primitive(value);
539
527
  },
540
528
  /**
541
529
  * Executes a conditional function based on whether the provided value is
@@ -558,7 +546,7 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
558
546
  * ifPrimitive({a: 'hello'}, 1, 2)
559
547
  */
560
548
  ifPrimitive(value, thenValue, elseValue) {
561
- return isThenElse(this.isPrimitive(value), thenValue, elseValue);
549
+ return isThenElse(toolkit_js_1.is.primitive(value), thenValue, elseValue);
562
550
  },
563
551
  /**
564
552
  * Checks if the given value is a valid key for an object. In JavaScript, a
@@ -730,6 +718,54 @@ exports.ObjectExtensions = new extension_1.Patch(Object, {
730
718
  }
731
719
  return result;
732
720
  },
721
+ withProperties(prototype, ...properties) {
722
+ const props = properties.filter(p => p instanceof property_js_1.Property);
723
+ const possible = properties.filter(p => Array.isArray(p));
724
+ if (possible.length) {
725
+ for (const [key, descriptorOrDataOrAccessorArgs, ...rest] of possible) {
726
+ // if arg[1] is a descriptor
727
+ if (property_js_1.Property.is.descriptor(descriptorOrDataOrAccessorArgs)) {
728
+ props.push(new property_js_1.Property(key, descriptorOrDataOrAccessorArgs));
729
+ }
730
+ else {
731
+ const { get, set } = descriptorOrDataOrAccessorArgs;
732
+ const args = [key, descriptorOrDataOrAccessorArgs, ...rest];
733
+ if (get || set) {
734
+ props.push(property_js_1.Property.accessor(...args));
735
+ }
736
+ else {
737
+ props.push(property_js_1.Property.data(...args));
738
+ }
739
+ }
740
+ }
741
+ }
742
+ const object = Object.create(prototype ?? Object.prototype);
743
+ const sorted = props.toSorted((a, b) => a.key < b.key ? -1 : (a.key > b.key ? 1 : 0));
744
+ for (const property of sorted) {
745
+ property.apply(object);
746
+ }
747
+ property_js_1.Property.data(Symbol.for('properties'), sorted).apply(object);
748
+ return object;
749
+ },
750
+ /**
751
+ * Retrieves a toolkit object containing various utility functions
752
+ * for type checking and introspection.
753
+ *
754
+ * The toolkit includes many functions. It was designed to read as
755
+ * though the toolkit were assigned to the variable `it`.
756
+ *
757
+ * @example
758
+ * const is = ObjectExtensions.patches.toolkit
759
+ * console.log(is.object({})) // Output: true
760
+ * console.log(is.string('hello')) // Output: true
761
+ * console.log(is.number(42)) // Output: true
762
+ *
763
+ * @returns {object} The toolkit object containing various utility
764
+ * functions for type checking and introspection.
765
+ */
766
+ get toolkit() {
767
+ return { as: toolkit_js_1.as, has: toolkit_js_1.has, is: toolkit_js_1.is, si: toolkit_js_1.si };
768
+ },
733
769
  },
734
770
  });
735
771
  const { isObject: pIsObject, ifObject: pIfObject, isNullDefined: pIsNullDefined, ifNullDefined: pIfNullDefined, isPrimitive: pIsPrimitive, ifPrimitive: pIfPrimitive, isValidKey: pIsValidKey, ifValidKey: pIfValidKey, hasStringTag: pHasStringTag, getStringTag: pGetStringTag, stripTo: pStripTo, } = exports.ObjectExtensions.patches;
@@ -1043,86 +1079,13 @@ exports.ObjectPrototypeExtensions = new extension_1.Patch(Object.prototype, {
1043
1079
  // {@see globalThis.isThenElse}
1044
1080
  function isThenElse(bv, tv, ev) {
1045
1081
  if (arguments.length > 1) {
1046
- var _then = isFunction(tv) ? tv(bv) : tv;
1082
+ var _then = toolkit_js_1.is.function(tv) ? tv(bv) : tv;
1047
1083
  if (arguments.length > 2) {
1048
- var _else = isFunction(ev) ? tv(bv) : ev;
1084
+ var _else = toolkit_js_1.is.function(ev) ? tv(bv) : ev;
1049
1085
  return bv ? _then : _else;
1050
1086
  }
1051
1087
  return bv || _then;
1052
1088
  }
1053
1089
  return bv;
1054
1090
  }
1055
- /**
1056
- * Creates a deep or shallow copy of the provided source objects and merges
1057
- * them into the destination object. The function uses a Set to keep track
1058
- * of visited objects to avoid circular references.
1059
- *
1060
- * @function
1061
- * @name copyObject
1062
- * @param {boolean} deep - If true, performs a deep copy, otherwise performs
1063
- * a shallow copy.
1064
- * @param {object} destination - The object to which properties will be copied.
1065
- * @param {...object} sources - The source object(s) from which properties
1066
- * will be copied.
1067
- * @returns {object} The destination object with the copied properties.
1068
- *
1069
- * @example
1070
- * // Shallow copy
1071
- * const obj1 = { a: 1, b: { c: 2 } };
1072
- * const obj2 = { b: { d: 3 }, e: 4 };
1073
- * const result = copyObject(false, obj1, obj2);
1074
- * console.log(result); // Output: { a: 1, b: { d: 3 }, e: 4 }
1075
- *
1076
- * @example
1077
- * // Deep copy
1078
- * const obj1 = { a: 1, b: { c: 2 } };
1079
- * const obj2 = { b: { d: 3 }, e: 4 };
1080
- * const result = copyObject(true, obj1, obj2);
1081
- * console.log(result); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }
1082
- */
1083
- function copyObject(deep, destination, ...sources) {
1084
- const visited = new Set();
1085
- for (const source of sources) {
1086
- if (source === null || typeof source !== 'object' || visited.has(source)) {
1087
- continue;
1088
- }
1089
- visited.add(source);
1090
- const keys = Reflect.ownKeys(source);
1091
- for (const key of keys) {
1092
- let descriptor;
1093
- try {
1094
- descriptor = Object.getOwnPropertyDescriptor(source, key);
1095
- }
1096
- catch (err) {
1097
- console.warn(`Failed to get descriptor for key "${key}": ${err}`);
1098
- continue;
1099
- }
1100
- const isDataDesc = Reflect.has(descriptor, 'value');
1101
- const keyedValue = descriptor?.value;
1102
- const conditionsMet = [
1103
- isDataDesc,
1104
- keyedValue,
1105
- typeof keyedValue === 'object',
1106
- !visited.has(keyedValue)
1107
- ].every(condition => condition);
1108
- if (conditionsMet) {
1109
- visited.add(keyedValue);
1110
- const prototype = Object.getPrototypeOf(keyedValue);
1111
- const descriptors = Object.getOwnPropertyDescriptors(keyedValue);
1112
- const replacement = Object.create(prototype, descriptors);
1113
- descriptor.value = deep
1114
- ? copyObject(deep, replacement, keyedValue)
1115
- : replacement;
1116
- }
1117
- try {
1118
- Object.defineProperty(destination, key, descriptor);
1119
- }
1120
- catch (err) {
1121
- console.error(`Failed to define property "${key}": ${err}`);
1122
- }
1123
- }
1124
- }
1125
- return destination;
1126
- }
1127
- exports.copyObject = copyObject;
1128
1091
  //# sourceMappingURL=object.extensions.js.map