Made pad function a little easier to use
This commit is contained in:
parent
cf9bdca2ba
commit
d4bd054953
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/js-utilities",
|
||||
"version": "0.3.3",
|
||||
"version": "0.3.4",
|
||||
"description": "JavaScript Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -52,11 +52,12 @@ export function insertAt(target: string, str: string, index: number): String {
|
||||
return `${target.slice(0, index)}${str}${target.slice(index + 1)}`;
|
||||
}
|
||||
|
||||
export function pad(text: string, length: number, char: string, start = true) {
|
||||
const l = length - text.length;
|
||||
if(l <= 0) return text;
|
||||
export function pad(text: any, length: number, char: string, start = true) {
|
||||
const t = text.toString();
|
||||
const l = length - t.length;
|
||||
if(l <= 0) return t;
|
||||
const padding = Array(~~(l / char.length)).fill(char).join('');
|
||||
return start ? padding + text : text + padding;
|
||||
return start ? padding + t : t + padding;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user