Skip to content

Instantly share code, notes, and snippets.

@roobie
Last active January 15, 2017 16:19
Show Gist options
  • Select an option

  • Save roobie/4641d331144c61cdb2fdd0ea3bd957fb to your computer and use it in GitHub Desktop.

Select an option

Save roobie/4641d331144c61cdb2fdd0ea3bd957fb to your computer and use it in GitHub Desktop.
// see https://github.com/roobie/uniform-accessor
import ua from 'uniform-accessor';
export default function uniformAccessTransform(object, extraProperties = {}) {
console.assert(typeof object === 'object', 'Must pass a source object');
let freshObject = {};
// iterate over the properties of the object, and
// create a uniform-accessor instance initialized
// to the value of the property.
Object.keys(object).forEach(k => {
freshObject[k] = ua(object[k]);
});
// assign any extra properties
Object.keys(extraProperties).forEach(k => {
freshObject[k] = extraProperties[k];
});
return freshObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment