Guest User

Untitled

a guest
May 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const args = process.argv.slice(2)
  2. const fs = require('fs')
  3. const file = args[0] || ''
  4.  
  5. const parseStyles = styles => styles
  6. .split(';')
  7. .filter(style => style.split(':')[0] && style.split(':')[1])
  8. .map(style => [
  9. style.split(':')[0].trim().replace(/-./g, c => c.substr(1).toUpperCase()),
  10. `'${style.split(':')[1].trim()}'`
  11. ].join(': ')).join(', ')
  12.  
  13. fs.readFile(file, 'utf8', (err, data) => {
  14. if (err) { return console.log(err) }
  15.  
  16. const styleAttributes = data.match(/style=(?:"|')[^("|')]+./g)
  17. for (const attribute of styleAttributes) {
  18. const style = attribute.match(/style=(?:"|')([^("|')]+)/)[1]
  19. data = data.replace(attribute, `style={{${parseStyles(style)}}}`)
  20. }
  21.  
  22. fs.writeFile(file, data, 'utf8', (err) => {
  23. if (err) return console.log(err)
  24. })
  25. })
Add Comment
Please, Sign In to add comment