···1-import assert from 'node:assert'
2import { describe, test } from 'node:test'
3import { type TreeInput, treeify } from './index.js'
4
···1+import assert from 'node:assert/strict'
2import { describe, test } from 'node:test'
3import { type TreeInput, treeify } from './index.js'
4
+1-1
src/index.ts
···8 * The strict tree input format. Must start with a string.
9 * This type is exported for testing purposes and advanced usage.
10 */
11-export type TreeInput = [string, ...Array<string | TreeNode[]>]
1213/**
14 * Flexible input type that accepts any array.
···8 * The strict tree input format. Must start with a string.
9 * This type is exported for testing purposes and advanced usage.
10 */
11+export type TreeInput = [string, ...Array<string | TreeNode[]>] | string[]
1213/**
14 * Flexible input type that accepts any array.
+32
src/types.test.ts
···00000000000000000000000000000000
···1+import assert from 'node:assert/strict'
2+import { describe, test } from 'node:test'
3+import { treeify } from './index.js'
4+import type { TreeInput } from './index.js'
5+6+describe('treeify types', () => {
7+ test('input with values', () => {
8+ const inputWithValues: TreeInput = ['root', ['child1', 'child2', 'child3']]
9+ let result = treeify(inputWithValues)
10+ assert.ok(result)
11+12+ const inputWithoutValues: TreeInput = []
13+ result = treeify(inputWithoutValues)
14+ assert.equal(result, '') // empty string
15+16+ // @ts-expect-error
17+ const inputWithoutRootString: TreeInput = [{ bad: 'root' }, 'root2']
18+ assert.throws(() => treeify(inputWithoutRootString), {
19+ message: 'First element must be a string',
20+ })
21+22+ // @ts-expect-error
23+ const inputWithRootStringAndInvalidValues: TreeInput = [
24+ 'root',
25+ 1,
26+ {},
27+ ['child1', 'child2', 'child3'],
28+ ]
29+ result = treeify(inputWithRootStringAndInvalidValues)
30+ assert.ok(result) // non-strings are ignored
31+ })
32+})