DashCase and CamelCase intrinsic string types, or similar
See original GitHub issueSearch Terms
dashcase snakecase
Suggestion
It would be great to also have DashCase
and CamelCase
and similar!
Use Cases
It is common in DOM libs to map from JS camelCase properties to DOM dash-case attributes (f.e. el.fooBar = 123
and <el foo-bar="123">
), or CapitalizedClass names to dash-case custom element names (f.e. class FooBar extends HTMLElement
and <foo-bar>
).
Examples
type T1 = Dashcase<'fooBar' | 'BarBaz'> // 'foo-bar' | 'bar-baz'
type T2 = Camelcase<'foo-bar' | 'bar-baz'> // 'fooBar' | 'barBaz'
Or similar.
Checklist
My suggestion meets these guidelines:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Intrinsic Types in TypeScript - Level Up Coding - gitconnected
As of TypeScript 4.1, there exist 4 intrinsic types : Lowercase , Uppercase , Capitalize and Uncapitalize , all of them defined using...
Read more >JSON Naming Convention (snake_case, camelCase or ...
Intrinsic - Programming language where JSON is accessed naturally similar to accessing native objects and arrays. Extrinsic - Programming ...
Read more >Documentation - Template Literal Types - TypeScript
Generating mapping types which change properties via template literal strings.
Read more >dash-case - npm search
Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: ... A JavaScript Package For Convert a string to Different Case Styles Edit.
Read more >Case Styles: Camel, Pascal, Snake, and Kebab Case
The most popular ways to combine words into a single string ... The commonly used strategies for combining words are: camel case, pascal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, scratch that, as shown in the top description of https://github.com/microsoft/TypeScript/pull/40336, a
Split<>
doesn’t have to be intrinsic at all but is actually possible right now in the current nightly and with that comes the creation of eg.CamelCase<>
.Trick is to use
infer
within the template string literal, like:I made a test on the playground which I’m pasting here:
@grumpyTofu See these types: https://github.com/sindresorhus/type-fest#template-literal-types