UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

28 lines 1.06 kB
/** * getDeepestSplits will take an array of strings like an array of deep object keys and return the set of keys at particular depth. * The point of the function is to get the deepest key of something like a deep object property for table heading labels for EasyAnalyticsHook. * * for instance deepKeys = [ 'a.b.c', 'w.x.y.z', '0.1.2.3.4.5' ] and assuming delim = '.' * * if idx === 0 : result: [ 'a','w','0' ] * if idx === 1 : result: [ 'b','x','1' ] * if idx === 2 : result: [ 'c','y','2' ] * if idx === 97 : result: [ 'c','z','5' ] * * @param deepKeys * @param delim * @param idx * @returns */ export function getDeepestSplits(deepKeys, delim = '.', idx = 97) { const keys = []; // Only map if there is something to map if (deepKeys && deepKeys.length > 0) deepKeys.map((key) => { const kS = key.split(delim); const pos = Math.min(idx, kS.length - 1); keys.push(kS[pos]); }); return keys; } //# sourceMappingURL=getDeepKeys.js.map