@sefinek/random-emoji 2.0.4 → 2.2.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 ADDED
@@ -0,0 +1,105 @@
1
+ ## 📥・v2.2.0 (06.12.2025)
2
+
3
+ ### ⚡ Performance
4
+ 1. Optimized code with arrow functions and `for...of` loops.
5
+ 2. Refactored Promise handling in `getContent()`.
6
+ 3. Added `getRandomElement()` helper function.
7
+
8
+ ### ✨ Changes
9
+ 1. Updated to `node:https` protocol.
10
+ 2. Improved error handling and JSON parsing.
11
+ 3. Rewritten TypeScript definitions with proper CommonJS export structure.
12
+ 4. Code quality improvements.
13
+
14
+ ### 🧪 Testing
15
+ 1. Added Jest test suite with 28 tests.
16
+
17
+
18
+ ## 📥・v2.1.0 (20.12.2023)
19
+
20
+ ### 🎉 Added
21
+ 1. New function `<random>.squares` for retrieving random squares.
22
+ 2. Added a new example ([examples/table.js](example/table.js)) demonstrating the use of module functions in a table format.
23
+
24
+ ### ✨ Changes
25
+ 1. General code quality improvements.
26
+ 2. Enhanced type definitions in [`index.d.ts`](index.d.ts) and expanded documentation.
27
+ 3. Improved the emoji randomization mechanism.
28
+ 4. Updated example files in the [`examples`](example) directory.
29
+
30
+
31
+ ## 📥・v2.0.2/v2.0.3 (08.11.2023)
32
+
33
+ ### 🎉 Added
34
+ 1. `<random>.version`
35
+
36
+ ### ✨ Changes
37
+ 1. Removed `README_PL.md`.
38
+ 2. Updated add added new types to `index.d.ts` file.
39
+ 3. Now this module uses only native module (like `https`).
40
+ 4. Added new headers for better safety etc.
41
+
42
+ ### 🌠 Migration
43
+ 1. Changed `new random.kaomojis()` to `new random.Kaomojis()`.
44
+
45
+
46
+ ## 📥・v1.4.6 (11.03.2023)
47
+ 1. Updated to **v2** release of API.
48
+
49
+
50
+ ## 📥・v1.4.5 (09.10.2022)
51
+ 1. Fixed URLs.
52
+
53
+
54
+ ## 📥・v1.4.4 (02.10.2022)
55
+ 1. Fixed URLs.
56
+
57
+
58
+ ## 📥・v1.4.3 (19.09.2022)
59
+ 1. Small changes in `index.d.ts` etc.
60
+
61
+
62
+ ## 📥・v1.4.2 (05.06.2022)
63
+ 1. Added typings.
64
+ 2. Small fixes in `README.md` and `README_PL.md`.
65
+
66
+
67
+ ## 📥・v1.4.1 (02.06.2022)
68
+ 1. Small changes.
69
+
70
+
71
+ ## 📥・v1.4.0 (15.05.2022)
72
+ 1. Added new function `foods()` with random foods.
73
+ 2. Fixes in `new kaomojis()`.
74
+ 3. Small fixes in README.md.
75
+ 4. Added Poland version of README.md file.
76
+
77
+
78
+ ## 📥・v1.3.0 (13.05.2022)
79
+ 1. Updated README.md file.
80
+ 2. Added `new kaomojis()` with random kaomoji from my [API](https://api.sefinek.net). See examples: [[1](https://github.com/sefinek/random-emoji/blob/main/test.js)] [[2](https://github.com/sefinek/random-emoji#%EF%B8%8F--kaomojis)]
81
+ 3. Other changes to [index.js](https://github.com/sefinek/random-emoji/blob/main/index.js) file.
82
+
83
+
84
+ ## 📥・v1.2.0 (12.05.2022)
85
+ 1. Updated CHANGELOG.md, README.md and package.json.
86
+ 2. Added new function `circles()` with random circles.
87
+ 3. Removed `.slashes`.
88
+
89
+
90
+ ## 📥・v1.1.1 (11.05.2022)
91
+ 1. Added new function `hearts()` with random hearts.
92
+
93
+
94
+ ## 📥・v1.0.1 (08.05.2022)
95
+ 1. Added new function `cats()` with random cat emojis.
96
+ 2. Added **CHANGELOG.md** file.
97
+ 3. Changes:
98
+ ```diff
99
+ - emoji()
100
+ + emojis()
101
+ ```
102
+
103
+
104
+ ## 📥・v0.1.0 (07.05.2022)
105
+ First release.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022-2023 Sefinek
3
+ Copyright (c) 2022-2025 Sefinek
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -3,13 +3,20 @@
3
3
  <p>Constantly supported Node.js module providing random emojis, including their names and categories. The module also offers random Japanese 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
- <img src="https://img.shields.io/github/issues/sefinek24/random-emoji" alt="Issues">
7
- <img src="https://img.shields.io/github/last-commit/sefinek24/random-emoji" alt="Last commit">
8
- <img src="https://img.shields.io/github/commit-activity/w/sefinek24/random-emoji" alt="Commit activity">
9
- <img src="https://img.shields.io/github/languages/code-size/sefinek24/random-emoji" alt="Code size">
6
+ <img src="https://img.shields.io/github/issues/sefinek/random-emoji" alt="Issues">
7
+ <img src="https://img.shields.io/github/last-commit/sefinek/random-emoji" alt="Last commit">
8
+ <img src="https://img.shields.io/github/commit-activity/w/sefinek/random-emoji" alt="Commit activity">
9
+ <img src="https://img.shields.io/github/languages/code-size/sefinek/random-emoji" alt="Code size">
10
10
  </a>
11
11
  </div>
12
12
 
13
+ Do you have any questions or want to receive notifications about important changes or new features in my repositories?
14
+ Join my [Discord server](https://discord.gg/S7NDzCzQTg)! If you don't use Discord, you can also open an issue on GitHub.
15
+
16
+ The project is released under the [MIT license](LICENSE) — you can do whatever you want with it.
17
+ If you like this repository, leave a star ⭐. Thank you!
18
+
19
+
13
20
  ## 📥 • Installation
14
21
  ```bash
15
22
  npm install @sefinek/random-emoji
@@ -17,15 +24,16 @@ npm install @sefinek/random-emoji
17
24
 
18
25
 
19
26
  ## 😻 • Usage
20
- | Function | Description |
21
- |----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
22
- | [unicode](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L4) | A single emoji |
23
- | [emojis](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L7) | Random emoji with name and type |
24
- | [cats](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L11) | Return random cat |
25
- | [hearts](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L14) | Return random heart |
26
- | [foods](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L18) | Return random food |
27
- | [circles](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L22) | Return random circle |
28
- | [**new** Kaomojis](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L28) | Return random kaomojis from [API](https://api.sefinek.net) |
27
+ | Function | Description |
28
+ |-----------------------------------------------------------------------------|-------------------------------------------------------------|
29
+ | [unicode](https://github.com/sefinek/random-emoji/blob/main/example.js#L4) | Get a single emoji |
30
+ | [emojis](https://github.com/sefinek/random-emoji/blob/main/example.js#L7) | Get a random emoji with its name and type |
31
+ | [cats](https://github.com/sefinek/random-emoji/blob/main/example.js#L11) | Get a random cat emoji |
32
+ | [hearts](https://github.com/sefinek/random-emoji/blob/main/example.js#L15) | Get a random heart emoji |
33
+ | [foods](https://github.com/sefinek/random-emoji/blob/main/example.js#L19) | Get a random food emoji |
34
+ | [circles](https://github.com/sefinek/random-emoji/blob/main/example.js#L23) | Get a random circle emoji |
35
+ | [squares](https://github.com/sefinek/random-emoji/blob/main/example.js#L27) | Get a random square emoji |
36
+ | [Kaomojis](#kaomoji-endpoints) | Get random kaomojis from the [API](https://api.sefinek.net) |
29
37
 
30
38
 
31
39
  ## 😼 • Examples
@@ -33,18 +41,17 @@ npm install @sefinek/random-emoji
33
41
  const random = require('@sefinek/random-emoji');
34
42
 
35
43
  // 1. A single emoji
36
- console.log(random.unicode());
37
- // Output: 🥰
44
+ console.log(random.unicode()); // 🥰
38
45
 
39
- // 2. Random emoji with name and type
46
+ // 2. Random emoji along with its visual representation, name, and category
40
47
  const emoji = random.emojis();
41
- console.log(`Name: ${emoji.name}; Emoji: ${emoji.content};`);
42
- // Output: Name: jack-o-lantern; Emoji: 🎃;
48
+ console.log(`Emoji: ${emoji.content}; Name: ${emoji.name}; Type: ${emoji.type}`);
49
+ // Emoji: 🐶; Name: Dog Face; Type: animal
43
50
 
44
51
  // 3. Random cat
45
52
  const cat = random.cats();
46
- console.log(`Name: ${cat.name}; Emoji: ${cat.content};`);
47
- // Output: Name: smiley_cat; Emoji: 😺;
53
+ console.log(`Emoji: ${cat.content}; Name: ${cat.name}`);
54
+ // Emoji: 😺; Name: smiley_cat
48
55
  ```
49
56
 
50
57
 
@@ -57,7 +64,7 @@ const random = require('@sefinek/random-emoji');
57
64
  const kaomoji = new random.Kaomojis();
58
65
 
59
66
  const uwu = await kaomoji.uwu();
60
- console.log(`Random UwU: ${uwu.message}`);
67
+ console.log('Random UwU:', uwu.message);
61
68
  })();
62
69
  ```
63
70
 
@@ -66,9 +73,9 @@ const random = require('@sefinek/random-emoji');
66
73
  const random = require('@sefinek/random-emoji');
67
74
  const kaomoji = new random.Kaomojis();
68
75
 
69
- kaomoji.love().then(data => console.log(data));
76
+ kaomoji.uwu().then(data => console.log(data));
70
77
  // or shorter
71
- kaomoji.love().then(console.log);
78
+ kaomoji.uwu().then(console.log);
72
79
  ```
73
80
 
74
81
  ### » The returned object from [API](https://api.sefinek.net)
@@ -76,36 +83,24 @@ kaomoji.love().then(console.log);
76
83
  {
77
84
  "success": true,
78
85
  "status": 200,
79
- "category": "kaomoji",
80
- "endpoint": "uwu",
81
- "message": "🅤🅦🅤"
86
+ "info": {
87
+ "category": "kaomoji",
88
+ "endpoint": "uwu"
89
+ },
90
+ "message": "UwU"
82
91
  }
83
92
  ```
84
93
 
85
94
 
86
- ### » Kaomoji endpoints
87
- | Function | Example |
88
- |-----------------------------------------------------|-----------|
89
- | [cat](https://api.sefinek.net/api/v2/kaomoji/cat) | (=^-ω-^=) |
90
- | [dog](https://api.sefinek.net/api/v2/kaomoji/dog) | ଘ(∪・ﻌ・∪)ଓ |
91
- | [owo](https://api.sefinek.net/api/v2/kaomoji/owo) | 𝓞𝔀𝓞 |
92
- | [uwu](https://api.sefinek.net/api/v2/kaomoji/uwu) | 𝕌𝕨𝕌 |
93
- | [love](https://api.sefinek.net/api/v2/kaomoji/love) | ヽ(♡‿♡)ノ |
95
+ ### <div id="kaomoji-endpoints">» Kaomoji endpoints</div>
96
+ | Function | Link to the API | Version | Example |
97
+ |----------|:----------------------------------------------------------|:--------|-----------|
98
+ | `cat()` | [Click here](https://api.sefinek.net/api/v2/kaomoji/cat) | v2 | (=^-ω-^=) |
99
+ | `dog()` | [Click here](https://api.sefinek.net/api/v2/kaomoji/dog) | v2 | ଘ(∪・ﻌ・∪)ଓ |
100
+ | `owo()` | [Click here](https://api.sefinek.net/api/v2/kaomoji/owo) | v2 | 𝓞𝔀𝓞 |
101
+ | `uwu()` | [Click here](https://api.sefinek.net/api/v2/kaomoji/uwu) | v2 | 𝕌𝕨𝕌 |
102
+ | `love()` | [Click here](https://api.sefinek.net/api/v2/kaomoji/love) | v2 | ヽ(♡‿♡)ノ |
94
103
 
95
104
 
96
105
  ## 📝 • Changelog
97
- > [Click here](CHANGELOG.md)
98
-
99
-
100
- ## 🤝 • Help
101
- Need assistance or have questions about this module? Don't hesitate to open a new [Issue](https://github.com/sefinek24/random-emoji/issues/new) on our GitHub repository.
102
- Our community is ready to help and provide answers to your inquiries.
103
-
104
-
105
- ## ⭐ • Thank you
106
- If you use the Random Emoji module and appreciate my work, I'd be grateful if you could give it a star on our [GitHub page](https://github.com/sefinek24/random-emoji).
107
- Your support helps me continue to develop this project and provide new and fun emojis to every user.
108
-
109
-
110
- ## 🎓 • [MIT License](LICENSE)
111
- Copyright 2023 © by [Sefinek](https://sefinek.net). All Rights Reserved.
106
+ [Click here](CHANGELOG.md)
@@ -0,0 +1 @@
1
+ [{"content":"🟥","name":"red_square"},{"content":"🟧","name":"orange_square"},{"content":"🟨","name":"yellow_square"},{"content":"🟩","name":"green_square"},{"content":"🟦","name":"blue_square"},{"content":"🟪","name":"purple_square"},{"content":"🟫","name":"brown_square"},{"content":"⬛","name":"black_large_square"},{"content":"⬜","name":"white_large_square"}]
@@ -0,0 +1,44 @@
1
+ const random = require('../index.js'); // Change to @sefinek/random-emoji
2
+
3
+ // Get a single random Unicode emoji.
4
+ console.log(`Single Emoji : ${random.unicode()}`);
5
+
6
+ // Retrieves a random emoji with its name, visual representation, and type
7
+ const emoji = random.emojis();
8
+ console.log(`Random Emoji : ${emoji.content}; ${emoji.name}; ${emoji.type}`);
9
+
10
+ // Get a random cat emoji
11
+ const cat = random.cats();
12
+ console.log(`Cat Emoji : ${cat.content}; ${cat.name}`);
13
+
14
+ // Get a random heart emoji
15
+ const heart = random.hearts();
16
+ console.log(`Heart Emoji : ${heart.content}; ${heart.name}`);
17
+
18
+ // Retrieves a random food emoji
19
+ const food = random.foods();
20
+ console.log(`Food Emoji : ${food.content}; ${food.name}`);
21
+
22
+ // Gets a random circle emoji
23
+ const circle = random.circles();
24
+ console.log(`Circle Emoji : ${circle.content}; ${circle.name}`);
25
+
26
+ // Gets a random squares emoji
27
+ const squares = random.squares();
28
+ console.log(`Square Emoji : ${squares.content}; ${squares.name}`);
29
+
30
+ // Fetches and displays random kaomojis using async/await syntax
31
+ (async () => {
32
+ const kaomojis = new random.Kaomojis();
33
+
34
+ // Retrieves and displays a cat face kaomoji
35
+ const kaoCat = await kaomojis.cat();
36
+ console.log(`Kaomoji Cat Face : ${kaoCat.message}`);
37
+
38
+ // Fetches and displays a random UwU kaomoji
39
+ const uwu = await kaomojis.uwu();
40
+ console.log(`Kaomoji UwU : ${uwu.message}`);
41
+ })();
42
+
43
+ // Displays the current version of the module
44
+ console.log(`Module version : v${random.version}`);
package/index.d.ts CHANGED
@@ -1,39 +1,108 @@
1
- declare module '@sefinek/random-emoji' {
2
- // Unicode
3
- export function unicode(): string;
4
-
5
-
6
- // Random emojis
7
- export interface Emoji {
8
- content: string;
9
- name: string;
10
- type: string;
11
- }
12
- export function emojis(): Emoji;
13
- export function cats(): Emoji;
14
- export function hearts(): Emoji;
15
- export function foods(): Emoji;
16
- export function circles(): Emoji;
17
-
18
-
19
- // Kaomojis
20
- export interface ApiResponse {
21
- success: boolean;
22
- status: number;
23
- info: {
24
- category: string;
25
- endpoint: string;
26
- };
27
- message: string;
28
- }
29
- export class Kaomojis {
30
- cat(): Promise<ApiResponse>;
31
- owo(): Promise<ApiResponse>;
32
- uwu(): Promise<ApiResponse>;
33
- love(): Promise<ApiResponse>;
34
- }
35
-
36
-
37
- // Other
38
- export const version: string;
1
+ /**
2
+ * Interface representing an emoji with a name, content, and type.
3
+ */
4
+ interface EmojisCollection {
5
+ content: string;
6
+ name: string;
7
+ type: string;
39
8
  }
9
+
10
+ /**
11
+ * Interface representing an emoji with a name and content.
12
+ */
13
+ interface Emojis {
14
+ content: string;
15
+ name: string;
16
+ }
17
+
18
+ /**
19
+ * Interface representing the response from an API endpoint.
20
+ */
21
+ interface ApiResponse {
22
+ success: boolean;
23
+ status: number;
24
+ info: {
25
+ category: string;
26
+ endpoint: string;
27
+ };
28
+ message: string;
29
+ }
30
+
31
+ /**
32
+ * Kaomojis class for accessing random kaomoji endpoints.
33
+ */
34
+ declare class Kaomojis {
35
+ constructor();
36
+
37
+ /**
38
+ * Get a random cat kaomoji.
39
+ */
40
+ cat(): Promise<ApiResponse>;
41
+
42
+ /**
43
+ * Get a random dog kaomoji.
44
+ */
45
+ dog(): Promise<ApiResponse>;
46
+
47
+ /**
48
+ * Get a random OwO kaomoji.
49
+ */
50
+ owo(): Promise<ApiResponse>;
51
+
52
+ /**
53
+ * Get a random UwU kaomoji.
54
+ */
55
+ uwu(): Promise<ApiResponse>;
56
+
57
+ /**
58
+ * Get a random love kaomoji.
59
+ */
60
+ love(): Promise<ApiResponse>;
61
+ }
62
+
63
+ declare namespace RandomEmoji {
64
+ /**
65
+ * Returns a random emoji from a large collection.
66
+ * Each emoji includes its name and type.
67
+ */
68
+ function emojis(): EmojisCollection;
69
+
70
+ /**
71
+ * Returns a random cat emoji.
72
+ */
73
+ function cats(): Emojis;
74
+
75
+ /**
76
+ * Returns a random circle emoji.
77
+ */
78
+ function circles(): Emojis;
79
+
80
+ /**
81
+ * Returns a random food emoji.
82
+ */
83
+ function foods(): Emojis;
84
+
85
+ /**
86
+ * Returns a random heart emoji.
87
+ */
88
+ function hearts(): Emojis;
89
+
90
+ /**
91
+ * Returns a random square emoji.
92
+ */
93
+ function squares(): Emojis;
94
+
95
+ /**
96
+ * Returns a random Unicode emoji character.
97
+ */
98
+ function unicode(): string;
99
+
100
+ /**
101
+ * The current version of the module.
102
+ */
103
+ const version: string;
104
+
105
+ export { Kaomojis };
106
+ }
107
+
108
+ export = RandomEmoji;
package/index.js CHANGED
@@ -1,135 +1,76 @@
1
- const { get } = require('https');
2
- const emojis = require('./data/emoji/random.json');
3
- const unicode = require('./data/emoji/unicode.json');
4
- const cats = require('./data/emoji/cat.json');
5
- const hearts = require('./data/emoji/heart.json');
6
- const foods = require('./data/emoji/food.json');
7
- const circles = require('./data/emoji/circle.json');
1
+ const { get } = require('node:https');
2
+
3
+ const emojis = {
4
+ emojis: require('./data/emoji/collection/big.json'),
5
+ cats: require('./data/emoji/cat.json'),
6
+ foods: require('./data/emoji/food.json'),
7
+ hearts: require('./data/emoji/heart.json'),
8
+ circles: require('./data/emoji/circle.json'),
9
+ squares: require('./data/emoji/square.json'),
10
+ unicode: require('./data/emoji/collection/single.json'),
11
+ };
8
12
  const endpoints = require('./data/endpoints.json');
9
- const { version } = require('./package.json');
13
+ const { name, version, devDependencies } = require('./package.json');
10
14
 
11
- /**
12
- * Configuration options for HTTP requests.
13
- * @type {Object}
14
- */
15
- const options = {
15
+ const httpOptions = {
16
16
  method: 'GET',
17
- port: 443,
18
17
  headers: {
19
- 'User-Agent': `random-emoji/${version} (+https://github.com/sefinek24/random-emoji)`,
18
+ 'User-Agent': `${name}/${version} (+https://github.com/sefinek/geoip2-api)${process.env.JEST_WORKER_ID && devDependencies?.jest ? ` jest/${devDependencies.jest.replace(/^[^0-9]*/, '')}` : ''}`,
20
19
  'Accept': 'application/json',
20
+ 'Content-Type': 'application/json',
21
21
  'Cache-Control': 'no-cache',
22
- 'CF-IPCountry': 'false',
23
- 'CF-Visitor': '{"scheme":"https"}',
24
22
  'Connection': 'keep-alive',
25
23
  'DNT': '1',
26
- 'Pragma': 'no-cache',
27
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
28
- 'X-Content-Type-Options': 'nosniff',
29
- 'X-Frame-Options': 'DENY',
30
- 'X-XSS-Protection': '1; mode=block',
31
24
  },
32
25
  };
