Consider the object shown below:
const obj = {
foo: "bar",
hello: "world",
}
and this function for processing objects:
const process = (obj) => {
const processedObj = {}
for (const key in obj) {
processedObj[`--${key}`] = obj[key]
}
return processedObj
}
Is there a way to restrict the key
argument to only allow processed keys that begin with --
?
const processedObj = process(obj)
const getValue = (key) => {
return processedObj[key]
}
I am attempting to automate the conversion of JavaScript object properties into CSS variables so that Visual Studio Code's IntelliSense feature recommends getValue("--foo")
when typing getValue("--f")
.