(str: string, args: string[])
| 25 | }; |
| 26 | |
| 27 | function format(str: string, args: string[]) { |
| 28 | if (str == undefined) return str; |
| 29 | |
| 30 | let unkeyed_index = 0; |
| 31 | return str.replace( |
| 32 | /\{(\w*)\}/g, |
| 33 | function (match, key) { |
| 34 | if (key === "") { |
| 35 | key = unkeyed_index; |
| 36 | unkeyed_index++; |
| 37 | } |
| 38 | if (key == +key) { |
| 39 | return args[key] ?? match; |
| 40 | } |
| 41 | return "" |
| 42 | } |
| 43 | ); |
| 44 | } |
| 45 | export default _; |