Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const args = process.argv.slice(2)
- const fs = require('fs')
- const file = args[0] || ''
- const parseStyles = styles => styles
- .split(';')
- .filter(style => style.split(':')[0] && style.split(':')[1])
- .map(style => [
- style.split(':')[0].trim().replace(/-./g, c => c.substr(1).toUpperCase()),
- `'${style.split(':')[1].trim()}'`
- ].join(': ')).join(', ')
- fs.readFile(file, 'utf8', (err, data) => {
- if (err) { return console.log(err) }
- const styleAttributes = data.match(/style=(?:"|')[^("|')]+./g)
- for (const attribute of styleAttributes) {
- const style = attribute.match(/style=(?:"|')([^("|')]+)/)[1]
- data = data.replace(attribute, `style={{${parseStyles(style)}}}`)
- }
- fs.writeFile(file, data, 'utf8', (err) => {
- if (err) return console.log(err)
- })
- })
Add Comment
Please, Sign In to add comment