Construct ANSI colors strings from object descriptors.

Overview

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

You might also like...

An open-development real-time strategy (RTS) game project made in Construct.

Command & Construct This is an open-development real-time strategy (RTS) game project made in Construct. Read more about it and follow along the devel

Dec 20, 2022

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Dec 6, 2022

Emoji - Use emoji names instead of Unicode strings. Copy-pasting emoji sucks.

Grammy Emoji Adds emoji parsing for grammY. Check out the official documentation for this plugin. While this draft is working, we still do not recomme

Sep 5, 2022

Compare camelized/dasherized/underscored strings each other 🤜🏿 🤛🏿

aynen Compare camelized/dasherized/underscored strings each other Install npm install aynen yarn add aynen Usage import aynen from 'aynen'; aynen('fo

Mar 25, 2022

A TypeScript namespace declaration for KeyboardEvent.key strings, just in case your code is allergic to enums.

ts-key-namespace A TypeScript namespace declaration for KeyboardEvent.key strings, just in case you prefer namespaces to enums. Largely based on ts-ke

Apr 5, 2022

Transform URLs in strings to actual links.

Transform URLs in strings to actual links.

Transform URLs in strings to actual links. It will find valid links in the given string and create a tags for it. Internally, it uses this Regex to

Nov 4, 2022

Converts JSX to HTML strings at compile time.

unplugin-jsx-string Converts JSX to HTML strings at compile time. Installation npm i unplugin-jsx-string Vite // vite.config.ts import JsxString from

Sep 3, 2022

♻️ Simple way to convert strings to gitmojis

convert-gitmoji Simple way to convert strings to gitmojis ♻️ Install # Using npm npm install convert-gitmoji # Using yarn yarn add convert-gitmoji Us

Nov 4, 2022

A lightweight JavaScript library that renders text in a brilliant style by displaying strings of random characters before the actual text.

A lightweight JavaScript library that renders text in a brilliant style by displaying strings of random characters before the actual text.

cryptoWriter.js A lightweight javascript library which creates brilliant text animation by rendering strings of random characters before the actual te

Sep 13, 2022
Releases(v0.0.3)
Owner
Anthony Fu
A ship in harbor is safe, but that is not what ships are built for.
Anthony Fu
🎨ansi escape code generator to help make colorful command line tools

ansicodes ?? ansi escape code generator to help make colorful command line tools i got tired of looking up ansi code tables when writing command line

Gabe Banks 53 Dec 17, 2022
Replace ansi escape sequences with tokens indicating what they are

Replace ansi escape sequences with tokens indicating what they are

Lily Scott 3 Mar 7, 2022
Simple string diffing. Given two strings, striff will return an object noting which characters were added or removed, and at which indices

Simple string diffing. Given two strings, striff will return an object noting which characters were added or removed, and at which indices

Alex MacArthur 196 Jan 6, 2023
Fix for Object.keys, which normally just returns an array of strings, which is not good when you care about strong typing

Welcome to ts-object-keys ?? Fix for Object.keys, which normally just returns an array of strings, which is not good when you care about strong typing

Funtal Foundation 1 Jul 4, 2022
Simple utils to pack arrays, objects and strings to a flat object (and back again).

packrup Simple utils to pack (and unpack) arrays and strings to a flat object. Status: In Development Please report any issues ?? Made possible by my

Harlan Wilton 15 Dec 23, 2022
This project provides a CDK construct creating AWS organizations.

AWS Organizations This project provides a CDK construct creating AWS organizations. Currently, there is no @aws-cdk/aws-organizations available. See t

Pepperize 107 Dec 29, 2022
This is the team project of construct week unit-3 (js201)

This is the team project of construct week unit-3 (js201) I. Project's Title => Clone of Mytheresa.com (E-commerce website) II. Project Description =>

Brajesh Lovanshi 5 Sep 28, 2022
Automatically construct and visualize Graphs generated from your Node.js project

cyclops is a minimalist developer tool that can be used to generate directed graphs from your Node.js project. It can automatically detect circular de

Antoine Coulon 74 Jan 5, 2023
CDK construct to periodically take snapshots of RDS databases, sanitize them, and share with selected accounts.

CDK Construct for RDS Sanitized Snapshots Periodically take snapshots of RDS databases, sanitize them, and share with selected accounts. Use this to a

CloudSnorkel 6 Dec 7, 2022
Automatically construct, traverse and visualize graphs generated from your Node.js project

skott is a minimalist developer tool that can be used to efficiently generate directed graphs from your JavaScript/Node.js project. It can automatical

Antoine Coulon 57 Dec 21, 2022