2020-11-06 08:10:30 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-11-06 08:54:30
|
|
|
|
* @modify date 2020-11-06 08:54:31
|
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
2020-08-25 08:21:55 +00:00
|
|
|
/**
|
|
|
|
* Replaces all Chars in a String
|
|
|
|
* @param str base string
|
|
|
|
* @param value the value which should be replaced
|
|
|
|
* @param replacement the value which is used as replacement
|
|
|
|
*/
|
|
|
|
export function replaceAll(str: string, value: string, replacement: string): string {
|
|
|
|
return str.split(value).join(replacement);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to Pad a String.
|
|
|
|
* @param num
|
|
|
|
* @param size
|
|
|
|
* @param maxLength
|
|
|
|
*/
|
|
|
|
export function padString(num: number, size: number, maxLength = false) {
|
|
|
|
|
|
|
|
let _size = size;
|
|
|
|
if (typeof maxLength === 'boolean' && maxLength) {
|
|
|
|
_size = Math.ceil(Math.log10(size));
|
|
|
|
}
|
|
|
|
|
|
|
|
let s = num + "";
|
|
|
|
while (s.length < _size) s = "0" + s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a String in the String
|
|
|
|
* @param str base string
|
|
|
|
* @param index index where the content should be inserted
|
|
|
|
* @param content the content to insert
|
|
|
|
*/
|
|
|
|
export function insert(str: string, index: number, content: string): string {
|
|
|
|
if (index > 0) {
|
|
|
|
return str.substring(0, index) + content + str.substring(index, str.length);
|
|
|
|
} else {
|
|
|
|
return content + str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to Camelize a String
|
|
|
|
* @param str The String,
|
|
|
|
* @param char A, used to determine "new words"
|
|
|
|
*/
|
|
|
|
export function camelize(str: string, char = '_') {
|
|
|
|
return replaceAll(str, char, ' ').replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
|
|
return index == 0 ? word.toLowerCase() : word.toUpperCase();
|
|
|
|
}).replace(/\s+/g, '');
|
|
|
|
}
|