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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colours of France #245

Open
wants to merge 7 commits 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
- rainbow
- zebra
- america
- france
- trap
- random

Expand Down Expand Up @@ -94,14 +95,16 @@ I prefer the first way. Some people seem to be afraid of extending `String.proto

If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.

## Disabling Colors
## Forcing Colors to be Enabled/Disabled

To disable colors you can pass the following arguments in the command line to your application:

```bash
node myapp.js --no-color
```

Alternatively, you can define an environment variable named `FORCE_COLOR` to force colors to be enabled (e.g. in a complex environment where colors support is not detected properly), or `FORCE_NO_COLOR` to force colors to be disabled; the environment variables will take effect if any non-zero value is specified.

## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)

```js
Expand Down
1 change: 1 addition & 0 deletions examples/normal-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ console.log('This is ' + 'not'.strikethrough + ' fun.');
console.log('Background color attack!'.black.bgWhite);
console.log('Use random styles on everything!'.random);
console.log('America, Heck Yeah!'.america);
console.log('Parlez-vous fran莽ais?'.france);


console.log('Setting themes is useful');
Expand Down
1 change: 1 addition & 0 deletions examples/safe-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ console.log('This is ' + colors.strikethrough('not') + ' fun.');
console.log(colors.black.bgWhite('Background color attack!'));
console.log(colors.random('Use random styles on everything!'));
console.log(colors.america('America, Heck Yeah!'));
console.log(colors.france('Parlez-vous fran莽ais?'));

console.log('Setting themes is useful');

Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface Color {
rainbow: Color;
zebra: Color;
america: Color;
france: Color;
trap: Color;
random: Color;
zalgo: Color;
Expand Down Expand Up @@ -87,6 +88,7 @@ export const strikethrough: Color;
export const rainbow: Color;
export const zebra: Color;
export const america: Color;
export const france: Color;
export const trap: Color;
export const random: Color;
export const zalgo: Color;
Expand Down Expand Up @@ -129,6 +131,7 @@ declare global {
rainbow: string;
zebra: string;
america: string;
france: string;
trap: string;
random: string;
zalgo: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function applyStyle() {
var args = Array.prototype.slice.call(arguments);

var str = args.map(function(arg) {
if (arg !== undefined && arg.constructor === String) {
if (arg != undefined && arg.constructor === String) {
return arg;
} else {
return util.inspect(arg);
Expand Down Expand Up @@ -186,6 +186,7 @@ colors.zalgo = require('./custom/zalgo');
// maps
colors.maps = {};
colors.maps.america = require('./maps/america')(colors);
colors.maps.france = require('./maps/france')(colors);
colors.maps.zebra = require('./maps/zebra')(colors);
colors.maps.rainbow = require('./maps/rainbow')(colors);
colors.maps.random = require('./maps/random')(colors);
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('france', function() {
return colors.france(this);
});

//
// Iterate through all default styles and colors
//
Expand Down
10 changes: 10 additions & 0 deletions lib/maps/france.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module['exports'] = function(colors) {
return function(letter, i, exploded) {
if (letter === ' ') return letter;
switch (i%3) {
case 0: return colors.blue(letter);
case 1: return colors.white(letter);
case 2: return colors.red(letter);
}
};
};
31 changes: 31 additions & 0 deletions lib/system/has-env-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

'use strict';

module.exports = function(flag, env) {
env = env || process.env;
return (flag in env) &&
(env[flag].length === 0 || parseInt(env[flag], 10) !== 0);
};
17 changes: 14 additions & 3 deletions lib/system/supports-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THE SOFTWARE.

var os = require('os');
var hasFlag = require('./has-flag.js');
var hasEnvFlag = require('./has-env-flag.js');

var env = process.env;

Expand All @@ -37,9 +38,19 @@ if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
|| hasFlag('color=always')) {
forceColor = true;
}
if ('FORCE_COLOR' in env) {
forceColor = env.FORCE_COLOR.length === 0
|| parseInt(env.FORCE_COLOR, 10) !== 0;

var forceColorFromEnv = hasEnvFlag('FORCE_COLOR', env);
var forceNoColorFromEnv = hasEnvFlag('FORCE_NO_COLOR', env);
if (forceColorFromEnv) {
if (forceNoColorFromEnv && process.emitWarning) {
process.emitWarning(
'FORCE_COLOR and FORCE_NO_COLOR env vars are both set and conflicting, ' +
'going with FORCE_COLOR.'
);
}
forceColor = true;
} else if (forceNoColorFromEnv) {
forceColor = false;
}

function translateLevel(level) {
Expand Down