MCPcopy Index your code
hub / github.com/angular/angular / toStylingKeyValueArray

Function toStylingKeyValueArray

packages/core/src/render3/instructions/styling.ts:682–717  ·  view source on GitHub ↗
(
  keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
  stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
  value: string | string[] | Set<string> | {[key: string]: any} | SafeValue | null | undefined,
)

Source from the content-addressed store, hash-verified

680 * @param value The value to parse/convert to `KeyValueArray`
681 */
682export function toStylingKeyValueArray(
683 keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
684 stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
685 value: string | string[] | Set<string> | {[key: string]: any} | SafeValue | null | undefined,
686): KeyValueArray<any> {
687 if (value == null /*|| value === undefined */ || value === '') return EMPTY_ARRAY as any;
688 const styleKeyValueArray: KeyValueArray<any> = [] as any;
689 const unwrappedValue = unwrapSafeValue(value) as
690 | string
691 | string[]
692 | Set<string>
693 | {[key: string]: any};
694 if (Array.isArray(unwrappedValue)) {
695 for (let i = 0; i < unwrappedValue.length; i++) {
696 keyValueArraySet(styleKeyValueArray, unwrappedValue[i], true);
697 }
698 } else if (unwrappedValue instanceof Set) {
699 for (const current of unwrappedValue) {
700 keyValueArraySet(styleKeyValueArray, current, true);
701 }
702 } else if (typeof unwrappedValue === 'object') {
703 for (const key in unwrappedValue) {
704 if (Object.hasOwn(unwrappedValue, key)) {
705 keyValueArraySet(styleKeyValueArray, key, unwrappedValue[key]);
706 }
707 }
708 } else if (typeof unwrappedValue === 'string') {
709 stringParser(styleKeyValueArray, unwrappedValue);
710 } else {
711 ngDevMode &&
712 throwError(
713 'Unsupported styling type: ' + typeof unwrappedValue + ' (' + unwrappedValue + ')',
714 );
715 }
716 return styleKeyValueArray;
717}
718
719/**
720 * Set a `value` for a `key`.

Callers 2

styling_spec.tsFile · 0.90
checkStylingMapFunction · 0.85

Calls 4

unwrapSafeValueFunction · 0.90
keyValueArraySetFunction · 0.90
throwErrorFunction · 0.90
isArrayMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…