/** * @file Match * @module unist-util-types/Match */ import type { Node } from 'unist' import type Test from './test' import type Type from './type' /** * Check if node `N` passes `Check`. * * > **Note**: Does not handle checks that are arrays. * * @internal * * @see {@linkcode Node} * @see {@linkcode Test} * * @template {Node} [N=Node] - Node to check * @template {Test} [Check=Test] - Node test */ type MatchOne = // dprint-ignore Check extends null | undefined ? N : N extends { type: Check } ? N : N extends Check ? N : Check extends Type ? N : Check extends (...args: any[]) => any ? Check extends (value: any) => value is infer U ? U extends N ? U : never : N : never /** * Check if node `N` passes a test. * * @see {@linkcode Node} * @see {@linkcode Test} * * @example * type X = Match * // docast.BlockTag | docast.InlineTag * @example * type X = Match * // mdast.Break * @example * type X = Match v is docast.Comment> * // docast.Comment * @example * type X = Match * // mdast.Code * @example * type X = Match * // docast.DocastNode * @example * type X = Match * // mdast.Nodes * * @template {Node} [N=Node] - Node to check * @template {Test} [Check=Test] - Node test */ type Match = Check extends any[] ? MatchOne : MatchOne export type { Match as default }