(
input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
)
| 116 | ): T extends object ? Array<KeyValue<keyof T, T[keyof T]>> : null; |
| 117 | |
| 118 | transform<K, V>( |
| 119 | input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>, |
| 120 | compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator, |
| 121 | ): Array<KeyValue<K, V>> | null { |
| 122 | ngDevMode && warnIfSignal('KeyValuePipe', input); |
| 123 | |
| 124 | if (!input || (!(input instanceof Map) && typeof input !== 'object')) { |
| 125 | return null; |
| 126 | } |
| 127 | |
| 128 | // make a differ for whatever type we've been passed in |
| 129 | this.differ ??= this.differs.find(input).create(); |
| 130 | |
| 131 | const differChanges: KeyValueChanges<K, V> | null = this.differ.diff(input as any); |
| 132 | const compareFnChanged = compareFn !== this.compareFn; |
| 133 | |
| 134 | if (differChanges || compareFnChanged) { |
| 135 | this.keyValues = []; |
| 136 | if (differChanges) { |
| 137 | differChanges.forEachItem((r: KeyValueChangeRecord<K, V>) => { |
| 138 | this.keyValues.push(makeKeyValuePair(r.key, r.currentValue!)); |
| 139 | }); |
| 140 | } else if (input instanceof Map) { |
| 141 | // Only `compareFn` changed. Rebuild from the input, since the previous result may be sorted. |
| 142 | input.forEach((value: V, key: K) => this.keyValues.push(makeKeyValuePair(key, value))); |
| 143 | } else { |
| 144 | for (const key of Object.keys(input)) { |
| 145 | this.keyValues.push(makeKeyValuePair(key as K, (input as any)[key])); |
| 146 | } |
| 147 | } |
| 148 | if (compareFn) { |
| 149 | this.keyValues.sort(compareFn); |
| 150 | } |
| 151 | this.compareFn = compareFn; |
| 152 | } |
| 153 | return this.keyValues; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | export function defaultComparator<K, V>( |
nothing calls this directly
no test coverage detected