Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: neon - similar to rainbow but user can choose the colors. #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
10 changes: 10 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
- white
- gray
- grey
- neonRed
- neonGreen
- neonYellow
- neonBlue
- neonMagenta
- neonCyan
- neonWhite

### background colors

Expand Down Expand Up @@ -54,6 +61,7 @@
- america
- trap
- random
- neon


## Usage
Expand All @@ -70,6 +78,7 @@ console.log('i like cake and pies'.underline.red) // outputs red underlined text
console.log('inverse the color'.inverse); // inverses the color
console.log('OMG Rainbows!'.rainbow); // rainbow
console.log('Run the trap'.trap); // Drops the bass
console.log('Show this is neon'.neon('red', 'blue', 'green')) // neon

```

Expand All @@ -83,6 +92,7 @@ console.log(colors.red.underline('i like cake and pies')) // outputs red underli
console.log(colors.inverse('inverse the color')); // inverses the color
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
console.log(colors.trap('Run the trap')); // Drops the bass
console.log(colors.neon('Show this is neon', 'red', 'blue', 'green')); // neon

```

Expand Down
2 changes: 2 additions & 0 deletions examples/normal-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ console.log("Drop the bass".trap)

console.log("DROP THE RAINBOW BASS".trap.rainbow)

console.log("Show this in neon".neon("neonRed", "blue", "neonYellow"))


console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported

Expand Down
3 changes: 2 additions & 1 deletion examples/safe-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ console.log(colors.trap("Drop the bass"))

console.log(colors.rainbow(colors.trap("DROP THE RAINBOW BASS")));

console.log(colors.bold.italic.underline.red('Chains are also cool.')); // styles not widely supported
console.log(colors.neon("Show this in neon", "neonRed", "blue", "neonYellow"));

console.log(colors.bold.italic.underline.red('Chains are also cool.')); // styles not widely supported

console.log(colors.green('So ') + colors.underline('are') + ' ' + colors.inverse('inverse') + colors.yellow.bold(' styles! ')); // styles not widely supported

Expand Down
1 change: 1 addition & 0 deletions lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ var sequencer = function sequencer (map, str) {
// custom formatter methods
colors.trap = require('./custom/trap');
colors.zalgo = require('./custom/zalgo');
colors.neon = require('./custom/neon');

// maps
colors.maps = {};
Expand Down
39 changes: 39 additions & 0 deletions lib/custom/neon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var colors = require('../colors');

var getValidColors = function(clrs) {
var validColors = [];
clrs.forEach(function(clr) {
if(colors[clr]) {
validColors.push(clr);
}
});
return validColors;
};

module['exports'] = function(str) {
if(!str) {
return '';
}

var clrs = Array.prototype.slice.call(arguments, 1);

if(clrs.length == 0) {
return str.toString();
}

var validColors = getValidColors(clrs);
var chars = str.split('');
var neonChars = [];

chars.forEach(function(c) {
if(c === ' ') {
neonChars.push(c)
} else {
var colorCode = validColors.shift();
neonChars.push(colors[colorCode](c));
validColors.push(colorCode);
}
});

return neonChars.join('');
}
6 changes: 6 additions & 0 deletions lib/extendStringPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ module['exports'] = function () {
return colors.america(this);
});

String.prototype.neon = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
return colors.neon.apply(null, args);
}

//
// Iterate through all default styles and colors
//
Expand Down
7 changes: 7 additions & 0 deletions lib/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ var codes = {
white: [37, 39],
gray: [90, 39],
grey: [90, 39],
neonRed: [91, 39],
neonGreen: [92, 39],
neonYellow: [93, 39],
neonBlue: [94, 39],
neonMagenta: [95, 39],
neonCyan: [96, 39],
neonWhite: [97, 39],

bgBlack: [40, 49],
bgRed: [41, 49],
Expand Down
1 change: 1 addition & 0 deletions tests/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m');
assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');

assert.ok(s.rainbow);
assert.ok(s.neon("red", "blue", "green"))

aE(s, 'white', 37);
aE(s, 'grey', 90);
Expand Down
1 change: 1 addition & 0 deletions tests/safe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ assert.equal(colors.strikethrough(s), '\x1B[9m' + s + '\x1B[29m');
assert.equal(colors.inverse(s), '\x1B[7m' + s + '\x1B[27m');

assert.ok(colors.rainbow);
assert.ok(colors.neon);

aE(s, 'white', 37);
aE(s, 'grey', 90);
Expand Down