obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
53 lines (52 loc) • 1.61 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for regular expressions.
*/
/**
* A strategy to use when merging multiple regex flags into one alternation.
*/
export declare enum RegExpMergeFlagsConflictStrategy {
/**
* Keep only the flags present in all regexes.
*/
Intersect = "Intersect",
/**
* Throw an error if the regexes have conflicting flags.
*/
Throw = "Throw",
/**
* Keep only the flags present in any regex.
*/
Union = "Union"
}
/**
* Escapes special characters in a string to safely use it within a regular expression.
*
* @param str - The string to escape.
* @returns The escaped string with special characters prefixed with a backslash.
*/
export declare function escapeRegExp(str: string): string;
/**
* Checks if a string is a valid regular expression.
*
* @param str - The string to check.
* @returns `true` if the string is a valid regular expression, `false` otherwise.
*/
export declare function isValidRegExp(str: string): boolean;
/**
* A regular expression that always matches.
*/
export declare const ALWAYS_MATCH_REG_EXP: RegExp;
/**
* A regular expression that never matches.
*/
export declare const NEVER_MATCH_REG_EXP: RegExp;
/**
* Combine multiple regexes into one alternation, handling flags.
*
* @param regExps - The regexes to combine.
* @param strategy - The strategy to use when merging flags (default: `RegExpMergeFlagsConflictStrategy.Throw`).
* @returns The combined regex.
*/
export declare function oneOf(regExps: RegExp[], strategy?: RegExpMergeFlagsConflictStrategy): RegExp;