• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 16053471080

03 Jul 2025 02:41PM UTC coverage: 4.981% (-86.4%) from 91.409%
16053471080

Pull #16021

github

web-flow
Merge 7c49966eb into 7e40671a1
Pull Request #16021: fix(radio-group): dynamically added radio buttons do not initialize

178 of 15753 branches covered (1.13%)

13 of 14 new or added lines in 2 files covered. (92.86%)

25644 existing lines in 324 files now uncovered.

1478 of 29670 relevant lines covered (4.98%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.92
/projects/igniteui-angular/src/lib/core/utils.ts
1
import { CurrencyPipe, formatDate as _formatDate, isPlatformBrowser } from '@angular/common';
2
import { Inject, Injectable, InjectionToken, PLATFORM_ID, inject } from '@angular/core';
3
import { mergeWith } from 'lodash-es';
4
import { NEVER, Observable } from 'rxjs';
5
import { setImmediate } from './setImmediate';
6
import { isDevMode } from '@angular/core';
7
import type { IgxTheme } from '../services/theme/theme.token';
8

9
/** @hidden @internal */
10
export const ELEMENTS_TOKEN = /*@__PURE__*/new InjectionToken<boolean>('elements environment');
3✔
11

12
/**
13
 * @hidden
14
 */
15
export const showMessage = (message: string, isMessageShown: boolean): boolean => {
3✔
16
    if (!isMessageShown && isDevMode()) {
×
17
        console.warn(message);
×
18
    }
19

20
    return true;
×
21
};
22

23
/**
24
 *
25
 * @hidden @internal
26
 */
27
export const getResizeObserver = () => globalThis.window?.ResizeObserver;
3✔
28

29
/**
30
 * @hidden
31
 */
32
export function cloneArray<T>(array: T[], deep = false): T[] {
×
UNCOV
33
    return deep ? (array ?? []).map(cloneValue) : (array ?? []).slice();
×
34
}
35

36
/**
37
 * Doesn't clone leaf items
38
 *
39
 * @hidden
40
 */
41
export const cloneHierarchicalArray = (array: any[], childDataKey: any): any[] => {
3✔
UNCOV
42
    const result: any[] = [];
×
UNCOV
43
    if (!array) {
×
44
        return result;
×
45
    }
46

UNCOV
47
    for (const item of array) {
×
UNCOV
48
        const clonedItem = cloneValue(item);
×
UNCOV
49
        if (Array.isArray(item[childDataKey])) {
×
UNCOV
50
            clonedItem[childDataKey] = cloneHierarchicalArray(clonedItem[childDataKey], childDataKey);
×
51
        }
UNCOV
52
        result.push(clonedItem);
×
53
    }
UNCOV
54
    return result;
×
55
};
56

57
/**
58
 * Creates an object with prototype from provided source and copies
59
 * all properties descriptors from provided source
60
 * @param obj Source to copy prototype and descriptors from
61
 * @returns New object with cloned prototype and property descriptors
62
 */
63
export const copyDescriptors = (obj) => {
3✔
UNCOV
64
    if (obj) {
×
UNCOV
65
        return Object.create(
×
66
            Object.getPrototypeOf(obj),
67
            Object.getOwnPropertyDescriptors(obj)
68
        );
69
    }
70
}
71

72

73
/**
74
 * Deep clones all first level keys of Obj2 and merges them to Obj1
75
 *
76
 * @param obj1 Object to merge into
77
 * @param obj2 Object to merge from
78
 * @returns Obj1 with merged cloned keys from Obj2
79
 * @hidden
80
 */
81
export const mergeObjects = (obj1: any, obj2: any): any => mergeWith(obj1, obj2, (objValue, srcValue) => {
3✔
UNCOV
82
    if (Array.isArray(srcValue)) {
×
UNCOV
83
        return objValue = srcValue;
×
84
    }
85
});
86

87
/**
88
 * Creates deep clone of provided value.
89
 * Supports primitive values, dates and objects.
90
 * If passed value is array returns shallow copy of the array.
91
 *
92
 * @param value value to clone
93
 * @returns Deep copy of provided value
94
 * @hidden
95
 */
96
export const cloneValue = (value: any): any => {
3✔
UNCOV
97
    if (isDate(value)) {
×
UNCOV
98
        return new Date(value.getTime());
×
99
    }
UNCOV
100
    if (Array.isArray(value)) {
×
UNCOV
101
        return value.slice();
×
102
    }
103

UNCOV
104
    if (value instanceof Map || value instanceof Set) {
×
UNCOV
105
        return value;
×
106
    }
107

UNCOV
108
    if (isObject(value)) {
×
UNCOV
109
        const result = {};
×
110

UNCOV
111
        for (const key of Object.keys(value)) {
×
UNCOV
112
            if (key === "externalObject") {
×
113
                continue;
×
114
            }
UNCOV
115
            result[key] = cloneValue(value[key]);
×
116
        }
UNCOV
117
        return result;
×
118
    }
UNCOV
119
    return value;
×
120
};
121

122
/**
123
 * Creates deep clone of provided value.
124
 * Supports primitive values, dates and objects.
125
 * If passed value is array returns shallow copy of the array.
126
 * For Objects property values and references are cached and reused.
127
 * This allows for circular references to same objects.
128
 *
129
 * @param value value to clone
130
 * @param cache map of cached values already parsed
131
 * @returns Deep copy of provided value
132
 * @hidden
133
 */
134
export const cloneValueCached = (value: any, cache: Map<any, any>): any => {
3✔
135
    if (isDate(value)) {
×
136
        return new Date(value.getTime());
×
137
    }
138
    if (Array.isArray(value)) {
×
139
        return [...value];
×
140
    }
141

142
    if (value instanceof Map || value instanceof Set) {
×
143
        return value;
×
144
    }
145

146
    if (isObject(value)) {
×
147
        if (cache.has(value)) {
×
148
            return cache.get(value);
×
149
        }
150

151
        const result = {};
×
152
        cache.set(value, result);
×
153

154
        for (const key of Object.keys(value)) {
×
155
            result[key] = cloneValueCached(value[key], cache);
×
156
        }
157
        return result;
×
158
    }
159
    return value;
×
160
};
161

162
/**
163
 * Parse provided input to Date.
164
 *
165
 * @param value input to parse
166
 * @returns Date if parse succeed or null
167
 * @hidden
168
 */
169
export const parseDate = (value: any): Date | null => {
3✔
170
    // if value is Invalid Date return null
UNCOV
171
    if (isDate(value)) {
×
UNCOV
172
        return !isNaN(value.getTime()) ? value : null;
×
173
    }
UNCOV
174
    return value ? new Date(value) : null;
×
175
};
176

177
/**
178
 * Returns an array with unique dates only.
179
 *
180
 * @param columnValues collection of date values (might be numbers or ISO 8601 strings)
181
 * @returns collection of unique dates.
182
 * @hidden
183
 */
184
export const uniqueDates = (columnValues: any[]) => columnValues.reduce((a, c) => {
3✔
185
    if (!a.cache[c.label]) {
×
186
        a.result.push(c);
×
187
    }
188
    a.cache[c.label] = true;
×
189
    return a;
×
190
}, { result: [], cache: {} }).result;
191

192
/**
193
 * Checks if provided variable is Object
194
 *
195
 * @param value Value to check
196
 * @returns true if provided variable is Object
197
 * @hidden
198
 */
199
export const isObject = (value: any): boolean => !!(value && value.toString() === '[object Object]');
3!
200

201
/**
202
 * Checks if provided variable is Date
203
 *
204
 * @param value Value to check
205
 * @returns true if provided variable is Date
206
 * @hidden
207
 */
208
export const isDate = (value: any): value is Date => {
3✔
UNCOV
209
    return Object.prototype.toString.call(value) === "[object Date]";
×
210
}
211

212
/**
213
 * Checks if the two passed arguments are equal
214
 * Currently supports date objects
215
 *
216
 * @param obj1
217
 * @param obj2
218
 * @returns: `boolean`
219
 * @hidden
220
 */
221
export const isEqual = (obj1, obj2): boolean => {
3✔
UNCOV
222
    if (isDate(obj1) && isDate(obj2)) {
×
UNCOV
223
        return obj1.getTime() === obj2.getTime();
×
224
    }
UNCOV
225
    return obj1 === obj2;
×
226
};
227

228
/**
229
 * Utility service taking care of various utility functions such as
230
 * detecting browser features, general cross browser DOM manipulation, etc.
231
 *
232
 * @hidden @internal
233
 */
234
@Injectable({ providedIn: 'root' })
235
export class PlatformUtil {
3✔
UNCOV
236
    public isBrowser: boolean = isPlatformBrowser(this.platformId);
×
UNCOV
237
    public isIOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !('MSStream' in window);
×
UNCOV
238
    public isSafari = this.isBrowser && /Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent);
×
UNCOV
239
    public isFirefox = this.isBrowser && /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);
×
UNCOV
240
    public isEdge = this.isBrowser && /Edge[\/\s](\d+\.\d+)/.test(navigator.userAgent);
×
UNCOV
241
    public isChromium = this.isBrowser && (/Chrom|e?ium/g.test(navigator.userAgent) ||
×
242
        /Google Inc/g.test(navigator.vendor)) && !/Edge/g.test(navigator.userAgent);
UNCOV
243
    public browserVersion = this.isBrowser ? parseFloat(navigator.userAgent.match(/Version\/([\d.]+)/)?.at(1)) : 0;
×
244

245
    /** @hidden @internal */
UNCOV
246
    public isElements = inject(ELEMENTS_TOKEN, { optional: true });
×
247

UNCOV
248
    public KEYMAP = {
×
249
        ENTER: 'Enter',
250
        SPACE: ' ',
251
        ESCAPE: 'Escape',
252
        ARROW_DOWN: 'ArrowDown',
253
        ARROW_UP: 'ArrowUp',
254
        ARROW_LEFT: 'ArrowLeft',
255
        ARROW_RIGHT: 'ArrowRight',
256
        END: 'End',
257
        HOME: 'Home',
258
        PAGE_DOWN: 'PageDown',
259
        PAGE_UP: 'PageUp',
260
        F2: 'F2',
261
        TAB: 'Tab',
262
        SEMICOLON: ';',
263
        // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values#editing_keys
264
        DELETE: 'Delete',
265
        BACKSPACE: 'Backspace',
266
        CONTROL: 'Control',
267
        X: 'x',
268
        Y: 'y',
269
        Z: 'z'
270
    } as const;
