function createTransformString(transformConfig) {
// a variable to store array of individual transform strings
var transformStrings = [];
// store functions that build strings for each transform type
// not shown here but you may want to consider ECMA6 templating
var buildString = {
rotate: function(rotate) {
for (dim in rotate) {
transformStrings.push( 'rotate' + dim + '(' + rotate[dim] + 'deg)';' );
}
},
scale: function(scale) {
scale.x = scale.x || 1;
scale.y = scale.y || 1;
transformStrings.push( 'scale(' + scale.x + ',' + scale.y + ')' );
},
translate: function(translate) {
for (dim in translate) {
transformStrings.push( 'translate' + dim + '(' + translate[dim] + 'px)';' );
}
},
skew: function(skew) {
skew.x = skew.x || 0;
skew.y = skew.y || 0;
transformStrings.push( 'skew(' + skew.x + 'deg,' + skew.y + 'deg)' );
}
};
// iterate the config object to generate strings
for (transformAction in transformConfig) {
let transform = transformConfig[transformAction];
buildString[transformAction](transform);
}
return transformStrings.join(' ');
};
Finally, from a stylistic standpoint, I would recommend sticking with camelCase instead of snake_case, as this is pretty much the de facto standard for javascript. At a minimum, don't intermingle the two. Additionally, I would suggest watching your line length. You should strive to keep lines of code under ~80 characters per line to improve code readability.