https://github.com/topcli/text-align
A wide-character aware text alignment 🎯 function for use in terminals / on the console 📟.
https://github.com/topcli/text-align
align alignment cli text widealign
Last synced: about 1 year ago
JSON representation
A wide-character aware text alignment 🎯 function for use in terminals / on the console 📟.
- Host: GitHub
- URL: https://github.com/topcli/text-align
- Owner: TopCli
- License: mit
- Created: 2020-03-20T14:38:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-05-01T14:20:22.000Z (about 1 year ago)
- Last Synced: 2025-05-01T15:29:42.764Z (about 1 year ago)
- Topics: align, alignment, cli, text, widealign
- Language: JavaScript
- Homepage:
- Size: 160 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# text-align

[](https://github.com/TopCli/text-align/commit-activity)
[](https://github.com/TopCli/text-align/blob/master/LICENSE)
[](https://api.securityscorecards.dev/projects/github.com/TopCli/text-align)

A wide-character aware text alignment function for use in terminals / on the console. This package is a modern implementation of [wide-align](https://github.com/iarna/wide-align) with String.prototype.padLeft and String.prototype.padRight.
## Requirements
- [Node.js](https://nodejs.org/en/) v22 or higher
## Getting Started
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
```bash
$ npm i @topcli/text-align
# or
$ yarn add @topcli/text-align
```
### Usage example
```js
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 ✨
[](#contributors-)
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
## License
MIT