All files / packages/sds-stylelint-config/src/utils namespace.ts

100% Statements 10/10
60% Branches 6/10
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                62x     372x             61x   61x 134x 81x     6x    
import sdsNamespaces from '@salesforce-ux/sds-namespaces';
 
interface NamespaceEntry {
  name: string;
  [key: string]: unknown;
}
 
export function getValidNamespaces(): string[] {
  const raw: NamespaceEntry[] = Array.isArray(sdsNamespaces)
    ? sdsNamespaces
    : ((sdsNamespaces as { default?: NamespaceEntry[] })?.default ?? []);
  return raw.map((entry) => (typeof entry === 'string' ? entry : entry.name));
}
 
export function validateNamespace(
  ns: string,
  privatePrefix: string,
): { valid: boolean; isPrivate: boolean; names: string[] } {
  const names = getValidNamespaces();
 
  for (const name of names) {
    if (ns === name) return { valid: true, isPrivate: false, names };
    if (ns === `${privatePrefix}${name}`) return { valid: true, isPrivate: true, names };
  }
 
  return { valid: false, isPrivate: false, names };
}