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

Method transform

packages/common/src/pipes/keyvalue_pipe.ts:109–138  ·  view source on GitHub ↗
(
    input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
    compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
  )

Source from the content-addressed store, hash-verified

107 ): T extends object ? Array<KeyValue<keyof T, T[keyof T]>> : null;
108
109 transform<K, V>(
110 input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
111 compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
112 ): Array<KeyValue<K, V>> | null {
113 ngDevMode && warnIfSignal('KeyValuePipe', input);
114
115 if (!input || (!(input instanceof Map) && typeof input !== 'object')) {
116 return null;
117 }
118
119 // make a differ for whatever type we've been passed in
120 this.differ ??= this.differs.find(input).create();
121
122 const differChanges: KeyValueChanges<K, V> | null = this.differ.diff(input as any);
123 const compareFnChanged = compareFn !== this.compareFn;
124
125 if (differChanges) {
126 this.keyValues = [];
127 differChanges.forEachItem((r: KeyValueChangeRecord<K, V>) => {
128 this.keyValues.push(makeKeyValuePair(r.key, r.currentValue!));
129 });
130 }
131 if (differChanges || compareFnChanged) {
132 if (compareFn) {
133 this.keyValues.sort(compareFn);
134 }
135 this.compareFn = compareFn;
136 }
137 return this.keyValues;
138 }
139}
140
141export function defaultComparator<K, V>(

Callers

nothing calls this directly

Calls 7

warnIfSignalFunction · 0.90
makeKeyValuePairFunction · 0.85
createMethod · 0.65
diffMethod · 0.65
forEachItemMethod · 0.65
findMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected