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

feat: add pakistan style to colors.js #352

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
- america
- trap
- random
- pakistan


## Usage
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Color {
trap: Color;
random: Color;
zalgo: Color;
pakustan: Color;
}

export function enable(): void;
Expand Down Expand Up @@ -90,6 +91,7 @@ export const america: Color;
export const trap: Color;
export const random: Color;
export const zalgo: Color;
export const pakistan: Color;

declare global {
interface String {
Expand Down Expand Up @@ -132,5 +134,6 @@ declare global {
trap: string;
random: string;
zalgo: string;
pakistan: string;
}
}
3 changes: 2 additions & 1 deletion lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var stylize = colors.stylize = function stylize(str, style) {
var styleMap = ansiStyles[style];

// Stylize should work for non-ANSI styles, too
if(!styleMap && style in colors){
if (!styleMap && style in colors) {
// Style maps like trap operate as functions on strings;
// they don't have properties like open or close.
return colors[style](str);
Expand Down Expand Up @@ -199,6 +199,7 @@ 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);
colors.maps.pakistan = require('./maps/pakistan')(colors);

for (var map in colors.maps) {
(function(map) {
Expand Down
4 changes: 4 additions & 0 deletions lib/extendStringPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ module['exports'] = function() {
return colors.america(this);
});

addProperty('pakistan', function() {
return colors.pakistan(this);
});

//
// Iterate through all default styles and colors
//
Expand Down
12 changes: 12 additions & 0 deletions lib/maps/pakistan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module['exports'] = function(colors) {
return function(letter, i, exploded) {
var totalLetters = exploded.length;
var threshold = Math.floor(totalLetters * 0.3);

if (i < threshold) {
return colors.white(letter);
} else {
return colors.green(letter);
}
};
};
Binary file added screenshots/paksitan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions tests/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function aE(s, color, code) {
}

var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta',
'red', 'yellow', 'brightYellow', 'brightRed',
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan',
'brightMagenta'];
'red', 'yellow', 'brightYellow', 'brightRed',
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan',
'brightMagenta'];

// eslint-disable-next-line
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline',
Expand All @@ -33,11 +33,11 @@ assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');

assert.ok(s.rainbow);

assert.equal(colors.stylize("foo", "rainbow"), '\u001b[31mf\u001b[39m\u001b[33mo\u001b[39m\u001b[32mo\u001b[39m');
assert.ok(colors.stylize(s, "america"));
assert.ok(colors.stylize(s, "zebra"));
assert.ok(colors.stylize(s, "trap"));
assert.ok(colors.stylize(s, "random"));
assert.equal(colors.stylize('foo', 'rainbow'), '\u001b[31mf\u001b[39m\u001b[33mo\u001b[39m\u001b[32mo\u001b[39m');
assert.ok(colors.stylize(s, 'america'));
assert.ok(colors.stylize(s, 'zebra'));
assert.ok(colors.stylize(s, 'trap'));
assert.ok(colors.stylize(s, 'random'));

aE(s, 'white', 37);
aE(s, 'grey', 90);
Expand Down
6 changes: 3 additions & 3 deletions tests/safe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function aE(s, color, code) {
}

var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta',
'red', 'yellow', 'brightYellow', 'brightRed',
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan',
'brightMagenta'];
'red', 'yellow', 'brightYellow', 'brightRed',
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan',
'brightMagenta'];
// eslint-disable-next-line
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse',
'rainbow']);
Expand Down