import $ from 'jquery'

export class DomQueryPreset {
    eq = (target: number | string | RegExp) => {
        return (index: number, element: HTMLElement) => {
            if (typeof target === 'number') {
                target = String(target)
            }

            const content = $(element).text().trim()
            if (typeof target !== 'string') {
                return target.test(content)
            }
            return content === target
        }
    }

    incl = (target: number | string | RegExp) => {
        return (index: number, element: HTMLElement) => {
            if (typeof target === 'number') {
                target = String(target)
            }

            const content = $(element).text().trim()

            if (typeof target !== 'string') {
                return target.test(content)
            }

            return content.includes(target)
        }
    }
}
