/** * @since 0.0.1 */ import type { Option } from 'fp-ts/Option' import * as O from 'fp-ts/Option' import * as F from 'fp-ts/function' import type { TagSpec } from './Internal/Tag/TagSpec' import * as T from './Internal/Html/Tokenizer' /** * Represents a selection of an HTML DOM tree to be operated upon by a web * `Scraper`. The selection includes the opening tag that matches the selection, * all of the inner tags, and the corresponding closing tag (if any). * * @category model * @since 0.0.1 */ export declare type Selector = ReadonlyArray /** * Represents the strategy used for the selection of an HTML DOM tree to be * operated on by a `Scraper` in addition to settings associated with the * `Selection`. * * @category model * @since 0.0.1 */ export interface Selection { readonly strategy: SelectStrategy readonly settings: SelectSettings } /** * Represents the strategy used for selection of an HTML DOM tree to be * operated on by a `Scraper`. * * @category model * @since 0.0.1 */ export declare type SelectStrategy = SelectOne | SelectAny | SelectText /** * Represents selection of an HTML DOM tree based upon a specific tag * and an optional list of `AttributePredicate` * * @category model * @since 0.0.1 */ export interface SelectOne { readonly _tag: 'SelectOne' readonly tag: string readonly predicates: ReadonlyArray } /** * Represents selection of any node within the HTML DOM tree (including * tags and bare text) which can be narrowed down by specifying a list * of `AttributePredicate`s that must also match a given node. * * @category model * @since 0.0.1 */ export interface SelectAny { readonly _tag: 'SelectAny' readonly predicates: ReadonlyArray } /** * Represents selection of all text nodes within the HTML DOM tree. * * @category model * @since 0.0.1 */ export interface SelectText { readonly _tag: 'SelectText' } /** * Represents a method that takes a `Token` and returns a boolean indicating if * the attributes of an HTML tag match a specified predicate. * * @category model * @since 0.0.1 */ export declare type AttributePredicate = F.Predicate> /** * Represents additional criteria for a `Selector` that must be satisfied in * addition to the `SelectNode`. This includes criteria that are dependent on * the context of the current node (e.g. the depth in relation to the previously * matched `SelectNode`). * * @category model * @since 0.0.1 */ export interface SelectSettings { /** * The required depth of the current `SelectNode` in relation to the previously * matched `SelectNode`. */ readonly depth: O.Option } /** * Represents the ephemeral metadata that each `TagSpec` contains, which has * information that is not instrinsic in the subtree that corresponds with a * given `TagSpec`. * * @category model * @since 0.0.1 */ export interface SelectContext { readonly position: number readonly inChroot: boolean } /** * @category constructors * @since 0.0.1 */ export declare const Selection: (strategy: SelectStrategy, settings: SelectSettings) => Selection /** * @category constructors * @since 0.0.1 */ export declare const SelectOne: ( tag: string, predicates: ReadonlyArray ) => SelectStrategy /** * @category constructors * @since 0.0.1 */ export declare const SelectAny: (predicates: ReadonlyArray) => SelectStrategy /** * @category constructors * @since 0.0.1 */ export declare const SelectText: SelectStrategy /** * @category constructors * @since 0.0.1 */ export declare const SelectSettings: (depth: O.Option) => SelectSettings /** * @category constructors * @since 0.0.1 */ export declare const defaultSelectSettings: SelectSettings /** * @category constructors * @since 0.0.1 */ export declare const SelectContext: (position: number, inChroot: boolean) => SelectContext /** * @category destructors * @since 0.0.1 */ export declare const foldStrategy: (patterns: { readonly SelectOne: (tag: string, predicates: ReadonlyArray) => R readonly SelectAny: (predicates: ReadonlyArray) => R readonly SelectText: () => R }) => (selectNode: SelectStrategy) => R /** * The `tag` combinator creates a `Selector` that will match a tag with the * specified `name`. * * @category constructors * @since 0.0.1 */ export declare const tag: (name: string) => Selector /** * The `any` combinator creates a `Selector` that will match any node (including * tags and bare text). * * @category constructors * @since 0.0.1 */ export declare const any: Selector /** * The `text` combinator creates a `Selector` that will match all text nodes. * * @category constructors * @since 0.0.1 */ export declare const text: Selector /** * The `withAttributes` combinator creates a `Selector` by combining a tag name * with a list of `AttributePredicate` The resulting `Selector` will match if * the tags with the specified `name` and that satisfy all of the specified * `AttributePredicates`. * * @category combinators * @since 0.0.1 */ export declare const withAttributes: ( name: string, predicates: ReadonlyArray ) => Selector /** * The `anyWithAttributes` combinator creates a `Selector` that takes a list of * `AttributePredicate`s and will match any tags that satisfy all of the specified * `AttributePredicates`. * * @category combinators * @since 0.0.1 */ export declare const anyWithAttributes: (predicates: ReadonlyArray) => Selector /** * The `attribute` combinator creates an `AttributePredicate` that will match * attributes with the specified `key` and `value`. * * If attempting to match a specific class of a tag with potentially multiple classes, * use `hasClass` instead. * * @category combinators * @since 0.0.1 */ export declare const attribute: (key: string, value: string) => AttributePredicate /** * The `anyAttribute` combinator creates an `AttributePredicate` that will match * any attributes with the specified `value`. * * If attempting to match a specific class of a tag with potentially multiple classes, * use `hasClass` instead. * * @category combinators * @since 0.0.1 */ export declare const anyAttribute: (value: string) => AttributePredicate /** * The `attributeRegex` combinator creates an `AttributePredicate` that will * match attributes with the specified `key` and whose value matches the * given `RegExp`. * * @category combinators * @since 0.0.1 */ export declare const attributeRegex: (key: string, regex: RegExp) => AttributePredicate /** * The `attributeRegex` combinator creates an `AttributePredicate` that will * match any attributes whose value matches the given `RegExp`. * * @category combinators * @since 0.0.1 */ export declare const anyAttributeRegex: (regex: RegExp) => AttributePredicate /** * The `atDepth` combinator constrains a `Selector` to only match when it is * at a `depth` below the previous selector. * * In the example below, a `Selector` is created that matches anchor tags that * are direct children of a div tag. * * ```typescript * pipe(tag('div'), nested(tag('a')), atDepth(1)) * ``` * * @category combinators * @since 0.0.1 */ export declare const atDepth: (depth: number) => (selector: Selector) => Selector /** * The `nested` combinator creates a `Selector` by nesting the `child` selector * under the `parent` selector`. * * In the example below, a `Selector` is created that matches anchor tags nested * arbitrarily deep within a div tag. * * ```typescript * pipe(tag('div'), nested(tag('a'))) * ``` * * @category combinators * @since 0.0.1 */ export declare const nested: (parent: Selector) => (child: Selector) => Selector /** * The classes of an HTML tag are definied as a space-separated list of characters * in a string designated by the `class` attribute. The `hasClass` combinator * creates an `AttributePredicate` that will match a `class` attribute if the * specified `className` appears anywhere in the space-separated list of classe * * @category combinators * @since 0.0.1 */ export declare const hasClass: (className: string) => AttributePredicate /** * Negates the result of an `AttributePredicate`. * * @category combinators * @since 0.0.1 */ export declare const notP: F.Endomorphism /** * The `match` combinator allows for the creation of arbitrary `AttributePredicate` * The argument is a function that takes an attribute's key and value and returns * a boolean indicating if the attribute satisfies the predicate. * * @category combinators * @since 0.0.1 */ export declare const match: (f: (key: string, value: string) => boolean) => AttributePredicate /** * @category selectors * @since 0.0.1 */ export declare const select: (selector: Selector) => (spec: TagSpec) => ReadonlyArray