Skip to content

Commit

Permalink
chore: add join
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jun 13, 2024
1 parent 9db4510 commit 9525047
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/abitype/src/human-readable/join.test.ts
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

View workflow job for this annotation

GitHub Actions / Verify / Test

packages/abitype/src/human-readable/join.test.ts > default

Error: Found no assertion data for 'packages/abitype/src/human-readable/join.test.ts' for TypeScript version typescript. ❯ node_modules/.pnpm/@arktype[email protected][email protected]/node_modules/@arktype/attest/out/cache/getCachedAssertions.js:51:19 ❯ getAssertionsOfKindAtPosition node_modules/.pnpm/@arktype[email protected][email protected]/node_modules/@arktype/attest/out/cache/getCachedAssertions.js:48:40 ❯ getBenchAssertionsAtPosition node_modules/.pnpm/@arktype[email protected][email protected]/node_modules/@arktype/attest/out/cache/getCachedAssertions.js:71:59 ❯ instantiationDataHandler node_modules/.pnpm/@arktype[email protected][email protected]/node_modules/@arktype/attest/out/bench/type.js:32:11 ❯ Function.instantiations node_modules/.pnpm/@arktype[email protected][email protected]/node_modules/@arktype/attest/out/assert/attest.js:38:9 ❯ packages/abitype/src/human-readable/join.test.ts:8:10

expect(res).toMatchInlineSnapshot(`"foo bar baz"`)
attest(res).snap('foo bar baz')
})
15 changes: 15 additions & 0 deletions packages/abitype/src/human-readable/join.ts
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>
}

0 comments on commit 9525047

Please sign in to comment.