@sefinek/random-emoji 1.2.0 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## đŸ“„ăƒ»v1.3.0 (13.05.2022)
2
+ 1. Updated README.md file.
3
+ 2. Added new function `new kaomojis()` with random kaomoji from my [API](https://api.skiffybot.pl). See examples: [[1](https://github.com/sefinek24/random-emoji/blob/main/test.js)] [[2](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis)]
4
+ 3. Other changes to [index.js](https://github.com/sefinek24/random-emoji/blob/main/index.js) file.
5
+
1
6
  ## đŸ“„ăƒ»v1.2.0 (12.05.2022)
2
7
  1. Updated CHANGELOG.md, README.md and package.json.
3
8
  2. Added new function `circles()` with random circles.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
- <h1>About this package</h1>
3
- <p>Returns a random emoticon, its name and type. đŸ± 🙀 ❀</p>
2
+ <h1>đŸ± About this package 🙀</h1>
3
+ <p>Returns a random emoticons (name, type) and kaomojis.</p>
4
4
  <a href="https://www.npmjs.com/package/@sefinek/random-emoji" target="_blank" title="random-emoji - npm" style="text-decoration:none">
5
5
  <img src="https://img.shields.io/npm/dt/@sefinek/random-emoji.svg?maxAge=3600" alt="The number of downloads">
6
6
  <img src="https://img.shields.io/github/issues/sefinek24/random-emoji" alt="Issues">
@@ -44,18 +44,62 @@ console.log(`Name: ${heart.name}; Emoji: ${heart.content};`);
44
44
  ```
45
45
 
46
46
  ## đŸ˜» ‱ Usage
47
+ | Function | Description |
48
+ |-----------------------------------------------------------------------------------|--------------------------------------------------------------|
49
+ | [emojis](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | Random emoji with name and type |
50
+ | [unicode](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | A single emote |
51
+ | [cats](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | Return random cat |
52
+ | [hearts](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | Return random heart |
53
+ | [circles](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | Return random circle |
54
+ | [**new** kaomojis](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis) | Return random kaomojis from [API](https://api.skiffybot.xyz) |
55
+
56
+ ## ⛩ ‱ Kaomojis
57
+ ### » Async/await example
58
+ ```js
59
+ const random = require('@sefinek/random-emoji');
60
+ const kaomoji = new random.kaomojis();
61
+
62
+ async function example() {
63
+ const uwu = await kaomoji.uwu();
64
+ console.log(uwu.message);
65
+ }
66
+
67
+ example(); // Execute function
68
+ ```
69
+
70
+ ### » Promise example
47
71
  ```js
48
- emojis() // Random emoji with name and type
49
- unicode() // A single emote
50
- cats() // Return random cat
51
- hearts() // Return random heart
52
- circles() // Return random circle
72
+ const random = require('@sefinek/random-emoji');
73
+ const kaomoji = new random.kaomojis();
74
+
75
+ kaomoji.love().then(data => console.log(data));
53
76
  ```
54
77
 
78
+ ### » The returned object from [API](https://api.skiffybot.xyz)
79
+ ```json
80
+ {
81
+ "success": true,
82
+ "status": 200,
83
+ "category": "kaomoji",
84
+ "endpoint": "uwu",
85
+ "message": "đŸ…€đŸ…ŠđŸ…€"
86
+ }
87
+ ```
88
+
89
+ ### » Kaomoji endpoints
90
+ | Function | Example |
91
+ |-------------------------------------------------------|-----------|
92
+ | [cat](https://api.skiffybot.xyz/api/v1/kaomoji/cat) | (=^-ω-^=) |
93
+ | [dog](https://api.skiffybot.xyz/api/v1/kaomoji/dog) | àŹ˜(âˆȘăƒ»ï»Œăƒ»âˆȘ)àŹ“ |
94
+ | [owo](https://api.skiffybot.xyz/api/v1/kaomoji/owo) | 𝓞𝔀𝓞 |
95
+ | [uwu](https://api.skiffybot.xyz/api/v1/kaomoji/uwu) | 𝕌𝕹𝕌 |
96
+ | [love](https://api.skiffybot.xyz/api/v1/kaomoji/love) | ăƒœ(♡‿♡)ノ |
97
+
55
98
  ## 📝 ‱ Changelog
56
- > <a href="https://github.com/sefinek24/random-emoji/blob/main/CHANGELOG.md" target="_blank" title="random-emoji/CHANGELOG.md at main · sefinek24/random-emoji">https://github.com/sefinek24/random-emoji/blob/main/CHANGELOG.md</a>
99
+ > https://github.com/sefinek24/random-emoji/blob/main/CHANGELOG.md
57
100
 
58
101
  ## đŸ€ ‱ Help
59
- Open new <a href="https://github.com/sefinek24/random-emoji/issues/new/choose" target="_blank">Issue</a> on Github.
102
+ Open new [Issue](https://github.com/sefinek24/random-emoji/issues/new/choose) on GitHub.
60
103
 
61
- ### Thank you ❀
104
+ ## ⭐ ‱ Thank you
105
+ Give a [star](https://github.com/sefinek24/random-emoji) if you can on GitHub page.
@@ -0,0 +1 @@
1
+ {"cat":"kaomoji/cat","dog":"kaomoji/dog","owo":"kaomoji/owo","uwu":"kaomoji/uwu","love":"kaomoji/love"}
package/index.js CHANGED
@@ -3,9 +3,50 @@ const unicode = require('./json/unicode.json');
3
3
  const cats = require('./json/cats.json');
4
4
  const hearts = require('./json/hearts.json');
5
5
  const circles = require('./json/circles.json');
6
+ const { get } = require('https');
7
+ const { URL, URLSearchParams } = require('url');
8
+ const endpoints = require('./api/endpoints.json');
6
9
 
7
- exports.emojis = () => emojis[Math.floor(Math.random() * emojis.length)];
8
- exports.unicode = () => unicode[Math.floor(Math.random() * unicode.length)];
9
- exports.cats = () => cats[Math.floor(Math.random() * cats.length)];
10
- exports.hearts = () => hearts[Math.floor(Math.random() * hearts.length)];
11
- exports.circles = () => circles[Math.floor(Math.random() * circles.length)];
10
+ function getContent(url) {
11
+ return new Promise((resolve, reject) => {
12
+ get(url, res => {
13
+ const { statusCode } = res;
14
+ if (statusCode !== 200) {
15
+ res.resume();
16
+ reject(`Request failed with status code ${statusCode}.`);
17
+ }
18
+
19
+ res.setEncoding('utf8');
20
+ let rawData = '';
21
+ res.on('data', chunk => {rawData += chunk;});
22
+ res.on('end', () => {
23
+ try {
24
+ resolve(JSON.parse(rawData));
25
+ } catch (err) {
26
+ reject(err.message);
27
+ }
28
+ });
29
+ }).on('error', err => reject(err.message));
30
+ });
31
+ }
32
+
33
+ class SkiffyBOT {
34
+ constructor() {
35
+ Object.keys(endpoints).forEach(endpoint => {
36
+ this[endpoint] = async function(queryParams = '') {
37
+ const url = new URL(`https://api.skiffybot.xyz/api/v1/${endpoints[endpoint]}`);
38
+ queryParams !== '' ? url.search = new URLSearchParams(queryParams) : '';
39
+ return await getContent(url.toString());
40
+ };
41
+ });
42
+ }
43
+ }
44
+
45
+ module.exports = {
46
+ emojis: () => emojis[Math.floor(Math.random() * emojis.length)],
47
+ unicode: () => unicode[Math.floor(Math.random() * unicode.length)],
48
+ cats: () => cats[Math.floor(Math.random() * cats.length)],
49
+ hearts: () => hearts[Math.floor(Math.random() * hearts.length)],
50
+ circles: () => circles[Math.floor(Math.random() * circles.length)],
51
+ kaomojis: SkiffyBOT,
52
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sefinek/random-emoji",
3
- "version": "1.2.0",
4
- "description": "Returns a random emoticon, its name and type.",
3
+ "version": "1.3.0",
4
+ "description": "Returns a random emoticons (name, type) and kaomojis.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node test.js"
package/test.js CHANGED
@@ -1,4 +1,4 @@
1
- const { unicode, emojis, cats, hearts, circles } = require('./index.js');
1
+ const { unicode, emojis, cats, hearts, circles, kaomojis } = require('./index.js');
2
2
 
3
3
  // A single emote
4
4
  console.log(unicode());
@@ -17,4 +17,14 @@ console.log(`Name: ${heart.name}; Emoji: ${heart.content};`);
17
17
 
18
18
  // Random circles
19
19
  const circle = circles();
20
- console.log(`Name: ${circle.name}; Emoji: ${circle.content};`);
20
+ console.log(`Name: ${circle.name}; Emoji: ${circle.content};`);
21
+
22
+ // Random kaomoji
23
+ (async () => {
24
+ const kaomoji = new kaomojis();
25
+ const kaoCat = await kaomoji.cat();
26
+ console.log(`Cat face: ${kaoCat.message}`);
27
+
28
+ const uwu = await kaomoji.uwu();
29
+ console.log(`Random UwU: ${uwu.message}`);
30
+ })();