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

SAP / ui5-webcomponents-react / 9890609870

11 Jul 2024 11:30AM CUT coverage: 79.701% (-0.9%) from 80.604%
9890609870

Pull #6061

github

web-flow
Merge 357334feb into 3822beed4
Pull Request #6061: refactor: replace `Toolbar` with UI5 Web Component

2532 of 3761 branches covered (67.32%)

4586 of 5754 relevant lines covered (79.7%)

72781.43 hits per line

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

96.3
/packages/main/src/internal/utils.ts
1
import {
2
  getCustomElementsScopingSuffix,
3
  getEffectiveScopingSuffixForTag,
4
  getScopedVarName
5
} from '@ui5/webcomponents-base/dist/CustomElementsScope.js';
6
import type { ReactNode } from 'react';
7
import { Children, cloneElement, Fragment } from 'react';
8

9
export function flattenFragments<T = ReactNode>(children: T | T[], depth = 1): T[] {
179✔
10
  const flatChildren = [];
8,997✔
11
  const removeFragments = (element, level = 0, key = []) => {
8,997✔
12
    if (!element) {
33,041✔
13
      return;
2,839✔
14
    }
15
    if (Array.isArray(element)) {
30,202✔
16
      Children.toArray(element).forEach((child, index) => {
3,263✔
17
        removeFragments(child, level + 1, [...key, index]);
17,320✔
18
      });
19
      return;
3,263✔
20
    }
21
    if (element.type === Fragment && level <= depth) {
26,939✔
22
      Children.toArray(element.props?.children).forEach((item, index) => {
3,139✔
23
        removeFragments(item, level + 1, [...key, index]);
6,724✔
24
      });
25
    } else if (typeof element === 'string' || typeof element === 'number') {
23,800!
26
      flatChildren.push(element);
×
27
    } else {
28
      flatChildren.push(cloneElement(element, { key: key.join('.') }));
23,800✔
29
    }
30
  };
31
  removeFragments(children);
8,997✔
32

33
  return flatChildren;
8,997✔
34
}
35

36
export const capitalizeFirstLetter = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
1,548,677✔
37
export const lowercaseFirstLetter = (s: string) => s.charAt(0).toLowerCase() + s.slice(1);
362✔
38
export const camelToKebabCase = (s: string) => s.replace(/([A-Z])/g, (a, b: string) => `-${b.toLowerCase()}`);
393,274✔
39
export const kebabToCamelCase = (str: string) => str.replace(/([-_]\w)/g, (g) => g[1].toUpperCase());
1,548,677✔
40

41
export function getUi5TagWithSuffix(baseTagName) {
42
  const tagNameSuffix: string = getEffectiveScopingSuffixForTag(baseTagName);
3,449✔
43
  return tagNameSuffix ? `${baseTagName}-${tagNameSuffix}` : baseTagName;
3,449!
44
}
45

46
export const isSSR = () => typeof window === 'undefined';
362✔
47

48
export function trimAndRemoveSpaces(value) {
49
  return value.trim().replace(/\s\s+/g, ' ');
673✔
50
}
51

52
export const cssVarVersionInfoPrefix = getScopedVarName('--_ui5_').replace('--_ui5_', '');
362✔
53

54
export function getTagNameWithoutScopingSuffix(tagName) {
55
  const tagNameSuffix = getCustomElementsScopingSuffix();
1,706✔
56
  return tagNameSuffix ? tagName.replace(`-${tagNameSuffix.toUpperCase()}`, '') : tagName;
1,706!
57
}
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

© 2025 Coveralls, Inc