10 lines
397 B
TypeScript
10 lines
397 B
TypeScript
import type { Node } from "~/types"
|
|
import { resolvePath } from "./resolvePath"
|
|
import { childrenOf } from "./childrenOf"
|
|
|
|
/** Siblings (display order) of the node at `path` ([root] at depth 0). */
|
|
export const siblingsOf = (root: Node, path: string[]): Node[] => {
|
|
const chain = resolvePath(root, path)
|
|
if (chain.length < 2) return [chain[0]!]
|
|
return childrenOf(chain[chain.length - 2]!)
|
|
}
|