MCPcopy Create free account
hub / github.com/formatjs/formatjs / replaceVariables

Function replaceVariables

packages/intl-segmenter/segmentation-utils.ts:1–12  ·  view source on GitHub ↗
(
  variables: Record<string, string>,
  input: string
)

Source from the content-addressed store, hash-verified

1export const replaceVariables = (
2 variables: Record<string, string>,
3 input: string
4): string => {
5 const findVarRegex = /\$[A-Za-z0-9_]+/gm
6 return input.replaceAll(findVarRegex, match => {
7 if (!(match in variables)) {
8 throw new Error(`No such variable ${match}`)
9 }
10 return variables[match]
11 })
12}
13
14export const isSurrogate = (str: string, pos: number): boolean => {
15 return (

Callers 1

generateRuleRegexFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected