import { groupBy , mapValues } from 'lodash' ; export function nest ( items , keys ) { if ( ! keys . length ) { return items ; } const [ first , ... rest ] = keys ; return mapValues ( groupBy ( items , first as string ) , ( value ) => nest ( value , rest ) ) ; }