UNPKG

rich-domain

Version:

This package provide utils file and interfaces to assistant build a complex application with domain driving design

29 lines 1.24 kB
/** * @description Replaces all occurrences of a specified character in a string with a given value. * The replacement is performed globally (all occurrences). * * @param target The string in which the replacements will be made. * @param char The character or substring to replace. A global regular expression will be created based on this. * @param value The value to replace the `char` with. Can be a string or a number. * * @returns A new string with all occurrences of `char` replaced by `value`. * If the inputs are not valid (e.g., `target` or `char` are not strings), the original `target` is returned unchanged. * * @example * ```typescript * // Example 1: Replace a character * const result = Replace("hello world", "o", "a"); * console.log(result); // "hella warld" * * // Example 2: Replace a substring * const result = Replace("2024-12-15", "-", "/"); * console.log(result); // "2024/12/15" * * // Example 3: Replace with a number * const result = Replace("Price: $$", "$", 100); * console.log(result); // "Price: 100100" * ``` */ export declare const Replace: (target: string, char: string, value: string | number) => string; export default Replace; //# sourceMappingURL=replace-char.util.d.ts.map