0.0.3 • Published 2 years ago

ansi-construct v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ansi-construct

NPM version

Construct ANSI colors strings from object descriptors.

Usage

import { ansi } from 'ansi-construct'

const item = ansi({ text: 'foo', color: ['red', 'bold'], padStart: 5 })

// change it after creation
item.padStart = 6

// stringify
console.log(`${item}`) // '   foo'
import { ansi } from 'ansi-construct'

const items = [
  ansi({ text: 'foo', color: ['red', 'bold'], padStart: 5 }),
  ansi({ text: 'bar', color: 'underline' }),
  ansi('baz', 'blue'),
]

// stringify
console.log(items.join('')) // '   foo\n\u001b[4mbar\u001b[0mbaz\u001b[0m'
import type { AnsiItem } from 'ansi-construct'
import { construct } from 'ansi-construct'

const items: AnsiItem[] = [
  { text: 'foo', color: 'red', padStart: 5 },
  { text: 'bar', color: ['green', 'bold', 'underline'] },
  ' raw text ',
  { t: 'shorthand', c: 'cyan' }
]

console.log(construct(items)) // '\x1b[31mfoo\x1b[0m \x1b[32mbar\x1b[0m raw text \x1b[36m\x1b[0m'

Sponsors

License

MIT License © 2022 Anthony Fu

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago