Skip to content

TopCli/text-align

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

text-align

version Maintenance mit OpenSSF Scorecard build

A wide-character aware text alignment function for use in terminals / on the console. This package is a modern implementation of wide-align with String.prototype.padLeft and String.prototype.padRight.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @topcli/text-align
# or
$ yarn add @topcli/text-align

Usage example

import * as align from "@topcli/text-align";

console.log(align.center('abc', 10));     // '   abc    '
console.log(align.center('叀叀叀', 10));   // '  叀叀叀  '
console.log(align.left('abc', 10));       // 'abc       '
console.log(align.left('叀叀叀', 10));     // '叀叀叀    '
console.log(align.right('abc', 10));      // '       abc'
console.log(align.right('叀叀叀', 10));    // '    叀叀叀'

API

align.center(str: string, length: number) β†’ string

Returns str with spaces added to both sides such that that it is length chars long and centered in the spaces.

align.left(str: string, length: number) β†’ string

Returns str with spaces to the right such that it is length chars long.

align.right(str: string, length: number) β†’ string

Returns str with spaces to the left such that it is length chars long.

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Gentilhomme

πŸ’» πŸ“– πŸ‘€ πŸ›‘οΈ πŸ›

Max

πŸ’»

License

MIT

About

A wide-character aware text alignment 🎯 function for use in terminals / on the console πŸ“Ÿ.

Topics

Resources

License

Security policy

Stars

Watchers

Forks