ansi-construct

Construct ANSI colors strings from object descriptors.
Usage
import { ansi } from 'ansi-construct'
const item = ansi({ text: 'foo', color: ['red', 'bold'], padStart: 5 })
item.padStart = 6
console.log(`${item}`)
import { ansi } from 'ansi-construct'
const items = [
ansi({ text: 'foo', color: ['red', 'bold'], padStart: 5 }),
ansi({ text: 'bar', color: 'underline' }),
ansi('baz', 'blue'),
]
console.log(items.join(''))
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))
License
MIT License © 2022 Anthony Fu