Skip to content

Commit 98e0117

Browse files
authored
Merge pull request #1041 from dnum-mi/feat/icon-dict
feat: ✨ make icon dictionnary
2 parents fff563d + 1f34b69 commit 98e0117

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

meta/custom-icon-collections-creator.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function createCustomCollectionFile (sourcePath, targetPath) {
3232

3333
const code = `import type { IconifyJSON } from '@iconify/vue'
3434
const collections: IconifyJSON[] = ${JSON.stringify(collections)}
35+
${collections.map(collection => `export const ${collection.prefix} = ${makeCollection(collection)} as const`).join('\n')}
3536
export default collections`
3637

3738
try {
@@ -131,3 +132,24 @@ export async function runShellCommand (command) {
131132
console.error('Erreur d’exécution :', error)
132133
}
133134
}
135+
136+
/**
137+
* @function
138+
* @param {string} icon
139+
*
140+
* @returns {string} a camelCase icon
141+
*/
142+
function camelize (icon) {
143+
return icon.replace(/-./g, x => x[1].toUpperCase())
144+
}
145+
146+
/**
147+
* @function
148+
* @param {import('@iconify/vue/dist/iconify.js').IconifyJSON} collection
149+
*
150+
* @returns {string} stringified collection
151+
*/
152+
function makeCollection (collection) {
153+
return JSON.stringify(Object.fromEntries(Object.keys(collection.icons)
154+
.map(icon => ([camelize(icon), `${collection.prefix}:${icon}`]))))
155+
}

0 commit comments

Comments
 (0)