32 lines
759 B
JavaScript
32 lines
759 B
JavaScript
/**
|
|
* Support utilities for handling the API
|
|
*
|
|
*/
|
|
'use strict';
|
|
|
|
var _ = require('lodash');
|
|
|
|
module.exports = {
|
|
renameFields: renameFields
|
|
};
|
|
|
|
/**
|
|
* Rename a field in the item by copying it to the new value and then deleting
|
|
* the old name.
|
|
*
|
|
* @param {Object | Object[]} items - The item or items to have the params renamed
|
|
* @param {Object} conversions - Key/values for the src name and dest name
|
|
*/
|
|
function renameFields(items, conversions) {
|
|
if (Array.isArray(items)) {
|
|
for (var i = 0; i < items.length; ++i) {
|
|
renameFields(items[i], conversions);
|
|
}
|
|
} else {
|
|
_.forEach(conversions, function(dest, src) {
|
|
items[dest] = items[src];
|
|
delete items[src];
|
|
});
|
|
}
|
|
}
|