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

Function toStylingKeyValueArray

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

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