Skip to content

souvikinator/pad-even

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pad-even

simple package to pad strings evenly

Install

npm install pad-even

example:

  • without padeven
const obj = {
    'abcd': 1234,
    'def': 123,
    'verylongword': 'evenly padded'
};

for (let key in obj) {
    console.log(`${key}= ${obj[key]}`);
}

/*
output:

abcd= 1234
def= 123
verylongword= evenly padded

*/
  • with pad-even
const padeven=require('pad-even');
const obj = {
    'abcd': 1234,
    'def': 123,
    'verylongword': 'evenly padded'
};

for (let key in obj) {
    console.log(`${padeven(key,20)}= ${obj[key]}`);
}

/*
output:

abcd                = 1234
def                 = 123
verylongword        = evenly paddedd
*/

API

padeven(str,n,c)

  • str: string that needs to be padded
  • n: padding value. Use positive value for padding to the right of the string, negative value for padding to the left of the string
  • c: padding string, default is " "