271

UNCOV
272
    constructor(@Inject(PLATFORM_ID) private platformId: any) { }
×
273

274
    /**
275
     * @hidden @internal
276
     * Returns the actual size of the node content, using Range
277
     * ```typescript
278
     * let range = document.createRange();
279
     * let column = this.grid.columnList.filter(c => c.field === 'ID')[0];
280
     *
281
     * let size = getNodeSizeViaRange(range, column.cells[0].nativeElement);
282
     *
283
     * @remarks
284
     * The last parameter is useful when the size of the element to measure is modified by a
285
     * parent element that has explicit size. In such cases the calculated size is never lower
286
     * and the function may instead remove the parent size while measuring to get the correct value.
287
     * ```
288
     */
289
    public getNodeSizeViaRange(range: Range, node: HTMLElement, sizeHoldingNode?: HTMLElement) {
UNCOV
290
        let overflow = null;
×
291
        let nodeStyles: string[];
292

UNCOV
293
        if (!this.isFirefox) {
×
UNCOV
294
            overflow = node.style.overflow;
×
295
            // we need that hack - otherwise content won't be measured correctly in IE/Edge
UNCOV
296
            node.style.overflow = 'visible';
×
297
        }
298

UNCOV
299
        if (sizeHoldingNode) {
×
UNCOV
300
            const style = sizeHoldingNode.style;
×
UNCOV
301
            nodeStyles = [style.width, style.minWidth, style.flexBasis];
×
UNCOV
302
            style.width = '';
×
UNCOV
303
            style.minWidth = '';
×
UNCOV
304
            style.flexBasis = '';
×
305
        }
306

UNCOV
307
        range.selectNodeContents(node);
×
UNCOV
308
        const scale = node.getBoundingClientRect().width / node.offsetWidth;
×
UNCOV
309
        const width = range.getBoundingClientRect().width / scale;
×
310

UNCOV
311
        if (!this.isFirefox) {
×
312
            // we need that hack - otherwise content won't be measured correctly in IE/Edge
UNCOV
313
            node.style.overflow = overflow;
×
314
        }
315

UNCOV
316
        if (sizeHoldingNode) {
×
UNCOV
317
            sizeHoldingNode.style.width = nodeStyles[0];
×
UNCOV
318
            sizeHoldingNode.style.minWidth = nodeStyles[1];
×
UNCOV
319
            sizeHoldingNode.style.flexBasis = nodeStyles[2];
×
320
        }
321

UNCOV
322
        return width;
×
323
    }
324

325

326
    /**
327
     * Returns true if the current keyboard event is an activation key (Enter/Space bar)
328
     *
329
     * @hidden
330
     * @internal
331
     *
332
     * @memberof PlatformUtil
333
     */
334
    public isActivationKey(event: KeyboardEvent) {
UNCOV
335
        return event.key === this.KEYMAP.ENTER || event.key === this.KEYMAP.SPACE;
×
336
    }
337

338
    /**
339
     * Returns true if the current keyboard event is a combination that closes the filtering UI of the grid. (Escape/Ctrl+Shift+L)
340
     *
341
     * @hidden
342
     * @internal
343
     * @param event
344
     * @memberof PlatformUtil
345
     */
346
    public isFilteringKeyCombo(event: KeyboardEvent) {
UNCOV
347
        return event.key === this.KEYMAP.ESCAPE || (event.ctrlKey && event.shiftKey && event.key.toLowerCase() === 'l');
×
348
    }
349

350
    /**
351
     * @hidden @internal
352
     */
353
    public isLeftClick(event: PointerEvent | MouseEvent) {
UNCOV
354
        return event.button === 0;
×
355
    }
356

357
    /**
358
     * @hidden @internal
359
     */
360
    public isNavigationKey(key: string) {
UNCOV
361
        return [
×
362
            this.KEYMAP.HOME, this.KEYMAP.END, this.KEYMAP.SPACE,
363
            this.KEYMAP.ARROW_DOWN, this.KEYMAP.ARROW_LEFT, this.KEYMAP.ARROW_RIGHT, this.KEYMAP.ARROW_UP
364
        ].includes(key as any);
365
    }
366
}
367

368
/**
369
 * @hidden
370
 */
371
export const flatten = (arr: any[]) => {
3✔
UNCOV
372
    let result = [];
×
373

UNCOV
374
    arr.forEach(el => {
×
UNCOV
375
        result.push(el);
×
UNCOV
376
        if (el.children) {
×
UNCOV
377
            const children = Array.isArray(el.children) ? el.children : el.children.toArray();
×
UNCOV
378
            result = result.concat(flatten(children));
×
379
        }
380
    });
UNCOV
381
    return result;
×
382
};
383

384
export interface CancelableEventArgs {
385
    /**
386
     * Provides the ability to cancel the event.
387
     */
388
    cancel: boolean;
389
}
390

391
export interface IBaseEventArgs {
392
    /**
393
     * Provides reference to the owner component.
394
     */
395
    owner?: any;
396
}
397

398
export interface CancelableBrowserEventArgs extends CancelableEventArgs {
399
    /* blazorSuppress */
400
    /** Browser event */
401
    event?: Event;
402
}
403

404
export interface IBaseCancelableBrowserEventArgs extends CancelableBrowserEventArgs, IBaseEventArgs { }
405

406
export interface IBaseCancelableEventArgs extends CancelableEventArgs, IBaseEventArgs { }
407

408
export const HORIZONTAL_NAV_KEYS = new Set(['arrowleft', 'left', 'arrowright', 'right', 'home', 'end']);
3✔
409

410
export const NAVIGATION_KEYS = new Set([
3✔
411
    'down',
412
    'up',
413
    'left',
414
    'right',
415
    'arrowdown',
416
    'arrowup',
417
    'arrowleft',
418
    'arrowright',
419
    'home',
420
    'end',
421
    'space',
422
    'spacebar',
423
    ' '
424
]);
425
export const ACCORDION_NAVIGATION_KEYS = new Set('up down arrowup arrowdown home end'.split(' '));
3✔
426
export const ROW_EXPAND_KEYS = new Set('right down arrowright arrowdown'.split(' '));
3✔
427
export const ROW_COLLAPSE_KEYS = new Set('left up arrowleft arrowup'.split(' '));
3✔
428
export const ROW_ADD_KEYS = new Set(['+', 'add', '≠', '±', '=']);
3✔
429
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS),
3✔
430
...Array.from(ROW_ADD_KEYS), 'enter', 'f2', 'escape', 'esc', 'pagedown', 'pageup']);
431
export const HEADER_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'escape', 'esc', 'l',
3✔
432
    /** This symbol corresponds to the Alt + L combination under MAC. */
433
    '¬']);
434

435
/**
436
 * @hidden
437
 * @internal
438
 *
439
 * Creates a new ResizeObserver on `target` and returns it as an Observable.
440
 * Run the resizeObservable outside angular zone, because it patches the MutationObserver which causes an infinite loop.
441
 * Related issue: https://github.com/angular/angular/issues/31712
442
 */