33
26
 
34
- /**
35
- * Fetch content from a given URL using HTTP GET.
36
- * @param {string} url - The URL to fetch content from.
37
- * @returns {Promise} - A Promise that resolves with the fetched JSON data or rejects with an error.
38
- */
39
- function getContent(url) {
40
- return new Promise((resolve, reject) => {
41
- const req = get(url, options, res => {
42
- if (res.statusCode !== 200) {
43
- reject(`Request failed with status code ${res.statusCode}.`);
44
- return;
45
- }
46
27
 
47
- res.setEncoding('utf8');
28
+ const getContent = url => new Promise((resolve, reject) => {
29
+ const req = get(url, httpOptions, res => {
30
+ if (res.statusCode !== 200) {
31
+ res.resume();
32
+ return reject(new Error(`Request failed with status code ${res.statusCode}`));
33
+ }
48
34
 
49
- let rawData = '';
50
- res.on('data', chunk => {
51
- rawData += chunk;
52
- });
35
+ res.setEncoding('utf8');
36
+ let rawData = '';
53
37
 
54
- res.on('end', () => {
55
- try {
56
- resolve(JSON.parse(rawData));
57
- } catch (err) {
58
- reject(err.message);
59
- }
60
- });
38
+ res.on('data', chunk => {
39
+ rawData += chunk;
61
40
  });
62
41
 
63
- req.on('error', err => {
64
- reject(err);
42
+ res.on('end', () => {
43
+ try {
44
+ resolve(JSON.parse(rawData));
45
+ } catch (err) {
46
+ reject(new Error(`Failed to parse JSON: ${err.message}`));
47
+ }
65
48
  });
66
49
 
67
- req.end();
50
+ res.on('error', reject);
68
51
  });
69
- }
70
52
 
71
- /**
72
- * SefinekAPI class for accessing various random content endpoints.
73
- * @class
74
- */
53
+ req.on('error', reject);
54
+ req.end();
55
+ });
56
+
75
57
  class SefinekAPI {
76
58
  constructor() {
77
- Object.keys(endpoints).forEach(endpoint => {
78
- /**
79
- * Access a specific random content endpoint.
80
- * @method
81
- * @returns {Promise} - A Promise that resolves with the fetched content or rejects with an error.
82
- */
83
- this[endpoint] = () => getContent(`https://api.sefinek.net/api/v2/random/${endpoints[endpoint]}`);
84
- });
59
+ for (const [key, endpoint] of Object.entries(endpoints)) {
60
+ this[key] = () => getContent(`https://api.sefinek.net/api/v2/random/${endpoint}`);
61
+ }
85
62
  }
86
63
  }
87
64
 
88
- module.exports = {
89
- /**
90
- * Get a random Unicode emoji.
91
- * @returns {string} - A random Unicode emoji.
92
- */
93
- unicode: () => unicode[Math.floor(Math.random() * unicode.length)],
94
-
95
- /**
96
- * Get a random emoji.
97
- * @returns {object} - A random emoji.
98
- */
99
- emojis: () => emojis[Math.floor(Math.random() * emojis.length)],
100
-
101
- /**
102
- * Get a random cat emoji.
103
- * @returns {object} - A random cat emoji.
104
- */
105
- cats: () => cats[Math.floor(Math.random() * cats.length)],
106
-
107
- /**
108
- * Get a random heart emoji.
109
- * @returns {object} - A random heart emoji.
110
- */
111
- hearts: () => hearts[Math.floor(Math.random() * hearts.length)],
112
-
113
- /**
114
- * Get a random food emoji.
115
- * @returns {object} - A random food emoji.
116
- */
117
- foods: () => foods[Math.floor(Math.random() * foods.length)],
65
+ const getRandomElement = arr => arr[Math.floor(Math.random() * arr.length)];
118
66
 
119
- /**
120
- * Get a random circle emoji.
121
- * @returns {object} - A random circle emoji.
122
- */
123
- circles: () => circles[Math.floor(Math.random() * circles.length)],
67
+ const emojiGetters = {};
68
+ for (const [key, value] of Object.entries(emojis)) {
69
+ emojiGetters[key] = () => getRandomElement(value);
70
+ }
124
71
 
125
- /**
126
- * Access various random content endpoints using the SefinekAPI class.
127
- */
72
+ module.exports = {
73
+ ...emojiGetters,
128
74
  Kaomojis: SefinekAPI,
129
-
130
- /**
131
- * Get the module version.
132
- * @returns {string} - Returns the package version.
133
- */
134
75
  version,
135
76
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sefinek/random-emoji",
3
- "version": "2.0.4",
4
- "description": "A module providing various random emoticons along with their names and types. Additionally, it also includes random kaomoji.",
3
+ "version": "2.2.0",
4
+ "description": "A module offering a range of random emoticons, complete with their names and categories. Additionally, it also includes random kaomoji.",
5
5
  "keywords": [
6
6
  "random",
7
7
  "emoji",
@@ -19,30 +19,41 @@
19
19
  "name",
20
20
  "type"
21
21
  ],
22
- "homepage": "https://github.com/sefinek24/random-emoji#readme",
22
+ "homepage": "https://github.com/sefinek/random-emoji#readme",
23
23
  "bugs": {
24
- "url": "https://github.com/sefinek24/random-emoji/issues"
24
+ "url": "https://github.com/sefinek/random-emoji/issues"
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
28
- "url": "git+https://github.com/sefinek24/random-emoji.git"
28
+ "url": "git+https://github.com/sefinek/random-emoji.git"
29
29
  },
30
30
  "license": "MIT",
31
31
  "author": "Sefinek <contact@sefinek.net> (https://sefinek.net)",
32
+ "type": "commonjs",
32
33
  "main": "index.js",
33
- "types": "./index.d.ts",
34
+ "types": "index.d.ts",
34
35
  "directories": {
35
- "data": "data"
36
+ "example": "example",
37
+ "test": "test"
36
38
  },
37
39
  "files": [
38
- "data/",
39
- "example.js",
40
+ "data",
41
+ "example",
42
+ "AUTHORS",
43
+ "CHANGELOG.md",
40
44
  "index.d.ts",
41
45
  "index.js",
42
46
  "LICENSE",
43
47
  "README.md"
44
48
  ],
45
49
  "scripts": {
46
- "test": "node example.js"
50
+ "test": "jest test",
51
+ "up": "ncu -u && npm install && npm update && npm audit fix"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/js": "^9.39.1",
55
+ "@jest/globals": "^30.2.0",
56
+ "globals": "^16.5.0",
57
+ "jest": "^30.2.0"
47
58
  }
48
59
  }
package/example.js DELETED
@@ -1,38 +0,0 @@
1
- const random = require('./index.js'); // Change to @sefinek/random-emoji
2
-
3
- // A single emoji
4
- console.log(random.unicode());
5
-
6
- // Random emoji with name and type
7
- const emoji = random.emojis();
8
- console.log(`Name: ${emoji.name}; Emoji: ${emoji.content};`);
9
-
10
- // Random cat
11
- const cat = random.cats();
12
- console.log(`Name: ${cat.name}; Emoji: ${cat.content};`);
13
-
14
- // Random heart
15
- const heart = random.hearts();
16
- console.log(`Name: ${heart.name}; Emoji: ${heart.content};`);
17
-
18
- // Random food
19
- const food = random.foods();
20
- console.log(`Name: ${food.name}; Emoji: ${food.content};`);
21
-
22
- // Random circle
23
- const circle = random.circles();
24
- console.log(`Name: ${circle.name}; Emoji: ${circle.content};`);
25
-
26
- // Random kaomoji
27
- (async () => {
28
- const kaomojis = new random.Kaomojis();
29
-
30
- const kaoCat = await kaomojis.cat();
31
- console.log(`Cat face: ${kaoCat.message}`);
32
-
33
- const uwu = await kaomojis.uwu();
34
- console.log(`Random UwU: ${uwu.message}`);
35
- })();
36
-
37
- // Version
38
- console.log(`Module version: ${random.version}`);
File without changes