🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ansi-construct

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-construct

[![NPM version](https://img.shields.io/npm/v/ansi-construct?color=a1b858&label=)](https://www.npmjs.com/package/ansi-construct)

0.0.3
latest
Source
npm
Version published
Weekly downloads
9
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 18 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts