Travis build: 1222
This commit is contained in:
43
README.md
43
README.md
@ -246,6 +246,7 @@ average(1, 2, 3);
|
|||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`colorize`](#colorize)
|
||||||
* [`hasFlags`](#hasflags)
|
* [`hasFlags`](#hasflags)
|
||||||
* [`isTravisCI`](#istravisci)
|
* [`isTravisCI`](#istravisci)
|
||||||
* [`JSONToFile`](#jsontofile)
|
* [`JSONToFile`](#jsontofile)
|
||||||
@ -3731,6 +3732,48 @@ toSafeInteger(Infinity); // 9007199254740991
|
|||||||
---
|
---
|
||||||
## 📦 Node
|
## 📦 Node
|
||||||
|
|
||||||
|
### colorize
|
||||||
|
|
||||||
|
Add special characters to text to print in color in the console (combined with `console.log()`).
|
||||||
|
|
||||||
|
Use template literals and special characters to add the appropriate color code to the string output.
|
||||||
|
For background colors, add a special character that resets the background color at the end of the string.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const colorize = (...args) => ({
|
||||||
|
black: `\x1b[30m${args.join(' ')}`,
|
||||||
|
red: `\x1b[31m${args.join(' ')}`,
|
||||||
|
green: `\x1b[32m${args.join(' ')}`,
|
||||||
|
yellow: `\x1b[33m${args.join(' ')}`,
|
||||||
|
blue: `\x1b[34m${args.join(' ')}`,
|
||||||
|
magenta: `\x1b[35m${args.join(' ')}`,
|
||||||
|
cyan: `\x1b[36m${args.join(' ')}`,
|
||||||
|
white: `\x1b[37m${args.join(' ')}`,
|
||||||
|
bgBlack: `\x1b[40m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgRed: `\x1b[41m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgGreen: `\x1b[42m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgYellow: `\x1b[43m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
||||||
|
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
console.log(colorize('foo').red); // 'foo' (red letters)
|
||||||
|
console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background)
|
||||||
|
console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both)
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### hasFlags
|
### hasFlags
|
||||||
|
|
||||||
Check if the current process's arguments contain the specified flags.
|
Check if the current process's arguments contain the specified flags.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -6,30 +6,28 @@ Use template literals and special characters to add the appropriate color code t
|
|||||||
For background colors, add a special character that resets the background color at the end of the string.
|
For background colors, add a special character that resets the background color at the end of the string.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const colorize = (...args) => (
|
const colorize = (...args) => ({
|
||||||
{
|
black: `\x1b[30m${args.join(' ')}`,
|
||||||
black: `\x1b[30m${args.join(' ')}`,
|
red: `\x1b[31m${args.join(' ')}`,
|
||||||
red: `\x1b[31m${args.join(' ')}`,
|
green: `\x1b[32m${args.join(' ')}`,
|
||||||
green: `\x1b[32m${args.join(' ')}`,
|
yellow: `\x1b[33m${args.join(' ')}`,
|
||||||
yellow: `\x1b[33m${args.join(' ')}`,
|
blue: `\x1b[34m${args.join(' ')}`,
|
||||||
blue: `\x1b[34m${args.join(' ')}`,
|
magenta: `\x1b[35m${args.join(' ')}`,
|
||||||
magenta: `\x1b[35m${args.join(' ')}`,
|
cyan: `\x1b[36m${args.join(' ')}`,
|
||||||
cyan: `\x1b[36m${args.join(' ')}`,
|
white: `\x1b[37m${args.join(' ')}`,
|
||||||
white: `\x1b[37m${args.join(' ')}`,
|
bgBlack: `\x1b[40m${args.join(' ')}\x1b[0m`,
|
||||||
bgBlack : `\x1b[40m${args.join(' ')}\x1b[0m`,
|
bgRed: `\x1b[41m${args.join(' ')}\x1b[0m`,
|
||||||
bgRed : `\x1b[41m${args.join(' ')}\x1b[0m`,
|
bgGreen: `\x1b[42m${args.join(' ')}\x1b[0m`,
|
||||||
bgGreen : `\x1b[42m${args.join(' ')}\x1b[0m`,
|
bgYellow: `\x1b[43m${args.join(' ')}\x1b[0m`,
|
||||||
bgYellow : `\x1b[43m${args.join(' ')}\x1b[0m`,
|
bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`,
|
||||||
bgBlue : `\x1b[44m${args.join(' ')}\x1b[0m`,
|
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
|
||||||
bgMagenta : `\x1b[45m${args.join(' ')}\x1b[0m`,
|
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
|
||||||
bgCyan : `\x1b[46m${args.join(' ')}\x1b[0m`,
|
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
|
||||||
bgWhite : `\x1b[47m${args.join(' ')}\x1b[0m`
|
});
|
||||||
}
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(colorize('foo').red); // 'foo' (red letters)
|
console.log(colorize('foo').red); // 'foo' (red letters)
|
||||||
console.log(colorize('foo','bar').bgBlue); // 'foo bar' (blue background)
|
console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background)
|
||||||
console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both)
|
console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both)
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user