tods-competition-factory 1.7.7 → 1.7.9

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.
@@ -3,8 +3,9 @@ declare function nearestPowerOf2(val: any): number;
3
3
  declare function isOdd(num: any): boolean | undefined;
4
4
  declare function nextPowerOf2(n?: any): any;
5
5
 
6
+ declare function createMap(objectArray: any, attribute: any): any;
6
7
  declare const hasAttributeValues: (a: any) => (o: any) => boolean;
7
- declare const extractAttributes: (atz: any) => (o: any) => any;
8
+ declare const extractAttributes: (accessor: any) => (element: any) => any;
8
9
  declare function definedAttributes(obj: object, ignoreFalse?: boolean, ignoreEmptyArrays?: boolean, shallow?: boolean): any;
9
10
  declare function undefinedToNull(obj: object, shallow?: boolean): any;
10
11
  declare function generateHashCode(o: any): string | undefined;
@@ -104,4 +105,4 @@ declare function noNumeric(arr: any): any;
104
105
  */
105
106
  declare function chunkByNth(arr: any[], chunksCount: number, shuttle?: boolean): any;
106
107
 
107
- export { JSON2CSV, UUID, allNumeric, attributeFilter, chunkArray, chunkByNth, chunkSizeProfile, countValues, definedAttributes, extractAttributes, generateHashCode, generateRange, generateTimeCode, groupValues, hasAttributeValues, instanceCount, intersection, isOdd, isPowerOf2, makeDeepCopy, nearestPowerOf2, nextPowerOf2, noNulls, noNumeric, numericSort, occurrences, overlap, randomMember, randomPop, shuffleArray, subSort, undefinedToNull, unique };
108
+ export { JSON2CSV, UUID, allNumeric, attributeFilter, chunkArray, chunkByNth, chunkSizeProfile, countValues, createMap, definedAttributes, extractAttributes, generateHashCode, generateRange, generateTimeCode, groupValues, hasAttributeValues, instanceCount, intersection, isOdd, isPowerOf2, makeDeepCopy, nearestPowerOf2, nextPowerOf2, noNulls, noNumeric, numericSort, occurrences, overlap, randomMember, randomPop, shuffleArray, subSort, undefinedToNull, unique };
@@ -164,17 +164,149 @@ function deepCopyEnabled() {
164
164
  };
165
165
  }
166
166
 
167
- const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
168
- const extractAttributes = (atz) => (o) => !atz || typeof o !== "object" ? void 0 : Array.isArray(atz) && atz.map((a) => ({ [a]: o[a] })) || typeof atz === "object" && Object.keys(atz).map((key) => ({ [key]: o[key] })) || typeof atz === "string" && getAttr(o, atz);
169
- function getAttr(o, attr) {
170
- const attrs = attr.split(".");
171
- for (const a of attrs) {
172
- o = o?.[a];
173
- if (!o)
174
- return;
167
+ function isDateObject(value) {
168
+ if (typeof value !== "object" || Array.isArray(value)) {
169
+ return false;
170
+ } else {
171
+ const datePrototype = Object.prototype.toString.call(value);
172
+ return datePrototype === "[object Date]";
173
+ }
174
+ }
175
+
176
+ function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
177
+ const deepCopy = deepCopyEnabled();
178
+ const { stringify, toJSON, ignore, modulate } = deepCopy || {};
179
+ if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
180
+ return sourceObject;
181
+ }
182
+ const devContext = getDevContext({ makeDeepCopy: true });
183
+ if (devContext) {
184
+ setDeepCopyIterations(iteration);
185
+ if (typeof devContext === "object" && (iteration > (devContext.iterationThreshold || 15) || devContext.firstIteration && iteration === 0) && devContext.log && (!devContext.notInternalUse || devContext.notInternalUse && !internalUse)) {
186
+ console.log({ devContext, iteration, internalUse }, sourceObject);
187
+ }
188
+ }
189
+ const targetObject = Array.isArray(sourceObject) ? [] : {};
190
+ const sourceObjectKeys = Object.keys(sourceObject).filter(
191
+ (key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
192
+ );
193
+ const stringifyValue = (key, value) => {
194
+ targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
195
+ };
196
+ for (const key of sourceObjectKeys) {
197
+ const value = sourceObject[key];
198
+ const modulated = typeof modulate === "function" ? modulate(value) : void 0;
199
+ if (modulated !== void 0) {
200
+ targetObject[key] = modulated;
201
+ } else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
202
+ const extensionConversions = extensionsToAttributes(value);
203
+ Object.assign(targetObject, ...extensionConversions);
204
+ } else if (removeExtensions && key === "extensions") {
205
+ targetObject[key] = [];
206
+ } else if (Array.isArray(stringify) && stringify.includes(key)) {
207
+ stringifyValue(key, value);
208
+ } else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
209
+ targetObject[key] = value.toJSON();
210
+ } else if (value === null) {
211
+ targetObject[key] = void 0;
212
+ } else if (isDateObject(value)) {
213
+ targetObject[key] = new Date(value).toISOString();
214
+ } else {
215
+ targetObject[key] = makeDeepCopy(
216
+ value,
217
+ convertExtensions,
218
+ internalUse,
219
+ removeExtensions,
220
+ iteration + 1
221
+ );
222
+ }
175
223
  }
176
- return o;
224
+ return targetObject;
225
+ }
226
+ function extensionsToAttributes(extensions) {
227
+ return extensions?.map((extension) => {
228
+ const { name, value } = extension;
229
+ return name && value && { [`_${name}`]: value };
230
+ }).filter(Boolean);
177
231
  }
232
+
233
+ function getAccessorValue({ element, accessor }) {
234
+ if (typeof accessor !== "string")
235
+ return { values: [] };
236
+ const targetElement = makeDeepCopy(element);
237
+ const attributes = accessor.split(".");
238
+ const values = [];
239
+ let value;
240
+ processKeys({ targetElement, attributes });
241
+ const result = { value };
242
+ if (values.length)
243
+ result.values = values;
244
+ return result;
245
+ function processKeys({
246
+ targetElement: targetElement2,
247
+ attributes: attributes2 = [],
248
+ significantCharacters
249
+ }) {
250
+ for (const [index, attribute] of attributes2.entries()) {
251
+ if (targetElement2?.[attribute]) {
252
+ const remainingKeys = attributes2.slice(index + 1);
253
+ if (!remainingKeys.length) {
254
+ if (!value)
255
+ value = targetElement2[attribute];
256
+ if (!values.includes(targetElement2[attribute])) {
257
+ values.push(targetElement2[attribute]);
258
+ }
259
+ } else if (Array.isArray(targetElement2[attribute])) {
260
+ const values2 = targetElement2[attribute];
261
+ values2.forEach(
262
+ (nestedTarget) => processKeys({
263
+ targetElement: nestedTarget,
264
+ attributes: remainingKeys
265
+ })
266
+ );
267
+ } else {
268
+ targetElement2 = targetElement2[attribute];
269
+ checkValue({ targetElement: targetElement2, index });
270
+ }
271
+ }
272
+ }
273
+ function checkValue({ targetElement: targetElement3, index }) {
274
+ if (targetElement3 && index === attributes2.length - 1 && ["string", "number"].includes(typeof targetElement3)) {
275
+ const extractedValue = significantCharacters ? targetElement3.slice(0, significantCharacters) : targetElement3;
276
+ if (value) {
277
+ if (!values.includes(extractedValue)) {
278
+ values.push(extractedValue);
279
+ }
280
+ } else {
281
+ value = extractedValue;
282
+ values.push(extractedValue);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ function isObject(obj) {
290
+ return typeof obj === "object";
291
+ }
292
+ function createMap(objectArray, attribute) {
293
+ if (!Array.isArray(objectArray))
294
+ return {};
295
+ return Object.assign(
296
+ {},
297
+ ...(objectArray ?? []).filter(isObject).map((obj) => {
298
+ return obj[attribute] && {
299
+ [obj[attribute]]: obj
300
+ };
301
+ }).filter(Boolean)
302
+ );
303
+ }
304
+ const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
305
+ const extractAttributes = (accessor) => (element) => !accessor || typeof element !== "object" ? void 0 : Array.isArray(accessor) && accessor.map((a) => ({
306
+ [a]: getAccessorValue({ element, accessor: a })?.value
307
+ })) || typeof accessor === "object" && Object.keys(accessor).map((key) => ({
308
+ [key]: getAccessorValue({ element, accessor: key })?.value
309
+ })) || (typeof accessor === "string" && getAccessorValue({ element, accessor }))?.value;
178
310
  function definedAttributes(obj, ignoreFalse, ignoreEmptyArrays, shallow) {
179
311
  if (typeof obj !== "object" || obj === null)
180
312
  return obj;
@@ -287,72 +419,6 @@ function generateTimeCode(index = 0) {
287
419
  return uidate.getTime().toString(36).slice(-6).toUpperCase();
288
420
  }
289
421
 
290
- function isDateObject(value) {
291
- if (typeof value !== "object" || Array.isArray(value)) {
292
- return false;
293
- } else {
294
- const datePrototype = Object.prototype.toString.call(value);
295
- return datePrototype === "[object Date]";
296
- }
297
- }
298
-
299
- function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
300
- const deepCopy = deepCopyEnabled();
301
- const { stringify, toJSON, ignore, modulate } = deepCopy || {};
302
- if (!deepCopy?.enabled && !internalUse || typeof sourceObject !== "object" || typeof sourceObject === "function" || sourceObject === null || typeof deepCopy?.threshold === "number" && iteration >= deepCopy.threshold) {
303
- return sourceObject;
304
- }
305
- const devContext = getDevContext({ makeDeepCopy: true });
306
- if (devContext) {
307
- setDeepCopyIterations(iteration);
308
- if (typeof devContext === "object" && (iteration > (devContext.iterationThreshold || 15) || devContext.firstIteration && iteration === 0) && devContext.log && (!devContext.notInternalUse || devContext.notInternalUse && !internalUse)) {
309
- console.log({ devContext, iteration, internalUse }, sourceObject);
310
- }
311
- }
312
- const targetObject = Array.isArray(sourceObject) ? [] : {};
313
- const sourceObjectKeys = Object.keys(sourceObject).filter(
314
- (key) => !internalUse || !ignore || Array.isArray(ignore) && !ignore.includes(key) || typeof ignore === "function" && !ignore(key)
315
- );
316
- const stringifyValue = (key, value) => {
317
- targetObject[key] = typeof value?.toString === "function" ? value.toString() : JSON.stringify(value);
318
- };
319
- for (const key of sourceObjectKeys) {
320
- const value = sourceObject[key];
321
- const modulated = typeof modulate === "function" ? modulate(value) : void 0;
322
- if (modulated !== void 0) {
323
- targetObject[key] = modulated;
324
- } else if (convertExtensions && key === "extensions" && Array.isArray(value)) {
325
- const extensionConversions = extensionsToAttributes(value);
326
- Object.assign(targetObject, ...extensionConversions);
327
- } else if (removeExtensions && key === "extensions") {
328
- targetObject[key] = [];
329
- } else if (Array.isArray(stringify) && stringify.includes(key)) {
330
- stringifyValue(key, value);
331
- } else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === "function") {
332
- targetObject[key] = value.toJSON();
333
- } else if (value === null) {
334
- targetObject[key] = void 0;
335
- } else if (isDateObject(value)) {
336
- targetObject[key] = new Date(value).toISOString();
337
- } else {
338
- targetObject[key] = makeDeepCopy(
339
- value,
340
- convertExtensions,
341
- internalUse,
342
- removeExtensions,
343
- iteration + 1
344
- );
345
- }
346
- }
347
- return targetObject;
348
- }
349
- function extensionsToAttributes(extensions) {
350
- return extensions?.map((extension) => {
351
- const { name, value } = extension;
352
- return name && value && { [`_${name}`]: value };
353
- }).filter(Boolean);
354
- }
355
-
356
422
  function numericSort(a, b) {
357
423
  return a - b;
358
424
  }
@@ -493,5 +559,5 @@ function UUID() {
493
559
  lut[d3 & 255] + lut[d3 >> 8 & 255] + lut[d3 >> 16 & 255] + lut[d3 >> 24 & 255];
494
560
  }
495
561
 
496
- export { JSON2CSV, UUID, allNumeric, attributeFilter, chunkArray, chunkByNth, chunkSizeProfile, countValues, definedAttributes, extractAttributes, generateHashCode, generateRange, generateTimeCode, groupValues, hasAttributeValues, instanceCount, intersection, isOdd, isPowerOf2, makeDeepCopy, nearestPowerOf2, nextPowerOf2, noNulls, noNumeric, numericSort, occurrences, overlap, randomMember, randomPop, shuffleArray, subSort, undefinedToNull, unique };
562
+ export { JSON2CSV, UUID, allNumeric, attributeFilter, chunkArray, chunkByNth, chunkSizeProfile, countValues, createMap, definedAttributes, extractAttributes, generateHashCode, generateRange, generateTimeCode, groupValues, hasAttributeValues, instanceCount, intersection, isOdd, isPowerOf2, makeDeepCopy, nearestPowerOf2, nextPowerOf2, noNulls, noNumeric, numericSort, occurrences, overlap, randomMember, randomPop, shuffleArray, subSort, undefinedToNull, unique };
497
563
  //# sourceMappingURL=utilities.mjs.map