@stacksjs/iconify-generator 0.2.19 → 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 +31 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/iconify-generator",
3
3
  "type": "module",
4
- "version": "0.2.19",
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.19"
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
@@ -809,10 +827,19 @@ export async function generatePackage(
809
827
  }
810
828
 
811
829
  /**
812
- * Convert kebab-case to camelCase
830
+ * Convert kebab-case to a valid JS identifier in camelCase form.
831
+ * Iconify allows names that start with digits (e.g. "2", "3d-move") and
832
+ * names containing dots/slashes — none of which are legal JS identifiers.
833
+ * Prefix with `_` when the first char isn't [A-Za-z_$], and replace any
834
+ * remaining illegal chars with `_` so downstream `export { default as X }`
835
+ * always parses.
813
836
  */
814
837
  export function toCamelCase(str: string): string {
815
- return str.replace(/-([a-z0-9])/g, g => g[1].toUpperCase())
838
+ let camel = str.replace(/-([a-z0-9])/g, g => g[1].toUpperCase())
839
+ camel = camel.replace(/[^a-zA-Z0-9_$]/g, '_')
840
+ if (/^[0-9]/.test(camel))
841
+ camel = `_${camel}`
842
+ return camel
816
843
  }
817
844
 
818
845
  /**