Last active
January 7, 2025 04:14
-
-
Save piouc/1c6c9680a99e03c1bacab0792d05b08c to your computer and use it in GitHub Desktop.
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