From b1e2c8fd5cb5dfa46bc440a12eafaf56cd844b1c Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 24 Nov 2025 20:54:57 +0100 Subject: Docs --- node_modules/chroma/.npmignore | 14 +++++ node_modules/chroma/README.md | 76 ++++++++++++++++++++++++++ node_modules/chroma/index.js | 113 +++++++++++++++++++++++++++++++++++++++ node_modules/chroma/license | 19 +++++++ node_modules/chroma/package.json | 7 +++ 5 files changed, 229 insertions(+) create mode 100644 node_modules/chroma/.npmignore create mode 100644 node_modules/chroma/README.md create mode 100644 node_modules/chroma/index.js create mode 100644 node_modules/chroma/license create mode 100644 node_modules/chroma/package.json (limited to 'node_modules/chroma') diff --git a/node_modules/chroma/.npmignore b/node_modules/chroma/.npmignore new file mode 100644 index 0000000..c1012c7 --- /dev/null +++ b/node_modules/chroma/.npmignore @@ -0,0 +1,14 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.swp +*.pid +*.gz + +node_modules +npm-debug.log + +.DS_Store \ No newline at end of file diff --git a/node_modules/chroma/README.md b/node_modules/chroma/README.md new file mode 100644 index 0000000..711c006 --- /dev/null +++ b/node_modules/chroma/README.md @@ -0,0 +1,76 @@ +#Chroma - Simple terminal colors for Node.js +##Contents + +1. [Install](#install) +2. [Introduction](#introduction) +3. [API](#api) + * [chroma \[color\]()](#chroma-color) + * [chroma()](#chroma) +5. [License](#license) + + +
+ +##Install + +`````text +npm install kagami +````` + +
+##Introduction + +Chroma is a quick and easy way to print colors in Node.js terminal applications. +`````javascript +console.log('My favorite colors are ' + chroma.blue('blue') + ' and ' + chroma.white('white') + '!'); + +//My favorite colors are blue and white! +````` + +Chroma supports the following ASCII colors: + ++ Black ++ Red ++ Green ++ Yellow ++ Blue ++ Magenta ++ Cyan ++ White + +
+##API + +
+###chroma \[color\]() +Returns the given text wrapped in the correct ASCII color. + +Usage: +> **chroma \[color\]( text )** + +`````javascript +console.log(chroma.blue('This will be blue!')); +````` + +
+###chroma() +Returns a generator function that can be used to produce the ASCII color that is closest to the supplied value. Accepts Hex and RGB values! + +Usage: +> **chroma ( hex string )** +> ** chroma ( red value, green value, blue value )** + +`````javascript +var blueifier = chroma('#00FFFF'); +var redifier = chroma(255, 12, 5); + +console.log(blueifier('This will be blue!')); +console.log(redifier('This will probably be red!')); +````` + +
+##License + +Chroma is MIT licensed. You can read the license [here](https://raw.github.com/pachet/chroma/master/license). + + diff --git a/node_modules/chroma/index.js b/node_modules/chroma/index.js new file mode 100644 index 0000000..84c6901 --- /dev/null +++ b/node_modules/chroma/index.js @@ -0,0 +1,113 @@ +var + util = require('util'), + color_map = [ + 'black', + 'red', + 'green', + 'yellow', + 'blue', + 'magenta', + 'cyan', + 'white' + ], + color_weights = [ + [0, 0, 0], + [255, 0, 0], + [0, 255, 0], + [255, 255, 0], + [0, 0, 255], + [255, 0, 255], + [0, 255, 255], + [255, 255, 255] + ], + reset = '\x1b[30m'; + +function hex_to_rgb ( hex ) { + var + base_16; + + if ( hex.indexOf('#') === 0 ) { + hex = hex.slice(1); + } + base_16 = parseInt(hex, 16); + if ( isNaN(base_16) ) { + base_16 = 0; + } + return [ + ( base_16 >> 16 ) & 255, + ( base_16 >> 8 ) & 255, + base_16 & 255 + ]; +} + +function get_fitness ( source, target ) { + return Math.abs(source - target); +} + +function get_closest_color ( red, green, blue ) { + var + current_color, + best_color = null, + current_fit, + best_fit = 765, + index = color_map.length; + + while ( index -- ) { + current_color = color_weights [index]; + current_fit = get_fitness(red, current_color [0]) + get_fitness(green, current_color [1]) + get_fitness(blue, current_color [2]); + if ( current_fit <= best_fit ) { + best_fit = current_fit; + best_color = color_map [index]; + } + } + return best_color; +} + +function generate ( color ) { + var + resolved_color, + index; + + function colorize ( text ) { + if ( typeof text !== 'string' ) { + text = util.format(text); + } + return resolved_color + text + reset; + } + + index = color_map.indexOf(color); + if ( index !== -1 ) { + resolved_color = '\x1b[3' + index + 'm'; + } + else { + resolved_color = reset; + } + + return colorize; +} + +function create_color ( color, green, blue ) { + var + index, + resolved_color; + + if ( typeof color === 'string' ) { + if ( color [0] === '#' ) { + resolved_color = get_closest_color.apply(null, hex_to_rgb(color)); + } + } + else if ( typeof color === 'number' ) { + resolved_color = get_closest_color(color, green, blue); + } + else { + resolved_color = reset; + } + + return generate(resolved_color); +} + +color_map.map(function ( item ) { + create_color [item] = generate(item); +}); + +module.exports = create_color; diff --git a/node_modules/chroma/license b/node_modules/chroma/license new file mode 100644 index 0000000..210aa74 --- /dev/null +++ b/node_modules/chroma/license @@ -0,0 +1,19 @@ +Copyright (c) 2013 Pachet (pachet@burninggarden.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. diff --git a/node_modules/chroma/package.json b/node_modules/chroma/package.json new file mode 100644 index 0000000..ca9aa40 --- /dev/null +++ b/node_modules/chroma/package.json @@ -0,0 +1,7 @@ +{ + "name" : "chroma", + "version" : "0.0.1", + "description" : "Simple terminal colors for Node.js", + "author" : "pachet", + "main" : "./index" +} -- cgit v1.2.3