Last active
January 7, 2025 04:14
replace-all-rem.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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