Skip to content

Instantly share code, notes, and snippets.

@tsmd
Last active September 5, 2020 14:02
Show Gist options
  • Save tsmd/b42c1dcd1dd43b94341bc2e947106953 to your computer and use it in GitHub Desktop.
Save tsmd/b42c1dcd1dd43b94341bc2e947106953 to your computer and use it in GitHub Desktop.
rem を 10/16 倍する
#!/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