UNPKG

@adguard/agtree

Version:
53 lines (52 loc) 1.98 kB
/** * @file Utility functions for working with scriptlet nodes */ import { type ParameterList } from '../nodes/index.js'; import { type QuoteType } from '../utils/quotes.js'; /** * Function to transform a parameter of the scriptlet node. * * @param param Parameter to transform or null if the parameter is not present. * * @returns Transformed parameter or null if the parameter should be removed. */ type ParamTransformer = (param: string | null) => string | null; /** * Get name of the scriptlet from the scriptlet node * * @param scriptletNode Scriptlet node to get name of * @returns Name of the scriptlet * @throws If the scriptlet is empty */ export declare function getScriptletName(scriptletNode: ParameterList): string; /** * Transform the nth argument of the scriptlet node * * @param scriptletNode Scriptlet node to transform argument of * @param index Index of the argument to transform (index 0 is the scriptlet name) * @param transform Function to transform the argument */ export declare function transformNthScriptletArgument(scriptletNode: ParameterList, index: number, transform: ParamTransformer): void; /** * Transform all arguments of the scriptlet node * * @param scriptletNode Scriptlet node to transform arguments of * @param transform Function to transform the arguments */ export declare function transformAllScriptletArguments(scriptletNode: ParameterList, transform: ParamTransformer): void; /** * Set name of the scriptlet. * Modifies input `scriptletNode` if needed. * * @param scriptletNode Scriptlet node to set name of * @param name Name to set */ export declare function setScriptletName(scriptletNode: ParameterList, name: string): void; /** * Set quote type of the scriptlet parameters * * @param scriptletNode Scriptlet node to set quote type of * @param quoteType Preferred quote type */ export declare function setScriptletQuoteType(scriptletNode: ParameterList, quoteType: QuoteType): void; export {};