Skip to content

Commit

Permalink
feat: add concat
Browse files Browse the repository at this point in the history
  • Loading branch information
jly36963 committed Oct 4, 2023
1 parent 2cf8123 commit 4fa1cf2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/primitives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace TypeTests {
Equal<Subject.Split<'some nice string', ' '>, ['some', 'nice', 'string']>
>
type test8 = Expect<Equal<Subject.CharAt<'some nice string', 5>, 'n'>>

type test9 = Expect<
Equal<
Subject.Concat<['a', 'bc', 'def'] | ['1', '23', '456']>,
'abcdef' | '123456'
>
>
}

describe('primitives', () => {
Expand Down
19 changes: 18 additions & 1 deletion src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function charAt<T extends string, I extends number>(
return str.charAt(index)
}

type Concat<T extends string[]> = Join<T, ''>

function concat<T extends string[]>(...strings: T): Concat<T> {
return strings.join('') as Concat<T>
}

/**
* Joins a tuple of strings with the given delimiter.
* T: The tuple of strings to join.
Expand Down Expand Up @@ -193,6 +199,7 @@ function trim<T extends string>(str: T) {

export type {
CharAt,
Concat,
Join,
Replace,
ReplaceAll,
Expand All @@ -201,4 +208,14 @@ export type {
TrimEnd,
Trim,
}
export { charAt, join, replace, replaceAll, split, trim, trimStart, trimEnd }
export {
charAt,
concat,
join,
replace,
replaceAll,
split,
trim,
trimStart,
trimEnd,
}

0 comments on commit 4fa1cf2

Please sign in to comment.