Zet - How can I get all the const keys on Drains?
How can I get all the const keys on Drains?
eg. Ones which are ALL_CAPS with underscore
Object.keys(Drains).filter((key) => /^[A-Z_]+$/.test(key))
^and$specify the start and end of the string, ensuring the entire key is uppercase.[A-Z_]+matches one or more uppercase letters or underscores.
Bonus: Here’s a script to get a json dump of the value
const jsonString = JSON.stringify(
Object.keys(Drains)
.filter((key) => /^[A-Z_]+$/.test(key))
.reduce((acc, key) => {
acc[key] = Drains[key];
return acc;
}, {})
);
#drains