UNPKG

@clayui/shared

Version:

ClayShared component

30 lines (27 loc) 772 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sub = void 0; /** * SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com> * SPDX-License-Identifier: BSD-3-Clause */ const SPLIT_REGEX = /({\d+})/g; /** * Utility function for substituting variables into language keys. */ const sub = (langKey, args) => { const keyArray = langKey.split(SPLIT_REGEX).filter(val => val.length !== 0); for (let i = 0; i < args.length; i++) { const arg = args[i]; const indexKey = `{${i}}`; let argIndex = keyArray.indexOf(indexKey); while (argIndex >= 0) { keyArray.splice(argIndex, 1, arg.toString()); argIndex = keyArray.indexOf(indexKey); } } return keyArray.join(''); }; exports.sub = sub;