UNPKG

nba

Version:

JavaScript client for the NBA's stats API

18 lines (13 loc) 416 B
const mapKeys = require("lodash.mapkeys"); module.exports = function translateKeys (translationMap, target) { if (typeof target !== "object") { throw new Error("needs an object"); } return mapKeys(target, function (value, oldKey) { const newKey = translationMap[oldKey]; if (newKey == null) { throw new Error(`Key '${oldKey}' not found in translator.`); } return newKey; }); };