Skip to content

eush77/string-align

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-align Build Status Code Climate Dependency Status

npm

Align string with whitespace. Whitespace character defaults to ascii space.

Examples

> align('foo', 7, 'center')
'  foo  '

> align('foo', 7, 'left')
'foo    '

> align('foo', 7, 'right')
'    foo'

> align('-=', 7, 'fill')
'-=-=-=-'

> align('foo', 7, 'center', '_')
'__foo__'

> align(7, {
    width: 4,
    alignment: 'right',
    placeholder: 0
  })
'0007'

API

stringAlign(string, width, [alignment], [placeholder])

stringAlign(string, options)

If string or placeholder is not a string, it is converted to.

Option Type Required? Default
width number Yes
alignment "center", "left", "right", "fill" No "center"
placeholder string No " "

Install

npm install string-align

License

MIT

About

Align string with whitespace

Resources

License

Stars

Watchers

Forks

Packages

No packages published