Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New String methods for TS 4.1+ #162

Closed
mikeplus64 opened this issue Dec 8, 2020 · 3 comments
Closed

New String methods for TS 4.1+ #162

mikeplus64 opened this issue Dec 8, 2020 · 3 comments
Labels
feature Add new features
Projects

Comments

@mikeplus64
Copy link

mikeplus64 commented Dec 8, 2020

Now that string templating is possible it's possible to build your own type-level parsers and formatters. Here's what I'd suggest as a start:

type Intersperse<L extends List<string|number|bigint>, Sep extends string|number|bigint> = ...

type Split<L extends List<string|number|bigint>, Sep extends string|number|bigint> = ...

type Concat<L extends List<string|number|bigint> = ...

type StartsWith<S extends string, Prefix extends string> = ...

type EndsWith<S extends string, Suffix extends string> = ...

Motivation

Writing a type-safe routing library, these are utility types that I've mostly already defined.

@millsp millsp added the feature Add new features label Dec 8, 2020
@millsp
Copy link
Owner

millsp commented Dec 8, 2020

Hey @mikeplus64, thanks! We should definitely add this. Would you like to open a PR?

@mikeplus64
Copy link
Author

Yep can do next week some time.

@ghost
Copy link

ghost commented Dec 28, 2020

Hi guys,

would you consider support of object keys case transformation to *Case types (like SnakeCase, CamelCase, DashCase etc.)?

Another library called type-fest already supports these types. Also, here is trivial implementation of SnakeCase to CamelCase scenario, although I am not qualified to check correctness of the implementation, which seems to be surprisingly simple.

There are many use cases for this kind of feature, for example when handling difference of object keys case between front-end and back-end apps, where you usually struggling with camel-case to snake-case transformations and vice versa in request/response payloads.

By the way, I was wondering if there is library which transforms object keys case at runtime and I found this one - change-case. Although I didn't use it yet, it may offers a simple solution to described problem in combinations with proposed *Case types.

@millsp millsp added this to To do in Board via automation Jan 29, 2021
@millsp millsp moved this from To do to Done in Board Jan 30, 2021
@millsp millsp closed this as completed Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Add new features
Projects
Board
  
Done
Development

No branches or pull requests

2 participants