ansi-pad
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ANSI Pad

A couple tiny functions for padding a string that may contain ANSI escape sequences.

Install

npm install --save ansi-pad

Usage

import {padStart, padRight} from 'ansi-pad';

// Let's pad a string in a width-aware way, handling ANSI escapes, emojis etc. specially

const FOO = `\u001b[31mFOO\u001b[39m`;

padStart ( FOO, 2, '👨‍👩‍👧‍👦' ) // => `${FOO}`
padStart ( FOO, 5, '👨‍👩‍👧‍👦' ) // => `👨‍👩‍👧‍👦${FOO}`
padStart ( FOO, 7, '👨‍👩‍👧‍👦' ) // => `👨‍👩‍👧‍👦👨‍👩‍👧‍👦${FOO}`

padEnd ( FOO, 2, '👨‍👩‍👧‍👦' ) // => `${FOO}`
padEnd ( FOO, 5, '👨‍👩‍👧‍👦' ) // => `${FOO}👨‍👩‍👧‍👦`
padEnd ( FOO, 7, '👨‍👩‍👧‍👦' ) // => `${FOO}👨‍👩‍👧‍👦👨‍👩‍👧‍👦`

License

MIT © Fabio Spampinato

Package Sidebar

Install

npm i ansi-pad

Weekly Downloads

1

Version

1.0.0

License

none

Unpacked Size

7.96 kB

Total Files

21

Last publish

Collaborators

  • fabiospampinato