aamoji 0.0.0

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.
Files changed (4) hide show
  1. package/README.md +62 -0
  2. package/ascii-map.js +235 -0
  3. package/index.js +76 -0
  4. package/package.json +25 -0
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # aamoji
2
+
3
+ Return an ASCII representation for each emoji.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install aamoji
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ const aamoji = require('aamoji');
15
+
16
+ aamoji('๐Ÿ˜€'); // ':D'
17
+ aamoji('โค๏ธ'); // '<3'
18
+ aamoji('๐Ÿ‘'); // '(b)'
19
+ aamoji('๐Ÿฆ„'); // '(unicorn)'
20
+
21
+ // Unknown emoji returns itself by default.
22
+ aamoji('๐Ÿซฅ'); // '๐Ÿซฅ'
23
+ aamoji('๐Ÿซฅ', '?'); // '?' (with fallback)
24
+
25
+ // Replace every known emoji inside a string.
26
+ aamoji.replace('hello ๐Ÿ˜€ world โค๏ธ');
27
+ // 'hello :D world <3'
28
+
29
+ // Check whether a mapping exists.
30
+ aamoji.has('๐Ÿ˜€'); // true
31
+
32
+ // Get the full map.
33
+ aamoji.all(); // { '๐Ÿ˜€': ':D', ... }
34
+ ```
35
+
36
+ ## API
37
+
38
+ ### `aamoji(emoji, fallback?)`
39
+
40
+ Returns the ASCII string for `emoji`. If the emoji is not in the map, returns
41
+ `fallback` when provided, otherwise the original emoji.
42
+
43
+ ### `aamoji.replace(str)`
44
+
45
+ Replaces every known emoji in `str` with its ASCII equivalent. Unknown
46
+ characters are left untouched.
47
+
48
+ ### `aamoji.has(emoji)`
49
+
50
+ Returns `true` if the emoji has a mapping.
51
+
52
+ ### `aamoji.all()`
53
+
54
+ Returns a shallow copy of the full emoji-to-ASCII map.
55
+
56
+ ### `aamoji.map`
57
+
58
+ The underlying map object (do not mutate).
59
+
60
+ ## License
61
+
62
+ MIT
package/ascii-map.js ADDED
@@ -0,0 +1,235 @@
1
+ 'use strict';
2
+
3
+ // Mapping of common emojis to ASCII representations.
4
+ const asciiMap = {
5
+ '๐Ÿ˜€': ':D',
6
+ '๐Ÿ˜ƒ': ':D',
7
+ '๐Ÿ˜„': ':D',
8
+ '๐Ÿ˜': '=D',
9
+ '๐Ÿ˜†': 'XD',
10
+ '๐Ÿ˜…': '^_^;',
11
+ '๐Ÿคฃ': 'XDD',
12
+ '๐Ÿ˜‚': ":')",
13
+ '๐Ÿ™‚': ':)',
14
+ '๐Ÿ™ƒ': '(:',
15
+ '๐Ÿ˜‰': ';)',
16
+ '๐Ÿ˜Š': ':)',
17
+ '๐Ÿ˜‡': 'O:)',
18
+ '๐Ÿฅฐ': '<3',
19
+ '๐Ÿ˜': ':*)',
20
+ '๐Ÿคฉ': '*_*',
21
+ '๐Ÿ˜˜': ':-*',
22
+ '๐Ÿ˜—': ':*',
23
+ '๐Ÿ˜š': ':*',
24
+ '๐Ÿ˜™': ':*',
25
+ '๐Ÿ˜‹': ':P',
26
+ '๐Ÿ˜›': ':P',
27
+ '๐Ÿ˜œ': ';P',
28
+ '๐Ÿคช': 'xP',
29
+ '๐Ÿ˜': 'xP',
30
+ '๐Ÿค‘': '$_$',
31
+ '๐Ÿค—': '>:)',
32
+ '๐Ÿค”': ':?',
33
+ '๐Ÿค': ':X',
34
+ '๐Ÿคจ': ':/',
35
+ '๐Ÿ˜': ':|',
36
+ '๐Ÿ˜‘': '-_-',
37
+ '๐Ÿ˜ถ': ':x',
38
+ '๐Ÿ˜': ';)',
39
+ '๐Ÿ˜’': ':/',
40
+ '๐Ÿ™„': '-_-',
41
+ '๐Ÿ˜ฌ': ':E',
42
+ '๐Ÿคฅ': ':-)',
43
+ '๐Ÿ˜Œ': 'u_u',
44
+ '๐Ÿ˜”': ':(',
45
+ '๐Ÿ˜ช': '-.-',
46
+ '๐Ÿคค': ":'P",
47
+ '๐Ÿ˜ด': 'Zzz',
48
+ '๐Ÿ˜ท': ':-#',
49
+ '๐Ÿค’': ':-S',
50
+ '๐Ÿค•': ':-S',
51
+ '๐Ÿคข': ':-&',
52
+ '๐Ÿคฎ': ':-X',
53
+ '๐Ÿคง': ':-{',
54
+ '๐Ÿฅต': '>_<',
55
+ '๐Ÿฅถ': '*_*',
56
+ '๐Ÿฅด': '@_@',
57
+ '๐Ÿ˜ต': 'X_X',
58
+ '๐Ÿคฏ': 'O_O!',
59
+ '๐Ÿค ': ':-D',
60
+ '๐Ÿฅณ': ':D*',
61
+ '๐Ÿ˜Ž': 'B)',
62
+ '๐Ÿค“': '8)',
63
+ '๐Ÿง': ':-?',
64
+ '๐Ÿ˜•': ':/',
65
+ '๐Ÿ˜Ÿ': ':(',
66
+ '๐Ÿ™': ':(',
67
+ 'โ˜น๏ธ': ':(',
68
+ '๐Ÿ˜ฎ': ':o',
69
+ '๐Ÿ˜ฏ': ':o',
70
+ '๐Ÿ˜ฒ': ':O',
71
+ '๐Ÿ˜ณ': ':$',
72
+ '๐Ÿฅบ': ":'(",
73
+ '๐Ÿ˜ฆ': 'D:',
74
+ '๐Ÿ˜ง': 'D:',
75
+ '๐Ÿ˜จ': 'D:',
76
+ '๐Ÿ˜ฐ': "D':",
77
+ '๐Ÿ˜ฅ': ":'(",
78
+ '๐Ÿ˜ข': ":'(",
79
+ '๐Ÿ˜ญ': ":'((",
80
+ '๐Ÿ˜ฑ': 'D:<',
81
+ '๐Ÿ˜–': '>_<',
82
+ '๐Ÿ˜ฃ': '>_<',
83
+ '๐Ÿ˜ž': ':(',
84
+ '๐Ÿ˜“': ":'|",
85
+ '๐Ÿ˜ฉ': 'X(',
86
+ '๐Ÿ˜ซ': 'X(',
87
+ '๐Ÿฅฑ': '(=_=)',
88
+ '๐Ÿ˜ค': '>:|',
89
+ '๐Ÿ˜ก': '>:(',
90
+ '๐Ÿ˜ ': '>:(',
91
+ '๐Ÿคฌ': '#@!',
92
+ '๐Ÿ˜ˆ': '}:)',
93
+ '๐Ÿ‘ฟ': '}:(',
94
+ '๐Ÿ’€': 'X_X',
95
+ 'โ˜ ๏ธ': 'X_X',
96
+ '๐Ÿ’ฉ': '~~',
97
+ '๐Ÿคก': ':o)',
98
+ '๐Ÿ‘น': '>:E',
99
+ '๐Ÿ‘บ': '>:(',
100
+ '๐Ÿ‘ป': 'Boo!',
101
+ '๐Ÿ‘ฝ': '(o.o)',
102
+ '๐Ÿ‘พ': '[o_o]',
103
+ '๐Ÿค–': '[:|]',
104
+ 'โค๏ธ': '<3',
105
+ '๐Ÿงก': '<3',
106
+ '๐Ÿ’›': '<3',
107
+ '๐Ÿ’š': '<3',
108
+ '๐Ÿ’™': '<3',
109
+ '๐Ÿ’œ': '<3',
110
+ '๐Ÿ–ค': '</3',
111
+ '๐Ÿค': '<3',
112
+ '๐ŸคŽ': '<3',
113
+ '๐Ÿ’”': '</3',
114
+ 'โฃ๏ธ': '<3!',
115
+ '๐Ÿ’•': '<3<3',
116
+ '๐Ÿ’ž': '<3~',
117
+ '๐Ÿ’“': '<3*',
118
+ '๐Ÿ’—': '<3+',
119
+ '๐Ÿ’–': '*<3*',
120
+ '๐Ÿ’˜': '<-3',
121
+ '๐Ÿ’': '[<3]',
122
+ '๐Ÿ‘': '(b)',
123
+ '๐Ÿ‘Ž': '(n)',
124
+ '๐Ÿ‘Œ': '(ok)',
125
+ 'โœŒ๏ธ': '(v)',
126
+ '๐Ÿคž': '(x)',
127
+ '๐Ÿค™': '(call)',
128
+ '๐Ÿ‘‹': '(wave)',
129
+ '๐Ÿ™Œ': '\\o/',
130
+ '๐Ÿ‘': '*clap*',
131
+ '๐Ÿ™': '_/\\_',
132
+ '๐Ÿ’ช': '(flex)',
133
+ '๐Ÿค': '(shake)',
134
+ 'โœŠ': '(fist)',
135
+ '๐Ÿ‘Š': '(punch)',
136
+ 'โ˜€๏ธ': '(*)',
137
+ '๐ŸŒ™': '(C',
138
+ 'โญ': '*',
139
+ '๐ŸŒŸ': '*+*',
140
+ 'โœจ': '*~*',
141
+ 'โšก': '/\\/',
142
+ '๐Ÿ”ฅ': '(fire)',
143
+ '๐Ÿ’ง': "o'",
144
+ '๐ŸŒˆ': '(rainbow)',
145
+ 'โ˜๏ธ': '(cloud)',
146
+ 'โ˜”': '(rain)',
147
+ 'โ„๏ธ': '*snow*',
148
+ 'โ›„': '(snowman)',
149
+ '๐ŸŒ': '(O)',
150
+ '๐ŸŒŽ': '(O)',
151
+ '๐ŸŒ': '(O)',
152
+ '๐ŸŽ': '(apple)',
153
+ '๐ŸŠ': '(orange)',
154
+ '๐ŸŒ': '(banana)',
155
+ '๐Ÿ“': '(strawberry)',
156
+ '๐Ÿ‰': '(watermelon)',
157
+ '๐Ÿ‡': '(grapes)',
158
+ '๐Ÿ•': '(pizza)',
159
+ '๐Ÿ”': '(burger)',
160
+ '๐ŸŸ': '(fries)',
161
+ '๐ŸŒฎ': '(taco)',
162
+ '๐Ÿฃ': '(sushi)',
163
+ '๐Ÿฉ': '(donut)',
164
+ '๐Ÿช': '(cookie)',
165
+ '๐ŸŽ‚': '(cake)',
166
+ 'โ˜•': '(coffee)',
167
+ '๐Ÿบ': '(beer)',
168
+ '๐Ÿท': '(wine)',
169
+ '๐Ÿถ': '(dog)',
170
+ '๐Ÿฑ': '(cat)',
171
+ '๐Ÿญ': '(mouse)',
172
+ '๐Ÿฐ': '(bunny)',
173
+ '๐ŸฆŠ': '(fox)',
174
+ '๐Ÿป': '(bear)',
175
+ '๐Ÿผ': '(panda)',
176
+ '๐Ÿจ': '(koala)',
177
+ '๐Ÿฏ': '(tiger)',
178
+ '๐Ÿฆ': '(lion)',
179
+ '๐Ÿฎ': '(cow)',
180
+ '๐Ÿท': '(pig)',
181
+ '๐Ÿธ': '(frog)',
182
+ '๐Ÿต': '(monkey)',
183
+ '๐Ÿ™ˆ': 'see-no',
184
+ '๐Ÿ™‰': 'hear-no',
185
+ '๐Ÿ™Š': 'speak-no',
186
+ '๐Ÿฆ„': '(unicorn)',
187
+ '๐Ÿ”': '(chicken)',
188
+ '๐Ÿง': '(penguin)',
189
+ '๐Ÿฆ': '(bird)',
190
+ '๐Ÿ': '(bee)',
191
+ '๐Ÿฆ‹': '(butterfly)',
192
+ '๐Ÿข': '(turtle)',
193
+ '๐Ÿ': '~S~',
194
+ '๐Ÿ™': '(octopus)',
195
+ '๐Ÿณ': '(whale)',
196
+ '๐Ÿฌ': '(dolphin)',
197
+ '๐ŸŸ': '><(((>',
198
+ '๐Ÿš—': '(car)',
199
+ '๐Ÿš•': '(taxi)',
200
+ '๐ŸšŒ': '(bus)',
201
+ '๐Ÿš‘': '(ambulance)',
202
+ '๐Ÿš’': '(firetruck)',
203
+ '๐Ÿšฒ': '(bike)',
204
+ 'โœˆ๏ธ': '(plane)',
205
+ '๐Ÿš€': '(rocket)',
206
+ '๐Ÿ›ธ': '(ufo)',
207
+ 'โšฝ': '(o)',
208
+ '๐Ÿ€': '(O)',
209
+ '๐ŸŽฎ': '(gamepad)',
210
+ '๐ŸŽฒ': '[::]',
211
+ '๐ŸŽต': '(note)',
212
+ '๐ŸŽถ': '(notes)',
213
+ '๐ŸŽธ': '(guitar)',
214
+ '๐ŸŽค': '(mic)',
215
+ '๐Ÿ“ฑ': '[phone]',
216
+ '๐Ÿ’ป': '[laptop]',
217
+ 'โŒจ๏ธ': '[keyboard]',
218
+ '๐Ÿ–ฅ๏ธ': '[pc]',
219
+ '๐Ÿ“ท': '[camera]',
220
+ '๐Ÿ’ก': '(idea)',
221
+ '๐Ÿ”‘': '-o<',
222
+ '๐Ÿ”’': '[lock]',
223
+ 'โœ‰๏ธ': '[mail]',
224
+ '๐Ÿ“ฆ': '[box]',
225
+ 'โœ…': '[x]',
226
+ 'โŒ': '[X]',
227
+ 'โš ๏ธ': '(!)',
228
+ 'โ“': '(?)',
229
+ 'โ—': '(!)',
230
+ '๐Ÿ’ฏ': '100',
231
+ '๐ŸŽ‰': '*party*',
232
+ '๐ŸŽ': '[gift]'
233
+ };
234
+
235
+ module.exports = asciiMap;
package/index.js ADDED
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ const asciiMap = require('./ascii-map.js');
4
+
5
+ function escapeRegex(str) {
6
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
7
+ }
8
+
9
+ // Build a single regex matching any mapped emoji. Sort by length descending so
10
+ // multi-codepoint emojis (e.g. 'โค๏ธ' = U+2764 + U+FE0F) match before shorter
11
+ // variants ('โค').
12
+ const replaceRegex = new RegExp(
13
+ Object.keys(asciiMap)
14
+ .sort((a, b) => b.length - a.length)
15
+ .map(escapeRegex)
16
+ .join('|'),
17
+ 'g'
18
+ );
19
+
20
+ /**
21
+ * Convert a single emoji to its ASCII representation.
22
+ *
23
+ * @param {string} emoji - The emoji character.
24
+ * @param {string} [fallback] - Optional fallback when the emoji is unknown.
25
+ * Defaults to the original emoji string.
26
+ * @returns {string} ASCII representation, or the fallback if not mapped.
27
+ */
28
+ function aamoji(emoji, fallback) {
29
+ if (typeof emoji !== 'string') {
30
+ throw new TypeError('aamoji: expected a string');
31
+ }
32
+ if (Object.prototype.hasOwnProperty.call(asciiMap, emoji)) {
33
+ return asciiMap[emoji];
34
+ }
35
+ return fallback === undefined ? emoji : fallback;
36
+ }
37
+
38
+ /**
39
+ * Replace every known emoji in a string with its ASCII equivalent.
40
+ *
41
+ * @param {string} input - Source string that may contain emojis.
42
+ * @returns {string} String with mapped emojis replaced by ASCII.
43
+ */
44
+ function replace(input) {
45
+ if (typeof input !== 'string') {
46
+ throw new TypeError('aamoji.replace: expected a string');
47
+ }
48
+ return input.replace(replaceRegex, (match) => asciiMap[match]);
49
+ }
50
+
51
+ /**
52
+ * Check whether an emoji has an ASCII mapping.
53
+ *
54
+ * @param {string} emoji
55
+ * @returns {boolean}
56
+ */
57
+ function has(emoji) {
58
+ return Object.prototype.hasOwnProperty.call(asciiMap, emoji);
59
+ }
60
+
61
+ /**
62
+ * Get a shallow copy of the full emoji-to-ASCII map.
63
+ *
64
+ * @returns {Record<string, string>}
65
+ */
66
+ function all() {
67
+ return { ...asciiMap };
68
+ }
69
+
70
+ aamoji.replace = replace;
71
+ aamoji.has = has;
72
+ aamoji.all = all;
73
+ aamoji.map = asciiMap;
74
+
75
+ module.exports = aamoji;
76
+ module.exports.default = aamoji;
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "aamoji",
3
+ "version": "0.0.0",
4
+ "description": "Returns an ASCII representation for each emoji.",
5
+ "main": "index.js",
6
+ "exports": {
7
+ ".": "./index.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "ascii-map.js",
12
+ "README.md"
13
+ ],
14
+ "keywords": [
15
+ "emoji",
16
+ "ascii",
17
+ "aamoji",
18
+ "ascii-art",
19
+ "emoticon"
20
+ ],
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "test": "node test.js"
24
+ }
25
+ }