@adguard/agtree
Version:
Tool set for working with adblock filter lists
48 lines (47 loc) • 1.58 kB
TypeScript
/**
* @file Conversion result interface and helper functions.
*/
import { type Node } from '../../nodes/index.js';
/**
* Common conversion result interface.
*
* @template T Type of the item to convert.
* @template U Type of the conversion result (defaults to `T`, but can be `T[]` as well).
*/
export interface ConversionResult<T, U extends T | T[] = T> {
/**
* Conversion result.
*/
result: U;
/**
* Indicates whether the input item was converted.
*/
isConverted: boolean;
}
/**
* Adblock rule node conversion result interface, where the conversion result is an array of rules.
*/
export type NodeConversionResult<T extends Node> = ConversionResult<T, T[]>;
/**
* Helper function to create a generic conversion result.
*
* @template T Type of the item to convert.
* @template U Type of the conversion result (defaults to `T`, but can be `T[]` as well).
*
* @param result Conversion result.
* @param isConverted Indicates whether the input item was converted.
*
* @returns Generic conversion result.
*/
export declare function createConversionResult<T, U extends T | T[] = T>(result: U, isConverted: boolean): ConversionResult<T, U>;
/**
* Helper function to create a node conversion result.
*
* @template T Type of the node (extends `Node`).
*
* @param nodes Array of nodes.
* @param isConverted Indicates whether the input item was converted.
*
* @returns Node conversion result.
*/
export declare function createNodeConversionResult<T extends Node>(nodes: T[], isConverted: boolean): NodeConversionResult<T>;