colors 0.6.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +6 -0
- package/MIT-LICENSE.txt +4 -3
- package/ReadMe.md +120 -30
- package/examples/normal-usage.js +74 -0
- package/examples/safe-string.js +76 -0
- package/lib/colors.js +176 -0
- package/lib/custom/trap.js +45 -0
- package/lib/custom/zalgo.js +104 -0
- package/lib/extendStringPrototype.js +118 -0
- package/lib/index.js +12 -0
- package/lib/maps/america.js +12 -0
- package/lib/maps/rainbow.js +13 -0
- package/lib/maps/random.js +8 -0
- package/lib/maps/zebra.js +5 -0
- package/lib/styles.js +77 -0
- package/lib/system/supports-colors.js +61 -0
- package/package.json +7 -3
- package/safe.js +9 -0
- package/screenshots/colors.png +0 -0
- package/{test.js → tests/basic-test.js} +6 -26
- package/tests/safe-test.js +45 -0
- package/themes/{winston-light.js → generic-logging.js} +0 -0
- package/colors.js +0 -342
- package/example.html +0 -76
- package/example.js +0 -77
- package/themes/winston-dark.js +0 -12
package/.travis.yml
ADDED
package/MIT-LICENSE.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
|
1
|
+
Original Library
|
2
|
+
- Copyright (c) Marak Squires
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
Additional Functionality
|
5
|
+
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
5
6
|
|
6
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/ReadMe.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
# colors.js
|
1
|
+
# colors.js
|
2
2
|
|
3
|
-
|
3
|
+
## get color and style in your node.js console
|
4
4
|
|
5
|
+
<img src="https://github.com/Marak/colors.js/raw/master/screenshots/colors.png"/>
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
|
@@ -9,34 +10,105 @@
|
|
9
10
|
|
10
11
|
## colors and styles!
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
- magenta
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
### text colors
|
14
|
+
|
15
|
+
- black
|
16
|
+
- red
|
17
|
+
- green
|
18
|
+
- yellow
|
19
|
+
- blue
|
20
|
+
- magenta
|
21
|
+
- cyan
|
22
|
+
- white
|
23
|
+
- gray
|
24
|
+
- grey
|
25
|
+
|
26
|
+
### background colors
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
- bgBlack
|
31
|
+
- bgRed
|
32
|
+
- bgGreen
|
33
|
+
- bgYellow
|
34
|
+
- bgBlue
|
35
|
+
- bgMagenta
|
36
|
+
- bgCyan
|
37
|
+
- bgWhite
|
38
|
+
|
39
|
+
### styles
|
40
|
+
|
41
|
+
- reset
|
42
|
+
- bold
|
43
|
+
- dim
|
44
|
+
- italic
|
45
|
+
- underline
|
46
|
+
- inverse
|
47
|
+
- hidden
|
48
|
+
- strikethrough
|
49
|
+
|
50
|
+
### extras
|
51
|
+
|
52
|
+
- rainbow
|
53
|
+
- zebra
|
54
|
+
- america
|
55
|
+
- trap
|
56
|
+
- random
|
57
|
+
|
27
58
|
|
28
59
|
## Usage
|
29
60
|
|
30
|
-
|
31
|
-
|
61
|
+
By popular demand, `colors` now ships with two types of usages!
|
62
|
+
|
63
|
+
The super nifty way
|
64
|
+
|
65
|
+
```js
|
66
|
+
var colors = require('colors');
|
32
67
|
|
33
68
|
console.log('hello'.green); // outputs green text
|
34
69
|
console.log('i like cake and pies'.underline.red) // outputs red underlined text
|
35
70
|
console.log('inverse the color'.inverse); // inverses the color
|
36
|
-
console.log('OMG Rainbows!'.rainbow); // rainbow
|
71
|
+
console.log('OMG Rainbows!'.rainbow); // rainbow
|
72
|
+
console.log('Run the trap'.trap); // Drops the bass
|
73
|
+
|
74
|
+
```
|
75
|
+
|
76
|
+
or a slightly less nifty way which doesn't extend `String.prototype`
|
77
|
+
|
78
|
+
```js
|
79
|
+
var colors = require('colors/safe');
|
80
|
+
|
81
|
+
console.log(colors.green('hello')); // outputs green text
|
82
|
+
console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
|
83
|
+
console.log(colors.inverse('inverse the color')); // inverses the color
|
84
|
+
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
|
85
|
+
console.log(colors.trap('Run the trap')); // Drops the bass
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
I prefer the first way. Some people seem to be afraid of extending `String.prototype` and prefer the second way.
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
93
|
+
## Disabling Colors
|
94
|
+
|
95
|
+
To disable colors you can pass the following arguments in the command line to your application:
|
96
|
+
|
97
|
+
```bash
|
98
|
+
node myapp.js --no-color
|
37
99
|
```
|
38
100
|
|
39
|
-
|
101
|
+
## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
|
102
|
+
|
103
|
+
```js
|
104
|
+
var name = 'Marak';
|
105
|
+
console.log(colors.green('Hello %s'), name);
|
106
|
+
// outputs -> 'Hello Marak'
|
107
|
+
```
|
108
|
+
|
109
|
+
## Custom themes
|
110
|
+
|
111
|
+
### Using standard API
|
40
112
|
|
41
113
|
```js
|
42
114
|
|
@@ -62,16 +134,34 @@ console.log("this is an error".error);
|
|
62
134
|
console.log("this is a warning".warn);
|
63
135
|
```
|
64
136
|
|
137
|
+
### Using string safe API
|
65
138
|
|
66
|
-
|
139
|
+
```js
|
140
|
+
var colors = require('colors/safe');
|
67
141
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
nicoreed (Nico Reed)
|
72
|
-
morganrallen (Morgan Allen)
|
73
|
-
JustinCampbell (Justin Campbell)
|
74
|
-
ded (Dustin Diaz)
|
142
|
+
// set single property
|
143
|
+
var error = colors.red;
|
144
|
+
error('this is red');
|
75
145
|
|
146
|
+
// set theme
|
147
|
+
colors.setTheme({
|
148
|
+
silly: 'rainbow',
|
149
|
+
input: 'grey',
|
150
|
+
verbose: 'cyan',
|
151
|
+
prompt: 'grey',
|
152
|
+
info: 'green',
|
153
|
+
data: 'grey',
|
154
|
+
help: 'cyan',
|
155
|
+
warn: 'yellow',
|
156
|
+
debug: 'blue',
|
157
|
+
error: 'red'
|
158
|
+
});
|
159
|
+
|
160
|
+
// outputs red text
|
161
|
+
console.log(colors.error("this is an error"));
|
162
|
+
|
163
|
+
// outputs yellow text
|
164
|
+
console.log(colors.warn("this is a warning"));
|
165
|
+
```
|
76
166
|
|
77
|
-
|
167
|
+
*Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
|
@@ -0,0 +1,74 @@
|
|
1
|
+
var colors = require('../lib/index');
|
2
|
+
|
3
|
+
console.log("First some yellow text".yellow);
|
4
|
+
|
5
|
+
console.log("Underline that text".yellow.underline);
|
6
|
+
|
7
|
+
console.log("Make it bold and red".red.bold);
|
8
|
+
|
9
|
+
console.log(("Double Raindows All Day Long").rainbow)
|
10
|
+
|
11
|
+
console.log("Drop the bass".trap)
|
12
|
+
|
13
|
+
console.log("DROP THE RAINBOW BASS".trap.rainbow)
|
14
|
+
|
15
|
+
|
16
|
+
console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
17
|
+
|
18
|
+
console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse + ' styles! '.yellow.bold); // styles not widely supported
|
19
|
+
console.log("Zebras are so fun!".zebra);
|
20
|
+
|
21
|
+
//
|
22
|
+
// Remark: .strikethrough may not work with Mac OS Terminal App
|
23
|
+
//
|
24
|
+
console.log("This is " + "not".strikethrough + " fun.");
|
25
|
+
|
26
|
+
console.log('Background color attack!'.black.bgWhite)
|
27
|
+
console.log('Use random styles on everything!'.random)
|
28
|
+
console.log('America, Heck Yeah!'.america)
|
29
|
+
|
30
|
+
|
31
|
+
console.log('Setting themes is useful')
|
32
|
+
|
33
|
+
//
|
34
|
+
// Custom themes
|
35
|
+
//
|
36
|
+
console.log('Generic logging theme as JSON'.green.bold.underline);
|
37
|
+
// Load theme with JSON literal
|
38
|
+
colors.setTheme({
|
39
|
+
silly: 'rainbow',
|
40
|
+
input: 'grey',
|
41
|
+
verbose: 'cyan',
|
42
|
+
prompt: 'grey',
|
43
|
+
info: 'green',
|
44
|
+
data: 'grey',
|
45
|
+
help: 'cyan',
|
46
|
+
warn: 'yellow',
|
47
|
+
debug: 'blue',
|
48
|
+
error: 'red'
|
49
|
+
});
|
50
|
+
|
51
|
+
// outputs red text
|
52
|
+
console.log("this is an error".error);
|
53
|
+
|
54
|
+
// outputs yellow text
|
55
|
+
console.log("this is a warning".warn);
|
56
|
+
|
57
|
+
// outputs grey text
|
58
|
+
console.log("this is an input".input);
|
59
|
+
|
60
|
+
console.log('Generic logging theme as file'.green.bold.underline);
|
61
|
+
|
62
|
+
// Load a theme from file
|
63
|
+
colors.setTheme(__dirname + '/../themes/generic-logging.js');
|
64
|
+
|
65
|
+
// outputs red text
|
66
|
+
console.log("this is an error".error);
|
67
|
+
|
68
|
+
// outputs yellow text
|
69
|
+
console.log("this is a warning".warn);
|
70
|
+
|
71
|
+
// outputs grey text
|
72
|
+
console.log("this is an input".input);
|
73
|
+
|
74
|
+
//console.log("Don't summon".zalgo)
|
@@ -0,0 +1,76 @@
|
|
1
|
+
var colors = require('../safe');
|
2
|
+
|
3
|
+
console.log(colors.yellow("First some yellow text"));
|
4
|
+
|
5
|
+
console.log(colors.yellow.underline("Underline that text"));
|
6
|
+
|
7
|
+
console.log(colors.red.bold("Make it bold and red"));
|
8
|
+
|
9
|
+
console.log(colors.rainbow("Double Raindows All Day Long"))
|
10
|
+
|
11
|
+
console.log(colors.trap("Drop the bass"))
|
12
|
+
|
13
|
+
console.log(colors.rainbow(colors.trap("DROP THE RAINBOW BASS")));
|
14
|
+
|
15
|
+
console.log(colors.bold.italic.underline.red('Chains are also cool.')); // styles not widely supported
|
16
|
+
|
17
|
+
|
18
|
+
console.log(colors.green('So ') + colors.underline('are') + ' ' + colors.inverse('inverse') + colors.yellow.bold(' styles! ')); // styles not widely supported
|
19
|
+
|
20
|
+
console.log(colors.zebra("Zebras are so fun!"));
|
21
|
+
|
22
|
+
console.log("This is " + colors.strikethrough("not") + " fun.");
|
23
|
+
|
24
|
+
|
25
|
+
console.log(colors.black.bgWhite('Background color attack!'));
|
26
|
+
console.log(colors.random('Use random styles on everything!'))
|
27
|
+
console.log(colors.america('America, Heck Yeah!'));
|
28
|
+
|
29
|
+
console.log('Setting themes is useful')
|
30
|
+
|
31
|
+
//
|
32
|
+
// Custom themes
|
33
|
+
//
|
34
|
+
//console.log('Generic logging theme as JSON'.green.bold.underline);
|
35
|
+
// Load theme with JSON literal
|
36
|
+
colors.setTheme({
|
37
|
+
silly: 'rainbow',
|
38
|
+
input: 'grey',
|
39
|
+
verbose: 'cyan',
|
40
|
+
prompt: 'grey',
|
41
|
+
info: 'green',
|
42
|
+
data: 'grey',
|
43
|
+
help: 'cyan',
|
44
|
+
warn: 'yellow',
|
45
|
+
debug: 'blue',
|
46
|
+
error: 'red'
|
47
|
+
});
|
48
|
+
|
49
|
+
// outputs red text
|
50
|
+
console.log(colors.error("this is an error"));
|
51
|
+
|
52
|
+
// outputs yellow text
|
53
|
+
console.log(colors.warn("this is a warning"));
|
54
|
+
|
55
|
+
// outputs grey text
|
56
|
+
console.log(colors.input("this is an input"));
|
57
|
+
|
58
|
+
|
59
|
+
// console.log('Generic logging theme as file'.green.bold.underline);
|
60
|
+
|
61
|
+
// Load a theme from file
|
62
|
+
colors.setTheme(__dirname + '/../themes/generic-logging.js');
|
63
|
+
|
64
|
+
// outputs red text
|
65
|
+
console.log(colors.error("this is an error"));
|
66
|
+
|
67
|
+
// outputs yellow text
|
68
|
+
console.log(colors.warn("this is a warning"));
|
69
|
+
|
70
|
+
// outputs grey text
|
71
|
+
console.log(colors.input("this is an input"));
|
72
|
+
|
73
|
+
// console.log(colors.zalgo("Don't summon him"))
|
74
|
+
|
75
|
+
|
76
|
+
|
package/lib/colors.js
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
The MIT License (MIT)
|
4
|
+
|
5
|
+
Original Library
|
6
|
+
- Copyright (c) Marak Squires
|
7
|
+
|
8
|
+
Additional functionality
|
9
|
+
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in
|
19
|
+
all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
27
|
+
THE SOFTWARE.
|
28
|
+
|
29
|
+
*/
|
30
|
+
|
31
|
+
var colors = {};
|
32
|
+
module['exports'] = colors;
|
33
|
+
|
34
|
+
colors.themes = {};
|
35
|
+
|
36
|
+
var ansiStyles = colors.styles = require('./styles');
|
37
|
+
var defineProps = Object.defineProperties;
|
38
|
+
|
39
|
+
colors.supportsColor = require('./system/supports-colors');
|
40
|
+
|
41
|
+
if (typeof colors.enabled === "undefined") {
|
42
|
+
colors.enabled = colors.supportsColor;
|
43
|
+
}
|
44
|
+
|
45
|
+
colors.stripColors = colors.strip = function(str){
|
46
|
+
return ("" + str).replace(/\x1B\[\d+m/g, '');
|
47
|
+
};
|
48
|
+
|
49
|
+
|
50
|
+
var stylize = colors.stylize = function stylize (str, style) {
|
51
|
+
return ansiStyles[style].open + str + ansiStyles[style].close;
|
52
|
+
}
|
53
|
+
|
54
|
+
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
55
|
+
var escapeStringRegexp = function (str) {
|
56
|
+
if (typeof str !== 'string') {
|
57
|
+
throw new TypeError('Expected a string');
|
58
|
+
}
|
59
|
+
return str.replace(matchOperatorsRe, '\\$&');
|
60
|
+
}
|
61
|
+
|
62
|
+
function build(_styles) {
|
63
|
+
var builder = function builder() {
|
64
|
+
return applyStyle.apply(builder, arguments);
|
65
|
+
};
|
66
|
+
builder._styles = _styles;
|
67
|
+
// __proto__ is used because we must return a function, but there is
|
68
|
+
// no way to create a function with a different prototype.
|
69
|
+
builder.__proto__ = proto;
|
70
|
+
return builder;
|
71
|
+
}
|
72
|
+
|
73
|
+
var styles = (function () {
|
74
|
+
var ret = {};
|
75
|
+
ansiStyles.grey = ansiStyles.gray;
|
76
|
+
Object.keys(ansiStyles).forEach(function (key) {
|
77
|
+
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
78
|
+
ret[key] = {
|
79
|
+
get: function () {
|
80
|
+
return build(this._styles.concat(key));
|
81
|
+
}
|
82
|
+
};
|
83
|
+
});
|
84
|
+
return ret;
|
85
|
+
})();
|
86
|
+
|
87
|
+
var proto = defineProps(function colors() {}, styles);
|
88
|
+
|
89
|
+
function applyStyle() {
|
90
|
+
var args = arguments;
|
91
|
+
var argsLen = args.length;
|
92
|
+
var str = argsLen !== 0 && String(arguments[0]);
|
93
|
+
if (argsLen > 1) {
|
94
|
+
for (var a = 1; a < argsLen; a++) {
|
95
|
+
str += ' ' + args[a];
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
if (!colors.enabled || !str) {
|
100
|
+
return str;
|
101
|
+
}
|
102
|
+
|
103
|
+
var nestedStyles = this._styles;
|
104
|
+
|
105
|
+
var i = nestedStyles.length;
|
106
|
+
while (i--) {
|
107
|
+
var code = ansiStyles[nestedStyles[i]];
|
108
|
+
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
109
|
+
}
|
110
|
+
|
111
|
+
return str;
|
112
|
+
}
|
113
|
+
|
114
|
+
function applyTheme (theme) {
|
115
|
+
for (var style in theme) {
|
116
|
+
(function(style){
|
117
|
+
colors[style] = function(str){
|
118
|
+
return colors[theme[style]](str);
|
119
|
+
};
|
120
|
+
})(style)
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
colors.setTheme = function (theme) {
|
125
|
+
if (typeof theme === 'string') {
|
126
|
+
try {
|
127
|
+
colors.themes[theme] = require(theme);
|
128
|
+
applyTheme(colors.themes[theme]);
|
129
|
+
return colors.themes[theme];
|
130
|
+
} catch (err) {
|
131
|
+
console.log(err);
|
132
|
+
return err;
|
133
|
+
}
|
134
|
+
} else {
|
135
|
+
applyTheme(theme);
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
function init() {
|
140
|
+
var ret = {};
|
141
|
+
Object.keys(styles).forEach(function (name) {
|
142
|
+
ret[name] = {
|
143
|
+
get: function () {
|
144
|
+
return build([name]);
|
145
|
+
}
|
146
|
+
};
|
147
|
+
});
|
148
|
+
return ret;
|
149
|
+
}
|
150
|
+
|
151
|
+
var sequencer = function sequencer (map, str) {
|
152
|
+
var exploded = str.split(""), i = 0;
|
153
|
+
exploded = exploded.map(map);
|
154
|
+
return exploded.join("");
|
155
|
+
};
|
156
|
+
|
157
|
+
// custom formatter methods
|
158
|
+
colors.trap = require('./custom/trap');
|
159
|
+
colors.zalgo = require('./custom/zalgo');
|
160
|
+
|
161
|
+
// maps
|
162
|
+
colors.maps = {};
|
163
|
+
colors.maps.america = require('./maps/america');
|
164
|
+
colors.maps.zebra = require('./maps/zebra');
|
165
|
+
colors.maps.rainbow = require('./maps/rainbow');
|
166
|
+
colors.maps.random = require('./maps/random')
|
167
|
+
|
168
|
+
for (var map in colors.maps) {
|
169
|
+
(function(map){
|
170
|
+
colors[map] = function (str) {
|
171
|
+
return sequencer(colors.maps[map], str);
|
172
|
+
}
|
173
|
+
})(map)
|
174
|
+
}
|
175
|
+
|
176
|
+
defineProps(colors, init());
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module['exports'] = function runTheTrap (text, options) {
|
2
|
+
var result = "";
|
3
|
+
text = text || "Run the trap, drop the bass";
|
4
|
+
text = text.split('');
|
5
|
+
var trap = {
|
6
|
+
a: ["\u0040", "\u0104", "\u023a", "\u0245", "\u0394", "\u039b", "\u0414"],
|
7
|
+
b: ["\u00df", "\u0181", "\u0243", "\u026e", "\u03b2", "\u0e3f"],
|
8
|
+
c: ["\u00a9", "\u023b", "\u03fe"],
|
9
|
+
d: ["\u00d0", "\u018a", "\u0500" , "\u0501" ,"\u0502", "\u0503"],
|
10
|
+
e: ["\u00cb", "\u0115", "\u018e", "\u0258", "\u03a3", "\u03be", "\u04bc", "\u0a6c"],
|
11
|
+
f: ["\u04fa"],
|
12
|
+
g: ["\u0262"],
|
13
|
+
h: ["\u0126", "\u0195", "\u04a2", "\u04ba", "\u04c7", "\u050a"],
|
14
|
+
i: ["\u0f0f"],
|
15
|
+
j: ["\u0134"],
|
16
|
+
k: ["\u0138", "\u04a0", "\u04c3", "\u051e"],
|
17
|
+
l: ["\u0139"],
|
18
|
+
m: ["\u028d", "\u04cd", "\u04ce", "\u0520", "\u0521", "\u0d69"],
|
19
|
+
n: ["\u00d1", "\u014b", "\u019d", "\u0376", "\u03a0", "\u048a"],
|
20
|
+
o: ["\u00d8", "\u00f5", "\u00f8", "\u01fe", "\u0298", "\u047a", "\u05dd", "\u06dd", "\u0e4f"],
|
21
|
+
p: ["\u01f7", "\u048e"],
|
22
|
+
q: ["\u09cd"],
|
23
|
+
r: ["\u00ae", "\u01a6", "\u0210", "\u024c", "\u0280", "\u042f"],
|
24
|
+
s: ["\u00a7", "\u03de", "\u03df", "\u03e8"],
|
25
|
+
t: ["\u0141", "\u0166", "\u0373"],
|
26
|
+
u: ["\u01b1", "\u054d"],
|
27
|
+
v: ["\u05d8"],
|
28
|
+
w: ["\u0428", "\u0460", "\u047c", "\u0d70"],
|
29
|
+
x: ["\u04b2", "\u04fe", "\u04fc", "\u04fd"],
|
30
|
+
y: ["\u00a5", "\u04b0", "\u04cb"],
|
31
|
+
z: ["\u01b5", "\u0240"]
|
32
|
+
}
|
33
|
+
text.forEach(function(c){
|
34
|
+
c = c.toLowerCase();
|
35
|
+
var chars = trap[c] || [" "];
|
36
|
+
var rand = Math.floor(Math.random() * chars.length);
|
37
|
+
if (typeof trap[c] !== "undefined") {
|
38
|
+
result += trap[c][rand];
|
39
|
+
} else {
|
40
|
+
result += c;
|
41
|
+
}
|
42
|
+
});
|
43
|
+
return result;
|
44
|
+
|
45
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
// please no
|
2
|
+
module['exports'] = function zalgo(text, options) {
|
3
|
+
text = text || " he is here ";
|
4
|
+
var soul = {
|
5
|
+
"up" : [
|
6
|
+
'̍', '̎', '̄', '̅',
|
7
|
+
'̿', '̑', '̆', '̐',
|
8
|
+
'͒', '͗', '͑', '̇',
|
9
|
+
'̈', '̊', '͂', '̓',
|
10
|
+
'̈', '͊', '͋', '͌',
|
11
|
+
'̃', '̂', '̌', '͐',
|
12
|
+
'̀', '́', '̋', '̏',
|
13
|
+
'̒', '̓', '̔', '̽',
|
14
|
+
'̉', 'ͣ', 'ͤ', 'ͥ',
|
15
|
+
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
16
|
+
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
17
|
+
'ͮ', 'ͯ', '̾', '͛',
|
18
|
+
'͆', '̚'
|
19
|
+
],
|
20
|
+
"down" : [
|
21
|
+
'̖', '̗', '̘', '̙',
|
22
|
+
'̜', '̝', '̞', '̟',
|
23
|
+
'̠', '̤', '̥', '̦',
|
24
|
+
'̩', '̪', '̫', '̬',
|
25
|
+
'̭', '̮', '̯', '̰',
|
26
|
+
'̱', '̲', '̳', '̹',
|
27
|
+
'̺', '̻', '̼', 'ͅ',
|
28
|
+
'͇', '͈', '͉', '͍',
|
29
|
+
'͎', '͓', '͔', '͕',
|
30
|
+
'͖', '͙', '͚', '̣'
|
31
|
+
],
|
32
|
+
"mid" : [
|
33
|
+
'̕', '̛', '̀', '́',
|
34
|
+
'͘', '̡', '̢', '̧',
|
35
|
+
'̨', '̴', '̵', '̶',
|
36
|
+
'͜', '͝', '͞',
|
37
|
+
'͟', '͠', '͢', '̸',
|
38
|
+
'̷', '͡', ' ҉'
|
39
|
+
]
|
40
|
+
},
|
41
|
+
all = [].concat(soul.up, soul.down, soul.mid),
|
42
|
+
zalgo = {};
|
43
|
+
|
44
|
+
function randomNumber(range) {
|
45
|
+
var r = Math.floor(Math.random() * range);
|
46
|
+
return r;
|
47
|
+
}
|
48
|
+
|
49
|
+
function is_char(character) {
|
50
|
+
var bool = false;
|
51
|
+
all.filter(function (i) {
|
52
|
+
bool = (i === character);
|
53
|
+
});
|
54
|
+
return bool;
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
function heComes(text, options) {
|
59
|
+
var result = '', counts, l;
|
60
|
+
options = options || {};
|
61
|
+
options["up"] = options["up"] || true;
|
62
|
+
options["mid"] = options["mid"] || true;
|
63
|
+
options["down"] = options["down"] || true;
|
64
|
+
options["size"] = options["size"] || "maxi";
|
65
|
+
text = text.split('');
|
66
|
+
for (l in text) {
|
67
|
+
if (is_char(l)) {
|
68
|
+
continue;
|
69
|
+
}
|
70
|
+
result = result + text[l];
|
71
|
+
counts = {"up" : 0, "down" : 0, "mid" : 0};
|
72
|
+
switch (options.size) {
|
73
|
+
case 'mini':
|
74
|
+
counts.up = randomNumber(8);
|
75
|
+
counts.min = randomNumber(2);
|
76
|
+
counts.down = randomNumber(8);
|
77
|
+
break;
|
78
|
+
case 'maxi':
|
79
|
+
counts.up = randomNumber(16) + 3;
|
80
|
+
counts.min = randomNumber(4) + 1;
|
81
|
+
counts.down = randomNumber(64) + 3;
|
82
|
+
break;
|
83
|
+
default:
|
84
|
+
counts.up = randomNumber(8) + 1;
|
85
|
+
counts.mid = randomNumber(6) / 2;
|
86
|
+
counts.down = randomNumber(8) + 1;
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
|
90
|
+
var arr = ["up", "mid", "down"];
|
91
|
+
for (var d in arr) {
|
92
|
+
var index = arr[d];
|
93
|
+
for (var i = 0 ; i <= counts[index]; i++) {
|
94
|
+
if (options[index]) {
|
95
|
+
result = result + soul[index][randomNumber(soul[index].length)];
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
// don't summon him
|
103
|
+
return heComes(text);
|
104
|
+
}
|