Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ast.walk(node => {
const [lightness, alpha] = getFunctionGrayArgs(node);
if (lightness !== undefined) {
// rename the gray() function to rgb()
node.value = 'rgb';
// convert the lab gray lightness into rgb
const [r, g, b] = lab2rgb(lightness, 0, 0).map(
channel => Math.max(Math.min(Math.round(channel * 2.55), 255), 0)
);
// preserve the slash nodes within rgb()
const openingSlash = node.first;
const closingSlash = node.last;
node.removeAll()
// replace the contents of rgb with `(r,g,b`
.append(openingSlash)
.append(parser.number({ value: r }))
.append(parser.comma({ value: ',' }))
.append(parser.number({ value: g }))
.append(parser.comma({ value: ',' }))
.append(parser.number({ value: b }))