443
export const resizeObservable = (target: HTMLElement): Observable<ResizeObserverEntry[]> => {
3✔
UNCOV
444
    const resizeObserver = getResizeObserver();
×
445
    // check whether we are on server env or client env
UNCOV
446
    if (resizeObserver) {
×
UNCOV
447
        return new Observable((observer) => {
×
UNCOV
448
            const instance = new resizeObserver((entries: ResizeObserverEntry[]) => {
×
UNCOV
449
                observer.next(entries);
×
450
            });
UNCOV
451
            instance.observe(target);
×
UNCOV
452
            const unsubscribe = () => instance.disconnect();
×
UNCOV
453
            return unsubscribe;
×
454
        });
455
    }
456
    // if on a server env return a empty observable that does not complete immediately
457
    return NEVER;
×
458

459
}
460

461
/**
462
 * @hidden
463
 * @internal
464
 *
465
 * Compares two maps.
466
 */
467
export const compareMaps = (map1: Map<any, any>, map2: Map<any, any>): boolean => {
3✔
UNCOV
468
    if (!map2) {
×
UNCOV
469
        return !map1;
×
470
    }
UNCOV
471
    if (map1.size !== map2.size) {
×
472
        return false;
×
473
    }
UNCOV
474
    let match = true;
×
UNCOV
475
    const keys = Array.from(map2.keys());
×
UNCOV
476
    for (const key of keys) {
×
UNCOV
477
        if (map1.has(key)) {
×
UNCOV
478
            match = map1.get(key) === map2.get(key);
×
479
        } else {
480
            match = false;
×
481
        }
UNCOV
482
        if (!match) {
×
UNCOV
483
            break;
×
484
        }
485
    }
UNCOV
486
    return match;
×
487
};
488

489
function _isObject(entity: unknown): entity is object {
UNCOV
490
    return entity != null && typeof entity === 'object';
×
491
}
492

493
export function columnFieldPath(path?: string): string[] {
UNCOV
494
    return path?.split('.') ?? [];
×
495
}
496

497
/**
498
 * Given a property access path in the format `x.y.z` resolves and returns
499
 * the value of the `z` property in the passed object.
500
 *
501
 * @hidden
502
 * @internal
503
 */
504
export function resolveNestedPath<T extends object, U>(obj: unknown, pathParts: string[], defaultValue?: U): T | U | undefined {
UNCOV
505
    if (!_isObject(obj) || pathParts.length < 1) {
×
UNCOV
506
        return defaultValue;
×
507
    }
508

UNCOV
509
    let current = obj;
×
510

UNCOV
511
    for (const key of pathParts) {
×
UNCOV
512
        if (_isObject(current) && key in (current as T)) {
×
UNCOV
513
            current = current[key];
×
514
        } else {
UNCOV
515
            return defaultValue;
×
516
        }
517
    }
518

UNCOV
519
    return current as T;
×
520
}
521

522
/**
523
 *
524
 * Given a property access path in the format `x.y.z` and a value
525
 * this functions builds and returns an object following the access path.
526
 *
527
 * @example
528
 * ```typescript
529
 * console.log('x.y.z.', 42);
530
 * >> { x: { y: { z: 42 } } }
531
 * ```
532
 *
533
 * @hidden
534
 * @internal
535
 */
536
export const reverseMapper = (path: string, value: any) => {
3✔
UNCOV
537
    const obj = {};
×
UNCOV
538
    const parts = path?.split('.') ?? [];
×
539

UNCOV
540
    let _prop = parts.shift();
×
541
    let mapping: any;
542

543
    // Initial binding for first level bindings
UNCOV
544
    obj[_prop] = value;
×
UNCOV
545
    mapping = obj;
×
546

UNCOV
547
    parts.forEach(prop => {
×
548
        // Start building the hierarchy
UNCOV
549
        mapping[_prop] = {};
×
550
        // Go down a level
UNCOV
551
        mapping = mapping[_prop];
×
552
        // Bind the value and move the key
UNCOV
553
        mapping[prop] = value;
×
UNCOV
554
        _prop = prop;
×
555
    });
556

UNCOV
557
    return obj;
×
558
};
559

560
export const yieldingLoop = (count: number, chunkSize: number, callback: (index: number) => void, done: () => void) => {
3✔
UNCOV
561
    let i = 0;
×
UNCOV
562
    const chunk = () => {
×
UNCOV
563
        const end = Math.min(i + chunkSize, count);
×
UNCOV
564
        for (; i < end; ++i) {
×
UNCOV
565
            callback(i);
×
566
        }
UNCOV
567
        if (i < count) {
×
UNCOV
568
            setImmediate(chunk);
×
569
        } else {
UNCOV
570
            done();
×
571
        }
572
    };
UNCOV
573
    chunk();
×
574
};
575

576
export const isConstructor = (ref: any) => typeof ref === 'function' && Boolean(ref.prototype) && Boolean(ref.prototype.constructor);
3!
577

578
/**
579
 * Similar to Angular's formatDate. However it will not throw on `undefined | null | ''` instead
580
 * coalescing to an empty string.
581
 */
582
export const formatDate = (value: string | number | Date, format: string, locale: string, timezone?: string): string => {
3✔
UNCOV
583
    if (value === null || value === undefined || value === '') {
×
UNCOV
584
        return '';
×
585
    }
UNCOV
586
    return _formatDate(value, format, locale, timezone);
×
587
};
588

589
export const formatCurrency = new CurrencyPipe(undefined).transform;
3✔
590

591
/** Converts pixel values to their rem counterparts for a base value */
592
export const rem = (value: number | string) => {
3✔
UNCOV
593
    const base = parseFloat(globalThis.window?.getComputedStyle(globalThis.document?.documentElement).getPropertyValue('--ig-base-font-size'))
×
UNCOV
594
    return Number(value) / base;
×
595
}
596

597
/** Get the size of the component as derived from the CSS size variable */
598
export function getComponentSize(el: Element) {
UNCOV
599
    return globalThis.window?.getComputedStyle(el).getPropertyValue('--component-size');
×
600
}
601

602
/** Get the first item in an array */
603
export function first<T>(arr: T[]) {
UNCOV
604
    return arr.at(0) as T;
×
605
}
606

607
/** Get the last item in an array */
608
export function last<T>(arr: T[]) {
UNCOV
609
    return arr.at(-1) as T;
×
610
}
611

612
/** Calculates the modulo of two numbers, ensuring a non-negative result. */
613
export function modulo(n: number, d: number) {
UNCOV
614
    return ((n % d) + d) % d;
×
615
}
616

617
/**
618
 * Splits an array into chunks of length `size` and returns a generator
619
 * yielding each chunk.
620
 * The last chunk may contain less than `size` elements.
621
 *
622
 * @example
623
 * ```typescript
624
 * const arr = [0,1,2,3,4,5,6,7,8,9];
625
 *
626
 * Array.from(chunk(arr, 2)) // [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]
627
 * Array.from(chunk(arr, 3)) // [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
628
 * Array.from(chunk([], 3)) // []
629
 * Array.from(chunk(arr, -3)) // Error
630
 * ```
631
 */
632
export function* intoChunks<T>(arr: T[], size: number) {
UNCOV
633
    if (size < 1) {
×
634
        throw new Error('size must be an integer >= 1');
×
635
    }
UNCOV
636
    for (let i = 0; i < arr.length; i += size) {
×
UNCOV
637
        yield arr.slice(i, i + size);
×
638
    }
639
}
640

641
/**
642
 * @param size
643
 * @returns string that represents the --component-size default value
644
 */
645
export function getComponentCssSizeVar(size: string) {
646
    switch (size) {
×
647
        case "1":
648
            return 'var(--ig-size, var(--ig-size-small))';
×
649
        case "2":
650
            return 'var(--ig-size, var(--ig-size-medium))';
×
651
        default:
652
            return 'var(--ig-size, var(--ig-size-large))';
×
653
    }
654
}
655

656
/**
657
 * @param path - The URI path to be normalized.
658
 * @returns string encoded using the encodeURI function.
659
 */
660
export function normalizeURI(path: string) {
UNCOV
661
    return path?.split('/').map(encodeURI).join('/');
×
662
}
663

664
export function getComponentTheme(el: Element) {
665
    return globalThis.window
43✔
666
        ?.getComputedStyle(el)
667
        .getPropertyValue('--theme')
668
        .trim() as IgxTheme;
669
}
670

671
/**
672
 * Collection re-created w/ the built in track by identity will always log
673
 * warning even for valid cases of recalculating all collection items.
674
 * See https://github.com/angular/angular/blob/55581b4181639568fb496e91055142a1b489e988/packages/core/src/render3/instructions/control_flow.ts#L393-L409
675
 * Current solution explicit track function doing the same as suggested in:
676
 * https://github.com/angular/angular/issues/56471#issuecomment-2180315803
677
 * This should be used with moderation and when necessary.
678
 * @internal
679
 */
680
export function trackByIdentity<T>(item: T): T {
UNCOV
681
    return item;
×
682
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc