MCPcopy Create free account
hub / github.com/angular/angular / toStylingKeyValueArray

Function toStylingKeyValueArray

packages/core/src/render3/instructions/styling.ts:718–750  ·  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

716 * @param value The value to parse/convert to `KeyValueArray`
717 */
718export function toStylingKeyValueArray(
719 keyValueArraySet: (keyValueArray: KeyValueArray<any>, key: string, value: any) => void,
720 stringParser: (styleKeyValueArray: KeyValueArray<any>, text: string) => void,
721 value: string | string[] | Set<string> | {[key: string]: any} | SafeValue | null | undefined,
722): KeyValueArray<any> {
723 if (value == null /*|| value === undefined */ || value === '') return EMPTY_ARRAY as any;
724 const styleKeyValueArray: KeyValueArray<any> = [] as any;
725 const unwrappedValue = unwrapSafeValue(value) as
726 string | string[] | Set<string> | {[key: string]: any};
727 if (Array.isArray(unwrappedValue)) {
728 for (let i = 0; i < unwrappedValue.length; i++) {
729 keyValueArraySet(styleKeyValueArray, unwrappedValue[i], true);
730 }
731 } else if (unwrappedValue instanceof Set) {
732 for (const current of unwrappedValue) {
733 keyValueArraySet(styleKeyValueArray, current, true);
734 }
735 } else if (typeof unwrappedValue === 'object') {
736 for (const key in unwrappedValue) {
737 if (Object.hasOwn(unwrappedValue, key)) {
738 keyValueArraySet(styleKeyValueArray, key, unwrappedValue[key]);
739 }
740 }
741 } else if (typeof unwrappedValue === 'string') {
742 stringParser(styleKeyValueArray, unwrappedValue);
743 } else {
744 ngDevMode &&
745 throwError(
746 'Unsupported styling type: ' + typeof unwrappedValue + ' (' + unwrappedValue + ')',
747 );
748 }
749 return styleKeyValueArray;
750}
751
752/**
753 * 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