0.2.0 • Published 2 years ago

@me5on/crayon v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Crayon

import crayon from '@me5on/crayon';


console.log(crayon('{: bg.red + fg.yellow :: red bg and yellow fg :}'));

npm.io

const {ansi: A, create} = crayon;

const custom = create({
  syntax: {
    and: ',', esc: '', dot: '',
    bgn: '\\{', mid: ':', end: '\\}',
  },
  box:    {
    dim:  A.cc.dim,
    done: A.bg.green + A.fg.white + A.cc.bright,
    warn: A.bg.yellow + A.fg.black,
    info: A.bg.blue + A.fg.black,
  },
});

console.log(custom('{dim: a dim text }'));
console.log(custom('{dim,info:MARK}'));
console.log(custom('{warn:WARN}'));
console.log(custom('{done:DONE}'));

npm.io

Can also use it as a tag for template strings

console.log(custom`{dim,info:INFO} if crayon is {bold:NOT} in the box, it is ignored`);
console.log(custom`{warn:WARN} something went {bad:bad}` + ' no {bad:crayon found}');
console.log(custom`this example is {done:DONE}`);

npm.io

const {ansi: {fg: FG, bg: BG, cc: CC}, bgf: {black}, idx: IDX, rgb: RGB} = crayon;


const c = crayon.create({
  box: {
    TXT: BG.black + IDX.fg(250) + CC.bright,
    VER: BG.black + RGB.fg(0x9f, 0x90, 0xff),
    ERR: BG.black + FG.red,
    REG: BG.black,
  },
});


const version = '1.2.3';
console.log(c`{:TXT::version: :}{:VER::${version}:}`);
console.log(c`{:TXT::version: :}{:ERR::unknown:}`);

// embedded directives don't work, so they can have similar colors
console.log(c`{:TXT::first color:} in between {:VER::second color:}`);
console.log(c`{:TXT::first background:}{:REG:: now with regular background :}{:VER::second background:}`);

// there is also no need of always using tagged template strings
console.log(black('also with the same background'));

npm.io

0.2.0

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago