2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 format(variables:Array<string>):string
31 * This function will replace the %<number> with strings (from array).
32 * Example: "Requested '%1' resource was not found.".format(["MyResource"]);
33 * Note: in case the array contains empty string the function will also remove the '' or the "".
35 if (!String.hasOwnProperty("format")) {
36 String.prototype["format"] = function (variables:Array<string>):string {
38 if (variables === null || variables === undefined || variables.length === 0) {
42 for (let i = 0; i < variables.length; i++) {
43 if (variables[i] === '' || variables[i] === null) {
44 variables[i] = '--DELETE--';
48 let res = this.replace(/%(\d+)/g, function (_, m) {
49 return variables[--m];
52 res = res.replace(" '--DELETE--' ", " ");
53 res = res.replace(" \"--DELETE--\" ", " ");
54 res = res.replace("'--DELETE--'", "");
55 res = res.replace("\"--DELETE--\"", "");
56 res = res.replace("--DELETE--", "");
62 if (!String.hasOwnProperty("capitalizeFirstLetter")) {
63 String.prototype["capitalizeFirstLetter"] = function () {
64 return this.charAt(0).toUpperCase() + this.slice(1);
68 if (!String.hasOwnProperty("replaceAll")) {
69 String.prototype["replaceAll"] = function (find:string, replace:string):string {
70 return this.replace(new RegExp(find, 'g'), replace);
74 if (!Array.hasOwnProperty("clean")) {
75 Array.prototype.clean = function (deleteValue) {
76 for (let i = 0; i < this.length; i++) {
77 if (this[i] == deleteValue) {