UNPKG

@adguard/agtree

Version:
95 lines (94 loc) 2.77 kB
/** * @file Utility functions for working with quotes */ /** * Set of all possible quote characters supported by the library */ export declare const QUOTE_SET: Set<string>; /** * Possible quote types for scriptlet parameters */ export declare const QuoteType: { /** * No quotes at all */ readonly None: "none"; /** * Single quotes (`'`) */ readonly Single: "single"; /** * Double quotes (`"`) */ readonly Double: "double"; /** * Backtick quotes (`` ` ``) */ readonly Backtick: "backtick"; }; export type QuoteType = typeof QuoteType[keyof typeof QuoteType]; /** * Utility functions for working with quotes */ export declare class QuoteUtils { /** * Escape all unescaped occurrences of the character * * @param string String to escape * @param char Character to escape * @returns Escaped string */ static escapeUnescapedOccurrences(string: string, char: string): string; /** * Unescape all single escaped occurrences of the character * * @param string String to unescape * @param char Character to unescape * @returns Unescaped string */ static unescapeSingleEscapedOccurrences(string: string, char: string): string; /** * Get quote type of the string * * @param string String to check * @returns Quote type of the string */ static getStringQuoteType(string: string): QuoteType; /** * Set quote type of the string * * @param string String to set quote type of * @param quoteType Quote type to set * @returns String with the specified quote type */ static setStringQuoteType(string: string, quoteType: QuoteType): string; /** * Removes bounding quotes from a string, if any * * @param string Input string * @returns String without quotes */ static removeQuotes(string: string): string; /** * Removes bounding quotes from a string, if any, and unescapes the escaped quotes, * like transforming `'abc\'def'` to `abc'def`. * * @param string Input string * @returns String without quotes */ static removeQuotesAndUnescape(string: string): string; /** * Wraps given `strings` with `quote` (defaults to single quote `'`) * and joins them with `separator` (defaults to comma+space `, `). * * @param strings Strings to quote and join. * @param quoteType Quote to use. * @param separator Separator to use. * * @returns String with joined items. * * @example * ['abc', 'def']: strings[] -> "'abc', 'def'": string */ static quoteAndJoinStrings(strings: string[], quoteType?: QuoteType, separator?: string): string; }