0.0.1-security • Published 1 year ago

sync-color v0.0.1-security

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

sync-color

Beautiful colors in terminal output

Install

$ npm i sync-color

Usage

const Color = require('sync-color');
Color.init() // Always use init function to removes all potentially errors in the colors
console.log(Color.InitGradient('cyan', 'pink')('Hello world!'));

Initialize a gradient

// Using varargs
let coolColor = Color.InitGradient('red', 'green', 'blue');

// Using array
let coolColor = Color.InitGradient(['#FF0000', '#00FF00', '#0000FF']);

The colors are parsed with TinyColor, multiple formats are accepted.

let coolColor = Color.InitGradient([
  tinycolor('#FFBB65'),       // tinycolor object
  {r: 0, g: 255, b: 0},       // RGB object
  {h: 240, s: 1, v: 1, a: 1}, // HSVa object
  'rgb(120, 120, 0)',         // RGB CSS string
  'gold'                      // named color
]);

Use a gradient

let coolString = coolColor.InitGradient('This is a fancy string!');
console.log(coolString);

Built-in gradients

Usage

const Color = require('sync-color');
Color.init()
// Use the rainbow gradient
console.log(Color.rainbow('I love sync-colors!'))

Multi line gradients

In some cases, you may want to apply the same horizontal gradient on each line of a long text (or a piece of ASCII art).

You can use the multiline() method of a gradient to ensure that the colors are vertically aligned.

const Color = require('sync-color');
Color.init()
// Use the same gradient on every line
let duck = Color.InitGradient('orange', 'yellow').multiline([
    "  __",
    "<(o )___",
    " ( ._> /",
    "  `---'",
].join('\n'));
console.log(duck);

// Works with aliases
Color.atlas.multiline('Multi line\nstring');

// Works with advanced options
Color.InitGradient('cyan', 'pink').multiline('Multi line\nstring', {interpolation: 'hsv'});

Advanced gradients

There are also more advanced options for gradient customization, such as custom color stops, or choice of color interpolation

Custom color stops

By default, the gradient color stops are distributed equidistantly.

You can specify the position of each color stop (between 0 and 1), using the following syntax:

let coolGradient = Color.InitGradient([
  {color: '#d8e0de', pos: 0},
  {color: '#255B53', pos: 0.8},
  {color: '#000000', pos: 1}
]);
Code
const redToGreen = Color.InitGradient('red', 'green');
const str = '■'.repeat(48);

// Standard RGB gradient
console.log(redToGreen(str)); 

// Short HSV gradient: red -> yellow -> green
console.log(redToGreen(str, {interpolation: 'hsv'}));

// Long HSV gradient: red -> magenta -> blue -> cyan -> green
console.log(redToGreen(str, {interpolation: 'hsv', hsvSpin: 'long'}));
0.0.1-security

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago