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

refactor: uses Join for other rules #418

Merged
merged 7 commits into from
Dec 14, 2024

Conversation

hugop95
Copy link
Contributor

@hugop95 hugop95 commented Dec 13, 2024

Changes

What is the purpose of this pull request?

  • Other

@hugop95 hugop95 force-pushed the refactor/rule-types branch 3 times, most recently from 65d08bd to 884c4a7 Compare December 13, 2024 11:20
@hugop95 hugop95 force-pushed the refactor/rule-types branch from 884c4a7 to e7046d2 Compare December 13, 2024 11:23
@hugop95 hugop95 marked this pull request as ready for review December 13, 2024 11:23
Comment on lines 1 to 10
export type JoinWithDash<T extends string[]> = T extends [
infer First extends string,
...infer Rest extends string[],
]
? Rest extends []
? `${First}`
: `${WithDashSuffixOrEmpty<First>}${JoinWithDash<Rest>}`
: never

type WithDashSuffixOrEmpty<T extends string> = `${T}-` | ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I have an idea. Maybe it makes sense to add a second Separator parameter?

export type Join<
  T extends string[],
  Separator extends string = '',
> = T extends [infer First extends string, ...infer Rest extends string[]]
  ? `${First}${Rest['length'] extends 0 ? '' : `${Separator}${Join<Rest, Separator>}`}`
  : ''

export type JoinWithDash<T extends string[]> = Join<T, '-'>

Copy link
Contributor Author

@hugop95 hugop95 Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azat-io 👍 Improved in a255406.

Your version accepts the separator at the end, so I kept the current one:
image

@azat-io azat-io merged commit 7fdadd7 into azat-io:main Dec 14, 2024
8 checks passed
@hugop95 hugop95 deleted the refactor/rule-types branch December 14, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants