···11-import assert from 'node:assert'
11+import assert from 'node:assert/strict'
22import { describe, test } from 'node:test'
33import { type TreeInput, treeify } from './index.js'
44
+1-1
src/index.ts
···88 * The strict tree input format. Must start with a string.
99 * This type is exported for testing purposes and advanced usage.
1010 */
1111-export type TreeInput = [string, ...Array<string | TreeNode[]>]
1111+export type TreeInput = [string, ...Array<string | TreeNode[]>] | string[]
12121313/**
1414 * Flexible input type that accepts any array.
+32
src/types.test.ts
···11+import assert from 'node:assert/strict'
22+import { describe, test } from 'node:test'
33+import { treeify } from './index.js'
44+import type { TreeInput } from './index.js'
55+66+describe('treeify types', () => {
77+ test('input with values', () => {
88+ const inputWithValues: TreeInput = ['root', ['child1', 'child2', 'child3']]
99+ let result = treeify(inputWithValues)
1010+ assert.ok(result)
1111+1212+ const inputWithoutValues: TreeInput = []
1313+ result = treeify(inputWithoutValues)
1414+ assert.equal(result, '') // empty string
1515+1616+ // @ts-expect-error
1717+ const inputWithoutRootString: TreeInput = [{ bad: 'root' }, 'root2']
1818+ assert.throws(() => treeify(inputWithoutRootString), {
1919+ message: 'First element must be a string',
2020+ })
2121+2222+ // @ts-expect-error
2323+ const inputWithRootStringAndInvalidValues: TreeInput = [
2424+ 'root',
2525+ 1,
2626+ {},
2727+ ['child1', 'child2', 'child3'],
2828+ ]
2929+ result = treeify(inputWithRootStringAndInvalidValues)
3030+ assert.ok(result) // non-strings are ignored
3131+ })
3232+})