Skip to content

Instantly share code, notes, and snippets.

@piouc
Last active January 7, 2025 04:14
Show Gist options
  • Save piouc/1c6c9680a99e03c1bacab0792d05b08c to your computer and use it in GitHub Desktop.
Save piouc/1c6c9680a99e03c1bacab0792d05b08c to your computer and use it in GitHub Desktop.
replace-all-rem.js
const { writeFile } = require('fs')
const fsp = require('fs/promises')
const { parse } = require('path')
;(async () => {
const files = await fsp.readdir('./', {recursive: true})
for(const file of files){
if(['.js', '.json', '.css', '.liquid', '.html'].includes(parse(file).ext)){
const data = await fsp.readFile(file, 'utf8')
const replaced = data.replace(/(\d+(\.\d+)?|\.?\d+|0)rem/g, match => {
const num = Number(match.replace('rem', ''))
return `${Math.round(num * 0.625 * 100) / 100}rem`
})
await fsp.writeFile(file, replaced)
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment