Last active
September 5, 2020 14:02
-
-
Save tsmd/b42c1dcd1dd43b94341bc2e947106953 to your computer and use it in GitHub Desktop.
rem を 10/16 倍する
This file contains 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
#!/usr/bin/env node | |
/** | |
* @fileoverview rem を 10/16 倍する | |
* @example cat styles.css | ./adjust-rem > styles.css | |
*/ | |
const { readFileSync } - require("fs"); | |
const postcss = require("postcss"); | |
const plugin = postcss.plugin("adjust-rem", () => { | |
return (root) => { | |
root.replaceValues(/([-.\d])+rem/g, { fast: "rem" }, (string) => { | |
const value = parseFloat(string.replace(/^\./, "0.")); | |
return (value * 10) / 16 + "rem"; | |
}); | |
}; | |
}); | |
const input = readFileSync(process.stdin.fd, { encoding: "utf-8" }) | |
postcss([plugin]) | |
.process(input) | |
.then((result) => console.log(result.toString())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment