3 Matching Annotations
  1. Mar 2021
    1. // A general key transform method. Pass it a function that accepts the old key and returns // the new key. // // @example // obj = transformKeys(obj, (key) => ( // key.replace(/\b(big)\b/g, 'little') // )) export function transformKeys(source, f) { return Object.entries(source).reduce((o, [key, value]) => { o[f(key) || key] = value return o }, {}) } // Provide an object that maps from old key to new key export function rekeyObject(source, keyMap) { transformKeys(source, key => keyMap[key]) }
    2. function objectMap(source,keyMap) { return Object.entries(keyMap).reduce((o,[key , newKey]) => { o[newKey]=source[key] return o;},{}) }