1 var colors = require('./colors');
3 module['exports'] = function () {
6 // Extends prototype of native string object to allow for "foo".red syntax
8 var addProperty = function (color, func) {
9 String.prototype.__defineGetter__(color, func);
12 var sequencer = function sequencer (map, str) {
14 var exploded = this.split(""), i = 0;
15 exploded = exploded.map(map);
16 return exploded.join("");
20 addProperty('strip', function () {
21 return colors.strip(this);
24 addProperty('stripColors', function () {
25 return colors.strip(this);
28 addProperty("trap", function(){
29 return colors.trap(this);
32 addProperty("zalgo", function(){
33 return colors.zalgo(this);
36 addProperty("zebra", function(){
37 return colors.zebra(this);
40 addProperty("rainbow", function(){
41 return colors.rainbow(this);
44 addProperty("random", function(){
45 return colors.random(this);
48 addProperty("america", function(){
49 return colors.america(this);
53 // Iterate through all default styles and colors
55 var x = Object.keys(colors.styles);
56 x.forEach(function (style) {
57 addProperty(style, function () {
58 return colors.stylize(this, style);
62 function applyTheme(theme) {
64 // Remark: This is a list of methods that exist
65 // on String that you should not overwrite.
67 var stringPrototypeBlacklist = [
68 '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
69 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
70 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
71 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
74 Object.keys(theme).forEach(function (prop) {
75 if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
76 console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name');
79 if (typeof(theme[prop]) === 'string') {
80 colors[prop] = colors[theme[prop]];
81 addProperty(prop, function () {
82 return colors[theme[prop]](this);
86 addProperty(prop, function () {
88 for (var t = 0; t < theme[prop].length; t++) {
89 ret = colors[theme[prop][t]](ret);
98 colors.setTheme = function (theme) {
99 if (typeof theme === 'string') {
101 colors.themes[theme] = require(theme);
102 applyTheme(colors.themes[theme]);
103 return colors.themes[theme];