Skip to content

fabiospampinato/ansi-pad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published