Skip to content

Instantly share code, notes, and snippets.

@orrybaram
Created November 16, 2017 19:09
Show Gist options
  • Save orrybaram/a05fb3124782ff009ce368998b482dae to your computer and use it in GitHub Desktop.
Save orrybaram/a05fb3124782ff009ce368998b482dae to your computer and use it in GitHub Desktop.
const numberToPixel = prop => {
if (!Number.isInteger(prop) || prop === 0) return prop;
return `${prop}px`;
}
const camelToDash = str => str
.replace(/(^[A-Z])/, ([first]) => first.toLowerCase())
.replace(/([A-Z])/g, ([letter]) => `-${letter.toLowerCase()}`)
const cssObjectToString = (obj) => Object.entries(obj).reduce((styleString, entry) => (
styleString + camelToDash(entry[0]) + ': ' + numberToPixel(entry[1]) + ';\n'
), '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment