UNPKG

701 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getInterpolatedString;
7
8/*
9Copyright (c) 2018-2020 Uber Technologies, Inc.
10
11This source code is licensed under the MIT license found in the
12LICENSE file in the root directory of this source tree.
13*/
14// Example:
15// getInterpolatedString('Selected date is ${date}', 'Jan 1, 2020') => 'Selected date is Jan 1, 2020'
16function getInterpolatedString(translation) {
17 var interpolations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18 return translation.replace(/\${(.*?)}/g, function (_, k) {
19 return interpolations[k] === undefined ? '${' + k + '}' : interpolations[k];
20 });
21}
\No newline at end of file