I want to build dynamically my typescript enum from a list of files, but I don't know how to do that.
Here is the code I wrote to get an array of value:
const fs = require('fs');
fs.readdir('./src/assets/icons', (err, files) => {
const name = files
.filter(file => file.match('.svg'))
.map(fileFiltred => fileFiltred.replace('.svg', ''))
console.log(name) // ["arrow-right", "home", "menu"...]
})
Can we build dynamically a typescript enum ? how ?
You think I have to write manually all icons name in my folder like below ?
enum iconName {
HOME = 'home',
ARROW_RIGHT = 'arrow-right',
MENU = 'menu',
}
Thanks !