Skip to content

Instantly share code, notes, and snippets.

@sayjeyhi
Created November 6, 2020 10:55
Show Gist options
  • Save sayjeyhi/214e290bd68539a14d7dea891174c0f0 to your computer and use it in GitHub Desktop.
Save sayjeyhi/214e290bd68539a14d7dea891174c0f0 to your computer and use it in GitHub Desktop.
function convertTypeToAction(types) {
function toCamelCase(str) {
// Lower cases the string
return str.toLowerCase()
.replace( /[-_]+/g, ' ')
.replace( /[^\w\s]/g, '')
.replace( / (.)/g, function($1) { return $1.toUpperCase(); })
.replace( / /g, '' );
}
let content = '';
Object.keys(types).forEach(type => {
content += `${toCamelCase(type)}: actionMaker(type.${type}),`
content += "\n";
});
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment