0.2.15 • Published 12 months ago

console-strings v0.2.15

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

console-strings

Coverage Status Social Media Photo by Dominik Scythe on Unsplash

A dual module that can be used via import, require, or directly via https://esm.run/console-strings, to automatically wrap \x1b[... escape chars around strings in a terminal or devtools compatible way.

import {
  bold,       // show bold text
  light,      // show a lighter text - alias: dim
  italic,     // show italic text
  underline,  // show underlined text
  strike,     // show a strike-through text
  overline,   // show an overline (not in devtools)
  foreground, // use a specific text color
  background, // use a specific background color
  reset,      // reset any broken output (not needed but handy)
} from 'console-strings';

// ⚠️ needed only for x-browser compatibility
// not needed at all in Bun, NodeJS or Chrome/ium browsers
import * as console from 'console-strings/browser';
// exported: error, info, log, warn

console.log(`
  This is ${bold('bold')} text
  while this should be ${light('light')}.
  An ${italic('italic')} text is allowed
  and so it should be ${underline('underlined')}.
  A ${strike('strike')} would work too but
  an ${overline('overline')} might not.
  Combine ${underline(bold(italic('underlined bold italic')))}
  or any other variant or add some ${foreground('color', 32)} and
  ${background(foreground('background', 30), 42)} color too. ${reset()}
`);

Live Demo

visual terminal example

Markdown

The console-strings/md default export converts:

  • bold via **double** stars
  • underline via __double__ underlines
  • light or dim via -single- or --double-- dashes
  • strike via ~single~ or ~~double~~ dashes
  • italic via single *star* or single _underlined_ only
  • foreground via f#32#color value# or f#R;G;B#rgb value#
  • background via b#42#color value# or b#R;G;B#rgb value#
import md from 'console-strings/md';

console.log(md('Hello **World**!'));

For anything more complex please see consolemd.

Live Demo

Colors

All colors compatible with devtools are described in here and this is a summary:

NameForegroundBackgroundLight themeDark theme
Black3040#000000#000000
Red3141#AA0000#ED4E4C
Green3242#00AA00#01C800
Yellow3343#AA5500#D2C057
Blue3444#0000AA#2774F0
Magenta3545#AA00AA#A142F4
Cyan3646#00AAAA#12B5CB
White3747#AAAAAA#CFD0D0
Bright Black90100#555555#898989
Bright Red91101#FF5555#F28B82
Bright Green92102#55FF55#01C801
Bright Yellow93103#FFFF55#DDFB55
Bright Blue94104#5555FF#669DF6
Bright Magenta95105#FF55FF#D670D6
Bright Cyan96106#55FFFF#84F0FF
Bright White97107#FFFFFF#FFFFFF

If a foreground value for a background(content, value) is passed along, or vice-versa, a char would prefix the error without throwing while outputting.

The browser variant color is chosen after a one-off matchMedia('(prefers-color-scheme:dark)') check.

0.2.15

12 months ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago