Skip to content

Commit

Permalink
Merge pull request #236 from Marak/solve-circular-refs
Browse files Browse the repository at this point in the history
Solve circular refs
  • Loading branch information
DABH authored Jul 22, 2018
2 parents 7aa37ff + c76ec61 commit 21abbcb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/safe-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ console.log('Setting themes is useful');
// Load theme with JSON literal
colors.setTheme({
silly: 'rainbow',
input: 'grey',
input: 'blue',
verbose: 'cyan',
prompt: 'grey',
info: 'green',
Expand All @@ -54,14 +54,14 @@ console.log(colors.error('this is an error'));
// outputs yellow text
console.log(colors.warn('this is a warning'));

// outputs grey text
// outputs blue text
console.log(colors.input('this is an input'));


// console.log('Generic logging theme as file'.green.bold.underline);

// Load a theme from file
colors.setTheme(__dirname + '/../themes/generic-logging.js');
colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));

// outputs red text
console.log(colors.error('this is an error'));
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ declare global {
bgCyan: string;
bgWhite: string;

reset: string;
// @ts-ignore
reset: string;
// @ts-ignore
bold: string;
dim: string;
italic: string;
Expand Down
8 changes: 4 additions & 4 deletions lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ colors.zalgo = require('./custom/zalgo');

// maps
colors.maps = {};
colors.maps.america = require('./maps/america');
colors.maps.zebra = require('./maps/zebra');
colors.maps.rainbow = require('./maps/rainbow');
colors.maps.random = require('./maps/random');
colors.maps.america = require('./maps/america')(colors);
colors.maps.zebra = require('./maps/zebra')(colors);
colors.maps.rainbow = require('./maps/rainbow')(colors);
colors.maps.random = require('./maps/random')(colors);

for (var map in colors.maps) {
(function(map) {
Expand Down
6 changes: 2 additions & 4 deletions lib/maps/america.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var colors = require('../colors');

module['exports'] = (function() {
module['exports'] = function(colors) {
return function(letter, i, exploded) {
if (letter === ' ') return letter;
switch (i%3) {
Expand All @@ -9,4 +7,4 @@ module['exports'] = (function() {
case 2: return colors.blue(letter);
}
};
})();
};
6 changes: 2 additions & 4 deletions lib/maps/rainbow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var colors = require('../colors');

module['exports'] = (function() {
module['exports'] = function(colors) {
// RoY G BiV
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
return function(letter, i, exploded) {
Expand All @@ -10,5 +8,5 @@ module['exports'] = (function() {
return colors[rainbowColors[i++ % rainbowColors.length]](letter);
}
};
})();
};

6 changes: 2 additions & 4 deletions lib/maps/random.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var colors = require('../colors');

module['exports'] = (function() {
module['exports'] = function(colors) {
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
'blue', 'white', 'cyan', 'magenta'];
return function(letter, i, exploded) {
Expand All @@ -9,4 +7,4 @@ module['exports'] = (function() {
available[Math.round(Math.random() * (available.length - 2))]
](letter);
};
})();
};
8 changes: 4 additions & 4 deletions lib/maps/zebra.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var colors = require('../colors');

module['exports'] = function(letter, i, exploded) {
return i % 2 === 0 ? letter : colors.inverse(letter);
module['exports'] = function(colors) {
return function(letter, i, exploded) {
return i % 2 === 0 ? letter : colors.inverse(letter);
};
};

0 comments on commit 21abbcb

Please sign in to comment.