You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			13 lines
		
	
	
		
			318 B
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			13 lines
		
	
	
		
			318 B
		
	
	
	
		
			TypeScript
		
	
| 
											6 years ago
										 | import { fromPairs, map } from 'lodash'; | ||
|  | 
 | ||
|  | export function makeLookup<T>( | ||
|  |   items: Array<T>, | ||
|  |   key: string | ||
|  | ): { [key: string]: T } { | ||
|  |   // Yep, we can't index into item without knowing what it is. True. But we want to.
 | ||
|  |   // @ts-ignore
 | ||
|  |   const pairs = map(items, item => [item[key], item]); | ||
|  | 
 | ||
|  |   return fromPairs(pairs); | ||
|  | } |