// Suffix can be a falsey value so nothing is appended to string // (helps when looping over props & some shouldn't change) import {upperFirst} from './stringUtils' /** * Use data last parameters to allow for currying * * @param suffix * @param value * @returns */ export const suffixPropName = (suffix: string, value: string): string => value + (suffix ? upperFirst(suffix) : '') /** * Given an array of properties or an object of property keys, plucks all the values off the target object, returning a new object that has props that reference the original prop values. * An object equivelent to TS Pick<> * * @param {ReadonlyArray | Record} keysToPluck * @param {Record} objToPluck * @returns */ export const pluckProps = < A extends Record, B extends ReadonlyArray | Record >( objToPluck: A, keysToPluck: B ): B extends readonly PropertyKey[] ? Pick : Pick => (Array.isArray(keysToPluck) ? keysToPluck.slice() : Object.keys(keysToPluck)).reduce( (memo, prop) => { memo[prop] = objToPluck[prop] return memo }, {} )