File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { describe , expect , it } from 'bun:test'
22
3- import { pluralize } from '../string'
3+ import { pluralize , safeReplace } from '../string'
44
55describe ( 'pluralize' , ( ) => {
66 it ( 'should handle singular and plural cases correctly' , ( ) => {
@@ -237,3 +237,16 @@ describe('pluralize', () => {
237237 } )
238238} )
239239
240+ describe ( 'safeReplace' , ( ) => {
241+ it ( 'should replace every occurrence of the search string' , ( ) => {
242+ expect ( safeReplace ( 'alpha beta alpha' , 'alpha' , 'gamma' ) ) . toBe (
243+ 'gamma beta gamma' ,
244+ )
245+ } )
246+
247+ it ( 'should treat dollar signs in replacement text literally' , ( ) => {
248+ expect ( safeReplace ( 'total: AMOUNT and AMOUNT' , 'AMOUNT' , '$& dollars' ) ) . toBe (
249+ 'total: $& dollars and $& dollars' ,
250+ )
251+ } )
252+ } )
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ export const safeReplace = (
292292 replaceStr : string ,
293293) : string => {
294294 const escapedReplaceStr = replaceStr . replace ( / \$ / g, '$$$$' )
295- return content . replace ( searchStr , escapedReplaceStr )
295+ return content . replaceAll ( searchStr , escapedReplaceStr )
296296}
297297
298298/**
You can’t perform that action at this time.
0 commit comments