2021-06-02 01:59:40 +00:00
|
|
|
/**
|
|
|
|
* If `string` is less than `length` characters long, add however many `padWith` characters
|
|
|
|
* are necessary to make up the difference to the END of the string.
|
|
|
|
* @param string
|
|
|
|
* @param length
|
|
|
|
* @param padWith
|
|
|
|
*/
|
2021-06-03 03:36:25 +00:00
|
|
|
export function padRight(string: string, length: number, padWith = ' '): string {
|
2021-06-02 01:59:40 +00:00
|
|
|
while ( string.length < length ) {
|
|
|
|
string += padWith
|
|
|
|
}
|
|
|
|
|
|
|
|
return string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If `string` is less than `length` characters long, add however many `padWith` characters
|
|
|
|
* are necessary to make up the difference to the BEGINNING of the string.
|
|
|
|
* @param string
|
|
|
|
* @param length
|
|
|
|
* @param padWith
|
|
|
|
*/
|
2021-06-03 03:36:25 +00:00
|
|
|
export function padLeft(string: string, length: number, padWith = ' '): string {
|
2021-06-02 01:59:40 +00:00
|
|
|
while ( string.length < length ) {
|
|
|
|
string = `${padWith}${string}`
|
|
|
|
}
|
|
|
|
|
|
|
|
return string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If `string` is less than `length` characters long, add however many `padWith` characters
|
|
|
|
* are necessary to make up the difference evenly split between the beginning and end of the string.
|
|
|
|
* @param string
|
|
|
|
* @param length
|
|
|
|
* @param padWith
|
|
|
|
*/
|
2021-06-03 03:36:25 +00:00
|
|
|
export function padCenter(string: string, length: number, padWith = ' '): string {
|
|
|
|
const bit = false
|
2021-06-02 01:59:40 +00:00
|
|
|
while ( string.length < length ) {
|
|
|
|
if ( bit ) {
|
|
|
|
string = `${padWith}${string}`
|
|
|
|
} else {
|
|
|
|
string += padWith
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return string
|
|
|
|
}
|
2021-07-25 14:15:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a string to PascalCase.
|
|
|
|
* @param input
|
|
|
|
*/
|
|
|
|
export function stringToPascal(input: string): string {
|
|
|
|
return input.split(/[\s_]+/i)
|
|
|
|
.map(part => {
|
|
|
|
return part[0].toUpperCase() + part.substr(1)
|
|
|
|
})
|
|
|
|
.join('')
|
|
|
|
.split(/\W+/i)
|
|
|
|
.join('')
|
|
|
|
}
|