File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 1010 *
1111 * @param input The string to format
1212 * @param formatArgs An object with the corresponding keys matching the ones in the string
13+ * @param placeholderPattern A pattern to search for the keys
1314 * @returns The formatted string
1415 */
1516export default function replacePlaceholder (
1617 input : string ,
17- formatArgs : Record < string , string | number >
18+ formatArgs : Record < string , string | number > ,
19+ placeholderPattern : RegExp = / (?< = (?: [ ^ \\ ] ) (?: \\ \\ ) * ) \{ \{ \s * ( \w + ) \s * } } / gm
1820) : string {
19- return input . replace ( / (?< = (?: [ ^ \\ ] ) (?: \\ \\ ) * ) \{ \{ \s * ( \w + ) \s * } } / gm , ( _ , formatKey : string ) : string => {
21+ return input . replace ( placeholderPattern , ( _ , formatKey : string ) : string => {
2022 if ( ! Object . hasOwn ( formatArgs , formatKey ) ) {
2123 throw new ReferenceError ( `Format key '${ formatKey } ' does not exist on the provided format object` ) ;
2224 }
You can’t perform that action at this time.
0 commit comments