UNPKG

@handy-common-utils/misc-utils

Version:
17 lines 1.45 kB
/** * Substitute all occurrences of a pattern in a string. * @param input The input string on which the substitutions will be performed. * @param searchPattern The regular expression pattern used to search for segments that should be substituted. * It must have the `g` flag set. * If the beginning part of the `input` should be skipped, set the `lastIndex` of the `searchPattern` before calling this function. * After all the substitution are done, the `lastIndex` of the `searchPattern` will be reset to zero. * See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex} * @param substitute TThe function that builds the substitution string. * It is called with the matched substring and the result of `RegExp.exec()`. * See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#examples}. * The function can return null to indicate that no further substitution is desired. * In such case, the `lastIndex` of the `searchPattern` will not be reset to zero. * @returns The resulting string after performing all substitutions. */ export declare function substituteAll<T extends string | null | undefined>(input: T, searchPattern: RegExp, substitute: (match: string, matchResult: NonNullable<ReturnType<RegExp['exec']>>) => string | null): T; //# sourceMappingURL=substitute.d.ts.map