|
47 | 47 |
|
48 | 48 | let formatted = format; |
49 | 49 |
|
50 | | - // Process replacements in a specific order to avoid conflicts |
51 | | - // Process longer patterns first, then shorter ones |
52 | | - const sortedKeys = Object.keys(replacements).sort((a, b) => b.length - a.length); |
53 | | - |
54 | | - for (const key of sortedKeys) { |
55 | | - const value = replacements[key]; |
56 | | - // Use a placeholder to avoid replacing already-replaced values |
57 | | - const placeholder = `__PLACEHOLDER_${key}__`; |
| 50 | + // Use a unique placeholder pattern that won't conflict with date format characters |
| 51 | + // Using Unicode characters that are unlikely to appear in format strings |
| 52 | + const placeholderPrefix = '\u{1F4C5}'; // Calendar emoji as unique marker |
| 53 | + const placeholders = {}; |
| 54 | + |
| 55 | + // First pass: replace format characters with unique placeholders |
| 56 | + for (const key in replacements) { |
| 57 | + const placeholder = placeholderPrefix + key + placeholderPrefix; |
| 58 | + placeholders[placeholder] = replacements[key]; |
58 | 59 | formatted = formatted.split(key).join(placeholder); |
59 | 60 | } |
60 | 61 |
|
61 | | - // Replace all placeholders with actual values |
62 | | - for (const key of sortedKeys) { |
63 | | - const value = replacements[key]; |
64 | | - const placeholder = `__PLACEHOLDER_${key}__`; |
65 | | - formatted = formatted.split(placeholder).join(value); |
| 62 | + // Second pass: replace placeholders with actual values |
| 63 | + for (const placeholder in placeholders) { |
| 64 | + formatted = formatted.split(placeholder).join(placeholders[placeholder]); |
66 | 65 | } |
67 | 66 |
|
68 | 67 | return formatted; |
|
0 commit comments