Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

itty-chroma

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itty-chroma

Powerful styling for the browser console in under 500 bytes.

  • 0.1.18
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

itty-chroma

Version Bundle Size Coverage Status Issues Discord

v1 Documentation  |   Discord


Powerful styling for the browser console in under 500 bytes.

Example

import { chroma } from 'itty-chroma'

// keep it simple
chroma.red.log('This will be red.')

// or play a little
chroma.log(
  chroma.green,                // set the color to green
  'This is all',
  'green.',
  chroma.blue.underline.bold,  // now switch to blue
  'Now this is blue.',
)

image

Features

  • Tiny. It's an itty library, after all.
  • Made specifically for the browser console.
  • Loads of styling options, with infinite combinations.
  • Simple and powerful API, designed for ease & readability.

How it Works

Chroma is an infinite proxy object/function chain... thingy... that assembles styles before sending them to console.log.

This sounds very confusing... which is understandable, because it was confusing to write as well.

Here are the basic rules:

1. Use chroma.log (also supports warn and error) to enable styling

chroma.log('text') // console.log('text')
chroma.warn('text') // console.warn('text')
chroma.error('text') // console.error('text')

image

2. Add styles by chaining style properties

// call a segment directly, using .log
chroma.bold.red.log('This will be red.')

image

3. Or compose using chroma segments

chroma.log(
  chroma.bold.green, 
  'This will be green.'
)

image

These can be saved for re-use:

const blue = chroma.bold.blue

chroma.log(
  blue,
  'This will be blue.'
)

image

They can also be saved with the .log as a custom logger:

const ittyLogger = chroma.bold.color("#f0c").log

ittyLogger('This will be itty-colored.')

image

4. Any valid CSS color name works (100% support)

chroma.salmon.log('This is salmon.')
chroma.cornflowerblue.log('This is cornflowerblue.')
chroma.cornFlowerBlue.log('Case does not matter here...')

image

5. All valid CSS works within properties that expect a value

chroma
  .color('rgba(255,0,100,0.4)')
  .log('This works just fine')

image

6. ...or use your own custom CSS with .style(css: string)

chroma
  .size('2em')
  .padding('0.5em')
  .style('text-transform:uppercase; text-shadow:0 0 0.5em magenta;')
  .log('So does this')

image

7. A style will continue until replaced, or cleared using chroma.none

chroma.log(
  chroma.red('this will be red'),
  '...but so will this',
  chroma.clear,
  'back to unformatted text'
)

image

8. Example: Creating custom log functions

// we define a curried function to accept some args now, some later
const createLogger = (type = 'log', label, badge = 'grey', text = 'grey') => 
  (...args) => 
    chroma[type](
      chroma.bg(badge).white.bold.padding('2px 5px 1px').radius('0.2rem')(label),
      chroma.color(text).italic,
      ...args,
    )

// our loggers are partial executions
const info = createLogger('log', 'INFO', 'green')
const warning = createLogger('warn', 'WARNING', 'orange', 'brown')

// and we finally call them to log messages
info('This is just a helpful bit of info!')
warning('But this is a more serious warning text...')

image


Supported Properties

PROPERTYDESCRIPTIONEXAMPLE(s)
.logonce executed, will output to console.logchroma.log('hello')
.warnonce executed, will output to console.warnchroma.warn('warning text')
.erroronce executed, will output to console.errorchroma.error('error text')
.boldbold textchroma.bold('this is bold'), chroma.bold.red('this is bold and red')
.italicitalicized textchroma.italic('this is italic')
.underlineunderlined textchroma.underline('text')
.striketext with a line through itchroma.strike('this text was removed')
.{colorName}sets text color, supports any valid CSS color namechroma.magenta, chroma.lightGreen
.color(value)sets font color, supports any valid CSS colorchroma.color('white'), chroma.color('rgba(255,0,0,0.2)')
.font(value)sets font, supports any valid CSS font-familychroma.font('Georgia')
.size(value)sets font sizechroma.size('0.8rem')
.bg(value)sets background, supports any valid CSS backgroundchroma.bg('salmon')
.radius(value)sets border-radius (for badges)chroma.radius('4px')
.border(value)sets border stylechroma.border('double 5px red')
.padding(value)sets paddingchroma.padding('2px 5px')
.style(value)sets custom CSS, allowing any valid sequencechroma.style('text-transform:uppercase;text-shadow:0 0 0.5rem rgba(255,0,100,0.5)')
.none1clears styling for subsequent argumentschroma.red('red text', chroma.none, 'plain text')

1 Any invalid CSS color name can be used in place of chroma.none, as this utimately turns into "color:none;". Alternatively, you could use chroma.clear, chroma.noStyle, or anything else.

Keywords

FAQs

Package last updated on 18 Dec 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc