(filename: string, taken: Set<string>)
| 102 | } |
| 103 | |
| 104 | export function safeAssetIdentifier(filename: string, taken: Set<string>): string { |
| 105 | const stem = filename.replace(/\.[^.]+$/, ''); |
| 106 | let camel = ''; |
| 107 | let upper = false; |
| 108 | for (const ch of stem) { |
| 109 | if (/[A-Za-z0-9]/.test(ch)) { |
| 110 | camel += upper ? ch.toUpperCase() : ch; |
| 111 | upper = false; |
| 112 | } else { |
| 113 | upper = camel.length > 0; |
| 114 | } |
| 115 | } |
| 116 | let base = camel; |
| 117 | if (!base || !/^[A-Za-z_$]/.test(base)) { |
| 118 | base = `asset${base.charAt(0).toUpperCase()}${base.slice(1)}` || 'asset'; |
| 119 | } |
| 120 | base = base.charAt(0).toLowerCase() + base.slice(1); |
| 121 | let candidate = base; |
| 122 | let i = 2; |
| 123 | while (taken.has(candidate)) { |
| 124 | candidate = `${base}${i}`; |
| 125 | i += 1; |
| 126 | } |
| 127 | return candidate; |
| 128 | } |
| 129 | |
| 130 | type JsxContainer = t.JSXElement | t.JSXFragment; |
| 131 |
no outgoing calls
no test coverage detected