First Commit of new way of building the Platform
This commit is contained in:
1 parent
e48cf0dae5
commit
40e60b42cc
4616 files changed
+713402
No files matched your search
+129
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
|
||||
var colornames = require('colornames');
|
||||
|
||||
/**
|
||||
* Kuler: Color text using CSS colors
|
||||
*
|
||||
* @constructor
|
||||
* @param {String} text The text that needs to be styled
|
||||
* @param {String} color Optional color for alternate API.
|
||||
* @api public
|
||||
*/
|
||||
function Kuler(text, color) {
|
||||
if (color) return (new Kuler(text)).style(color);
|
||||
if (!(this instanceof Kuler)) return new Kuler(text);
|
||||
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* ANSI color codes.
|
||||
*
|
||||
* @type {String}
|
||||
* @private
|
||||
*/
|
||||
Kuler.prototype.prefix = '\x1b[';
|
||||
Kuler.prototype.suffix = 'm';
|
||||
|
||||
/**
|
||||
* Parse a hex color string and parse it to it's RGB equiv.
|
||||
*
|
||||
* @param {String} color
|
||||
* @returns {Array}
|
||||
* @api private
|
||||
*/
|
||||
Kuler.prototype.hex = function hex(color) {
|
||||
color = color[0] === '#' ? color.substring(1) : color;
|
||||
|
||||
//
|
||||
// Pre-parse for shorthand hex colors.
|
||||
//
|
||||
if (color.length === 3) {
|
||||
color = color.split('');
|
||||
|
||||
color[5] = color[2]; // F60##0
|
||||
color[4] = color[2]; // F60#00
|
||||
color[3] = color[1]; // F60600
|
||||
color[2] = color[1]; // F66600
|
||||
color[1] = color[0]; // FF6600
|
||||
|
||||
color = color.join('');
|
||||
}
|
||||
|
||||
var r = color.substring(0, 2)
|
||||
, g = color.substring(2, 4)
|
||||
, b = color.substring(4, 6);
|
||||
|
||||
return [ parseInt(r, 16), parseInt(g, 16), parseInt(b, 16) ];
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform a 255 RGB value to an RGV code.
|
||||
*
|
||||
* @param {Number} r Red color channel.
|
||||
* @param {Number} g Green color channel.
|
||||
* @param {Number} b Blue color channel.
|
||||
* @returns {String}
|
||||
* @api public
|
||||
*/
|
||||
Kuler.prototype.rgb = function rgb(r, g, b) {
|
||||
var red = r / 255 * 5
|
||||
, green = g / 255 * 5
|
||||
, blue = b / 255 * 5;
|
||||
|
||||
return this.ansi(red, green, blue);
|
||||
};
|
||||
|
||||
/**
|
||||
* Turns RGB 0-5 values into a single ANSI code.
|
||||
*
|
||||
* @param {Number} r Red color channel.
|
||||
* @param {Number} g Green color channel.
|
||||
* @param {Number} b Blue color channel.
|
||||
* @returns {String}
|
||||
* @api public
|
||||
*/
|
||||
Kuler.prototype.ansi = function ansi(r, g, b) {
|
||||
var red = Math.round(r)
|
||||
, green = Math.round(g)
|
||||
, blue = Math.round(b);
|
||||
|
||||
return 16 + (red * 36) + (green * 6) + blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Marks an end of color sequence.
|
||||
*
|
||||
* @returns {String} Reset sequence.
|
||||
* @api public
|
||||
*/
|
||||
Kuler.prototype.reset = function reset() {
|
||||
return this.prefix +'39;49'+ this.suffix;
|
||||
};
|
||||
|
||||
/**
|
||||
* Colour the terminal using CSS.
|
||||
*
|
||||
* @param {String} color The HEX color code.
|
||||
* @returns {String} the escape code.
|
||||
* @api public
|
||||
*/
|
||||
Kuler.prototype.style = function style(color) {
|
||||
//
|
||||
// We've been supplied a CSS color name instead of a hex color format so we
|
||||
// need to transform it to proper CSS color and continue with our execution
|
||||
// flow.
|
||||
//
|
||||
if (!/^#?(?:[0-9a-fA-F]{3}){1,2}$/.test(color)) {
|
||||
color = colornames(color);
|
||||
}
|
||||
|
||||
return this.prefix +'38;5;'+ this.rgb.apply(this, this.hex(color)) + this.suffix + this.text + this.reset();
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Expose the actual interface.
|
||||
//
|
||||
module.exports = Kuler;
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"kuler@1.0.1",
|
||||
"C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer"
|
||||
]
|
||||
],
|
||||
"_from": "kuler@1.0.1",
|
||||
"_id": "kuler@1.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==",
|
||||
"_location": "/kuler",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "kuler@1.0.1",
|
||||
"name": "kuler",
|
||||
"escapedName": "kuler",
|
||||
"rawSpec": "1.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/diagnostics"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz",
|
||||
"_spec": "1.0.1",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\TaskServer",
|
||||
"author": {
|
||||
"name": "Arnout Kazemier"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/3rd-Eden/kuler/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"colornames": "^1.1.1"
|
||||
},
|
||||
"description": "Color your terminal using CSS/hex color codes",
|
||||
"devDependencies": {
|
||||
"assume": "^2.0.1",
|
||||
"mocha": "^5.1.1"
|
||||
},
|
||||
"homepage": "https://github.com/3rd-Eden/kuler",
|
||||
"keywords": [
|
||||
"kuler",
|
||||
"ansi",
|
||||
"color",
|
||||
"colour",
|
||||
"chalk",
|
||||
"css",
|
||||
"hex",
|
||||
"rgb",
|
||||
"rgv"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "kuler",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/3rd-Eden/kuler.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test.js"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
const { it, describe } = require('mocha');
|
||||
const assume = require('assume');
|
||||
const kuler = require('./');
|
||||
|
||||
describe('kuler', function () {
|
||||
it('renders colors in the terminal', function () {
|
||||
console.log(' VISUAL INSPECTION');
|
||||
console.log(' '+ kuler('red').style('red'));
|
||||
console.log(' '+ kuler('black').style('#000'));
|
||||
console.log(' '+ kuler('white').style('#FFFFFF'));
|
||||
console.log(' '+ kuler('lime').style('AAFF5B'));
|
||||
console.log(' '+ kuler('violet').style('violetred 1'));
|
||||
console.log(' '+ kuler('purple').style('purple'));
|
||||
console.log(' '+ kuler('purple').style('purple'), 'correctly reset to normal color');
|
||||
console.log(' '+ kuler('green', 'green'));
|
||||
});
|
||||
|
||||
it('supports color names and hex values', function () {
|
||||
assume(kuler('black', 'black')).equals(kuler('black', '#000'));
|
||||
})
|
||||
|
||||
describe('#style', function () {
|
||||
it('has a style method', function () {
|
||||
assume(kuler('what').style).is.a('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user