ts-commons
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -265,3 +265,14 @@ export declare class StringUtils { | ||
static replaceAll(str: string, searchValue: string, replacer: string): string; | ||
/** | ||
* Joins the elements of the provided array into a single String | ||
* @param array the array of values to join together, may be null | ||
* @param separator the separator character to use, null treated as "" | ||
* @returns the joined String | ||
* @example StringUtils.join([], *) = ""; | ||
* @example StringUtils.join(["a", "b", "c"], null) = "abc" | ||
* @example StringUtils.join(["a", "b", "c"], "-") = "a-b-c" | ||
* @example StringUtils.join([1, 2, 3], "-") = "1-2-3" | ||
*/ | ||
static join<T>(array: T[], separator?: string): string; | ||
private static escapeRegExp; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StringUtils = void 0; | ||
var array_utils_1 = require("./array.utils"); | ||
var number_utils_1 = require("./number.utils"); | ||
@@ -484,2 +485,30 @@ var object_utils_1 = require("./object.utils"); | ||
}; | ||
/** | ||
* Joins the elements of the provided array into a single String | ||
* @param array the array of values to join together, may be null | ||
* @param separator the separator character to use, null treated as "" | ||
* @returns the joined String | ||
* @example StringUtils.join([], *) = ""; | ||
* @example StringUtils.join(["a", "b", "c"], null) = "abc" | ||
* @example StringUtils.join(["a", "b", "c"], "-") = "a-b-c" | ||
* @example StringUtils.join([1, 2, 3], "-") = "1-2-3" | ||
*/ | ||
StringUtils.join = function (array, separator) { | ||
if (separator === void 0) { separator = ""; } | ||
if (array_utils_1.ArrayUtils.isEmpty(array)) { | ||
return ""; | ||
} | ||
var useSeparator = this.isEmpty(separator) ? "" : separator; | ||
var result; | ||
for (var index = 0; index < array.length; index++) { | ||
var element = array[index] + ""; | ||
if (index === 0) { | ||
result = element; | ||
} | ||
else { | ||
result = result + useSeparator + element; | ||
} | ||
} | ||
return result; | ||
}; | ||
StringUtils.escapeRegExp = function (str) { | ||
@@ -486,0 +515,0 @@ return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); |
{ | ||
"name": "ts-commons", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"description": "common methods for typescript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
215856
2203