ReferenceError: CSS is not defined

416 Views Asked by At

In a javascript application running in command line with node.js that is not attached to an HTML or CSS file, I want to use the CSS.supports function as it's useful for checking if a color input is valid.

async getColor(){
        await inquirer.prompt([
            {
                type: 'input',
                name: 'color',
                message: "Enter a CSS color keyword or hexadecimal value."
            }
        ]).then((answer) => {
            let potentialColor;
            if(answer.color.length === 6 && !isNaN(Number('0x' + answer.color))){
                potentialColor = '#' + answer.color;
            }
            else{
                potentialColor = answer.color;
            }
            if(CSS.supports('color', potentialColor)){
                this.color = potentialColor;
            }
            else{
                console.log("You did not enter a valid color keyword or hexadecimal value.")
                this.getColor();
            }
        });
    }

I get a 'ReferenceError: CSS is not defined' Yet my code editor recognizes it as a valid object. From my understanding CSSOM is supported by vanilla JavaScript. I was wondering if I needed to do something special to get access to CSSOM in JavaScript?

0

There are 0 best solutions below