@stacksjs/iconify-generator 0.2.20 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.ts +20 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/iconify-generator",
3
3
  "type": "module",
4
- "version": "0.2.20",
4
+ "version": "0.2.21",
5
5
  "description": "Generator for Iconify icon packages",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "dev": "bun build.ts --watch"
34
34
  },
35
35
  "dependencies": {
36
- "@stacksjs/iconify-core": "0.2.20"
36
+ "@stacksjs/iconify-core": "0.2.21"
37
37
  }
38
38
  }
package/src/index.ts CHANGED
@@ -192,9 +192,27 @@ const svg = \`<svg xmlns="http://www.w3.org/2000/svg" width="\${iconWidth}" heig
192
192
  * Generate index file for a collection
193
193
  */
194
194
  export function generateIndexFile(iconNames: string[]): string {
195
+ // toCamelCase can produce collisions across distinct kebab names
196
+ // (e.g. "mp-401" and "mp-4-01" both → "mp401"). Track used identifiers
197
+ // and disambiguate later occurrences with a fully-sanitized form of the
198
+ // original kebab name, then a numeric suffix as a final fallback.
199
+ const used = new Set<string>()
195
200
  const dataExports = iconNames.map((name) => {
196
- const camelCaseName = toCamelCase(name)
197
- return `export { default as ${camelCaseName} } from './${name}.js'`
201
+ const primary = toCamelCase(name)
202
+ let id = primary
203
+ if (used.has(id)) {
204
+ let candidate = name.replace(/[^a-zA-Z0-9]/g, '_')
205
+ if (/^[0-9]/.test(candidate))
206
+ candidate = `_${candidate}`
207
+ id = candidate
208
+ let n = 2
209
+ while (used.has(id)) {
210
+ id = `${candidate}_${n}`
211
+ n++
212
+ }
213
+ }
214
+ used.add(id)
215
+ return `export { default as ${id} } from './${name}.js'`
198
216
  }).join('\n')
199
217
 
200
218
  return `// Icon data exports