-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { attest } from '@arktype/attest' | ||
import { expect, test } from 'vitest' | ||
|
||
import { join } from './join.js' | ||
|
||
test('default', () => { | ||
const res = join(['foo', 'bar', 'baz'], ' ') | ||
attest.instantiations([45, 'instantiations']) | ||
Check failure on line 8 in packages/abitype/src/human-readable/join.test.ts GitHub Actions / Verify / Testpackages/abitype/src/human-readable/join.test.ts > default
|
||
|
||
expect(res).toMatchInlineSnapshot(`"foo bar baz"`) | ||
attest(res).snap('foo bar baz') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type join< | ||
list extends readonly unknown[], | ||
separator extends string, | ||
> = list extends readonly [infer head, ...infer tail] | ||
? tail['length'] extends 0 | ||
? `${head & string}` | ||
: `${head & string}${separator}${join<tail, separator>}` | ||
: never | ||
|
||
export function join< | ||
const list extends readonly unknown[], | ||
separator extends string, | ||
>(list: list, separator: separator): join<list, separator> { | ||
return list.join(separator) as join<list, separator> | ||
} |