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]) }

      Inspired by: https://hyp.is/zmkwioCVEeugtheDFcLEkw/stackoverflow.com/questions/8747561/is-there-any-way-to-rename-js-object-keys-using-underscore-js