UNPKG

topkat-utils

Version:

A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.

23 lines (22 loc) 1.34 kB
/** * Will escape all special character in a string to output a valid regexp string to put in RegExp(myString) * * Eg: from `'path.*.addr(*)'` will output `'aa\..*?\.addr\(.*?\)'` so regexp match `'path.random.addr(randomItem)'` * * Options: * * parseWildcard => config will replace '*' by '.*?' which is the best for 'match all until' * * wildcardNotMatchingChars => if provided, will replace '*' by `[^${wildcardNotMatchingChars}]` instead of '.*?'. This allows wildcard not to match certains characters */ export declare function escapeRegexp(str: string, config?: { /** will replace '*' by '.*?' which is the best for 'match all until' */ parseWildcard?: boolean; /** if provided, will replace '*' by `[^${wildcardNotMatchingChars}]` instead of '.*?'. This allows wildcard not to match certains characters */ wildcardNotMatchingChars?: string; }): string; /** Get first match of the first capturing group of regexp * Eg: const basePath = firstMatch(apiFile, /basePath = '(.*?)'/); will get what is inside quotes */ export declare function firstMatch(str: string, regExp: RegExp): string | undefined; /** Get all matches from regexp with g flag * Eg: [ [full, match1, m2], [f, m1, m2]... ] * NOTE: the G flag will be appended to regexp */ export declare function allMatches(str: string, reg: RegExp): string[];