import { Node, NodeEntry } from 'slate'; export interface IsNodeMatchOptions { filter?: (entry: NodeEntry) => boolean; /** * List of types that are valid. * If empty or undefined - allow all. */ includeTypes?: string[]; /** * List of types that are invalid. */ excludeTypes?: string[]; } export function isNodeMatch( entry: NodeEntry, { filter, includeTypes = [], excludeTypes = [] }: IsNodeMatchOptions = {} ): boolean { const [node] = entry; return ( (!filter || filter(entry)) && (!includeTypes.length || includeTypes.includes(node.type as string)) && !(excludeTypes.length && excludeTypes.includes(node.type as string)) ); }