JSPM

@slimio/text-align

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q27155F
  • License MIT

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

Package Exports

  • @slimio/text-align

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@slimio/text-align) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

text-align

version Maintenance MIT dep size known vulnerabilities Build Status

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 @slimio/text-align
# or
$ yarn add @slimio/text-align

Usage example

const align = require("@slimio/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.

Dependencies

Name Refactoring Security Risk Usage
@slimio/wcwidth Minor Low Determine columns needed for a fixed-size wide-character string

License

MIT