* Convert a dotted CDDL name to PascalCase TypeScript name. * "browsingContext.Info" → "BrowsingContextInfo"
(name)
| 383 | * "browsingContext.Info" → "BrowsingContextInfo" |
| 384 | */ |
| 385 | function normalizeDottedName(name) { |
| 386 | return name |
| 387 | .split('.') |
| 388 | .map((part) => |
| 389 | // A schema name segment may itself be hyphenated (e.g. the CDDL prelude |
| 390 | // range aliases 'js-uint'/'js-int'), which isn't a valid TS identifier |
| 391 | // character — split on '-' too so each word gets its own PascalCase turn. |
| 392 | part |
| 393 | .split('-') |
| 394 | .map((word) => { |
| 395 | const titled = word.charAt(0).toUpperCase() + word.slice(1) |
| 396 | // Normalize acronym runs to match cddl2ts output: |
| 397 | // CSPParameters → CspParameters HTMLCollection → HtmlCollection |
| 398 | // Rule: 2+ uppercase letters followed by an uppercase+lowercase pair (or end |
| 399 | // of string) → keep only the first uppercase and lowercase the rest. |
| 400 | return titled.replace(/([A-Z]{2,})(?=[A-Z][a-z]|$)/g, (m) => m[0] + m.slice(1).toLowerCase()) |
| 401 | }) |
| 402 | .join(''), |
| 403 | ) |
| 404 | .join('') |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Walk the `CommandData` or `EventData` union type hierarchy and collect all |
no test coverage detected