@sefinek/random-emoji 2.1.0 → 2.2.1

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,14 +1,35 @@
1
+ ## 📥・v2.2.1 (28.06.2026)
2
+ 1. Quality fixes.
3
+
4
+
5
+ ## 📥・v2.2.0 (06.12.2025)
6
+
7
+ ### ⚡ Performance
8
+ 1. Optimized code with arrow functions and `for...of` loops.
9
+ 2. Refactored Promise handling in `getContent()`.
10
+ 3. Added `getRandomElement()` helper function.
11
+
12
+ ### ✨ Changes
13
+ 1. Updated to `node:https` protocol.
14
+ 2. Improved error handling and JSON parsing.
15
+ 3. Rewritten TypeScript definitions with proper CommonJS export structure.
16
+ 4. Code quality improvements.
17
+
18
+ ### 🧪 Testing
19
+ 1. Added Jest test suite with 28 tests.
20
+
21
+
1
22
  ## 📥・v2.1.0 (20.12.2023)
2
23
 
3
24
  ### 🎉 Added
4
25
  1. New function `<random>.squares` for retrieving random squares.
5
- 2. Added a new example ([examples/table.js](examples/table.js)) demonstrating the use of module functions in a table format.
26
+ 2. Added a new example ([examples/table.js](example/table.js)) demonstrating the use of module functions in a table format.
6
27
 
7
28
  ### ✨ Changes
8
29
  1. General code quality improvements.
9
30
  2. Enhanced type definitions in [`index.d.ts`](index.d.ts) and expanded documentation.
10
31
  3. Improved the emoji randomization mechanism.
11
- 4. Updated example files in the [`examples`](examples) directory.
32
+ 4. Updated example files in the [`examples`](example) directory.
12
33
 
13
34
 
14
35
  ## 📥・v2.0.2/v2.0.3 (08.11.2023)
@@ -60,8 +81,8 @@
60
81
 
61
82
  ## 📥・v1.3.0 (13.05.2022)
62
83
  1. Updated README.md file.
63
- 2. Added `new kaomojis()` with random kaomoji from my [API](https://api.sefinek.net). See examples: [[1](https://github.com/sefinek24/random-emoji/blob/main/test.js)] [[2](https://github.com/sefinek24/random-emoji#%EF%B8%8F--kaomojis)]
64
- 3. Other changes to [index.js](https://github.com/sefinek24/random-emoji/blob/main/index.js) file.
84
+ 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)]
85
+ 3. Other changes to [index.js](https://github.com/sefinek/random-emoji/blob/main/index.js) file.
65
86
 
66
87
 
67
88
  ## 📥・v1.2.0 (12.05.2022)
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) | Get a single emoji |
23
- | [emojis](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L7) | Get a random emoji with its name and type |
24
- | [cats](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L11) | Get a random cat |
25
- | [hearts](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L14) | Get a random heart |
26
- | [foods](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L18) | Get a random food |
27
- | [circles](https://github.com/sefinek24/random-emoji/blob/f8e6a007717dc5e51adc31b4418bb954e2d364e5/example.js#L22) | Get a random circle |
28
- | [**new** Kaomojis](#kaomoji-endpoints) | Get random kaomojis from the [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
@@ -95,18 +103,4 @@ kaomoji.uwu().then(console.log);
95
103
 
96
104
 
97
105
  ## 📝 • Changelog
98
- > [Click here](CHANGELOG.md)
99
-
100
-
101
- ## 🤝 • Help
102
- 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.
103
- Our community is ready to help and provide answers to your inquiries.
104
-
105
-
106
- ## ⭐ • Thank you
107
- 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).
108
- Your support helps me continue to develop this project and provide new and fun emojis to every user.
109
-
110
-
111
- ## 🎓 • [MIT License](LICENSE)
112
- Copyright 2023 © by [Sefinek](https://sefinek.net). All Rights Reserved.
106
+ [Click here](CHANGELOG.md)
package/index.d.ts CHANGED
@@ -1,98 +1,108 @@
1
- declare module '@sefinek/random-emoji' {
2
- /**
3
- * Interface representing an emoji with a name, content, and type.
4
- * Used in the emoji collection to provide more detailed information about each emoji.
5
- */
6
- export interface EmojisCollection {
7
- content: string;
8
- name: string;
9
- type: string;
10
- }
11
-
12
- /**
13
- * Interface representing an emoji with a name and content.
14
- * Used for simpler emoji categories like cats, hearts, etc.
15
- */
16
- export interface Emojis {
17
- content: string;
18
- name: string;
19
- }
20
-
21
- /**
22
- * Returns a random emoji from a large collection.
23
- * Each emoji includes its name and type.
24
- * @returns {EmojisCollection} A random emoji from the collection.
25
- */
26
- export function emojis(): EmojisCollection;
27
-
28
- /**
29
- * Returns a random cat emoji.
30
- * @returns {Emojis} A random cat emoji.
31
- */
32
- export function cats(): Emojis;
33
-
34
- /**
35
- * Returns a random circle emoji.
36
- * @returns {Emojis} A random circle emoji.
37
- */
38
- export function circles(): Emojis;
39
-
40
- /**
41
- * Returns a random food emoji.
42
- * @returns {Emojis} A random food emoji.
43
- */
44
- export function foods(): Emojis;
45
-
46
- /**
47
- * Returns a random heart emoji.
48
- * @returns {Emojis} A random heart emoji.
49
- */
50
- export function hearts(): Emojis;
51
-
52
- /**
53
- * Returns a random square emoji.
54
- * @returns {Emojis} A random square emoji.
55
- */
56
- export function squares(): Emojis;
57
-
58
-
59
- /**
60
- * Returns a random Unicode emoji character.
61
- * @returns {string} A random Unicode emoji character.
62
- */
63
- export function unicode(): string;
64
-
65
- /**
66
- * Interface representing the response from an API endpoint.
67
- * Includes information about the success status, API category, and response message.
68
- */
69
- export interface ApiResponse {
70
- success: boolean;
71
- status: number;
72
- info: {
73
- category: string;
74
- endpoint: string;
75
- };
76
- message: string;
77
- }
78
-
79
- /**
80
- * Kaomojis class for accessing various random content endpoints.
81
- * Allows fetching of random kaomojis from specified endpoints.
82
- */
83
- export class Kaomojis {
84
- constructor();
85
-
86
- /**
87
- * Dynamically generated methods for accessing random content endpoints.
88
- * Each method returns a Promise that resolves to an ApiResponse.
89
- * @returns {Promise<ApiResponse>} A promise resolving to the API response.
90
- */
91
- [endpoint: string]: () => Promise<ApiResponse>;
92
- }
93
-
94
- /**
95
- * The current version of the module.
96
- */
97
- export const version: string;
98
- }
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;
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,4 +1,5 @@
1
- const { get } = require('https');
1
+ const { get } = require('node:https');
2
+
2
3
  const emojis = {
3
4
  emojis: require('./data/emoji/collection/big.json'),
4
5
  cats: require('./data/emoji/cat.json'),
@@ -9,57 +10,61 @@ const emojis = {
9
10
  unicode: require('./data/emoji/collection/single.json'),
10
11
  };
11
12
  const endpoints = require('./data/endpoints.json');
12
- const { version } = require('./package.json');
13
+ const { name, version, devDependencies } = require('./package.json');
13
14
 
14
15
  const httpOptions = {
15
16
  method: 'GET',
16
17
  headers: {
17
- 'User-Agent': `Mozilla/5.0 (compatible; random-emoji/${version}; +https://github.com/sefinek24/random-emoji)`,
18
- 'Accept': 'application/json',
19
- 'Cache-Control': 'no-cache',
20
- 'Connection': 'keep-alive',
21
- 'DNT': '1',
22
- 'Pragma': 'no-cache',
23
- 'Referrer-Policy': 'strict-origin-when-cross-origin',
24
- 'X-Content-Type-Options': 'nosniff',
25
- 'X-Frame-Options': 'DENY',
26
- 'X-XSS-Protection': '1; mode=block',
18
+ 'User-Agent': `${name}/${version} (+https://github.com/sefinek/geoip2-api)${process.env.JEST_WORKER_ID && devDependencies?.jest ? ` jest/${devDependencies.jest.replace(/^[^0-9]*/, '')}` : ''}`,
27
19
  },
28
20
  };
29
21
 
22
+ const getContent = url => new Promise((resolve, reject) => {
23
+ const req = get(url, httpOptions, res => {
24
+ if (res.statusCode !== 200) {
25
+ res.resume();
26
+ return reject(new Error(`Request failed with status code ${res.statusCode}`));
27
+ }
30
28
 
31
- async function getContent(url) {
32
- const res = await new Promise((resolve, reject) => {
33
- const req = get(url, httpOptions, resolve);
34
- req.on('error', reject);
35
- req.end();
36
- });
29
+ res.setEncoding('utf8');
30
+ let rawData = '';
37
31
 
38
- if (res.statusCode !== 200) {
39
- throw new Error(`Request failed with status code ${res.statusCode}`);
40
- }
32
+ res.on('data', chunk => {
33
+ rawData += chunk;
34
+ });
41
35
 
42
- res.setEncoding('utf8');
43
- let rawData = '';
44
- for await (const chunk of res) {
45
- rawData += chunk;
46
- }
36
+ res.on('end', () => {
37
+ try {
38
+ resolve(JSON.parse(rawData));
39
+ } catch (err) {
40
+ reject(new Error(`Failed to parse JSON: ${err.message}`));
41
+ }
42
+ });
47
43
 
48
- return JSON.parse(rawData);
49
- }
44
+ res.on('error', reject);
45
+ });
46
+
47
+ req.on('error', reject);
48
+ req.end();
49
+ });
50
50
 
51
51
  class SefinekAPI {
52
52
  constructor() {
53
- Object.entries(endpoints).forEach(([key, endpoint]) => {
53
+ for (const [key, endpoint] of Object.entries(endpoints)) {
54
54
  this[key] = () => getContent(`https://api.sefinek.net/api/v2/random/${endpoint}`);
55
- });
55
+ }
56
56
  }
57
57
  }
58
58
 
59
+ const getRandomElement = arr => arr[Math.floor(Math.random() * arr.length)];
60
+
61
+ const emojiGetters = {};
62
+ for (const [key, value] of Object.entries(emojis)) {
63
+ emojiGetters[key] = () => getRandomElement(value);
64
+ }
65
+
59
66
  module.exports = {
60
- ...Object.fromEntries(Object.entries(emojis).map(([key, value]) => [
61
- key, () => value[Math.floor(Math.random() * value.length)],
62
- ])),
67
+ ...emojiGetters,
63
68
  Kaomojis: SefinekAPI,
64
69
  version,
65
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sefinek/random-emoji",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
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",
@@ -19,19 +19,44 @@
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
- "typings": "./index.d.ts",
34
+ "types": "index.d.ts",
35
+ "directories": {
36
+ "example": "example",
37
+ "test": "test"
38
+ },
39
+ "files": [
40
+ "data",
41
+ "example",
42
+ "AUTHORS",
43
+ "CHANGELOG.md",
44
+ "index.d.ts",
45
+ "index.js",
46
+ "LICENSE",
47
+ "README.md"
48
+ ],
34
49
  "scripts": {
35
- "test": "node examples/main.js"
50
+ "m": "ncu -u && npm install && npm update",
51
+ "test": "jest test"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/js": "^10.0.1",
55
+ "@jest/globals": "^30.4.1",
56
+ "globals": "^17.7.0",
57
+ "jest": "^30.4.2"
58
+ },
59
+ "allowScripts": {
60
+ "unrs-resolver@1.12.2": true
36
61
  }
37
62
  }
package/examples/table.js DELETED
@@ -1,53 +0,0 @@
1
- const random = require('../index.js'); // Change to @sefinek/random-emoji
2
- const data = [];
3
-
4
- async function displayEmojiData() {
5
- // Get a single random Unicode emoji
6
- data.push({ Function: 'unicode()', Emoji: random.unicode().trim() });
7
-
8
- // Retrieves a random emoji, including its visual representation, name, and category
9
- const emoji = random.emojis();
10
- data.push({ Function: 'emojis()', Emoji: emoji.content.trim(), Name: emoji.name, Type: emoji.type });
11
-
12
- // Get a random cat emoji
13
- const cat = random.cats();
14
- data.push({ Function: 'cats()', Emoji: cat.content.trim(), Name: cat.name });
15
-
16
- // Get a random heart emoji
17
- const heart = random.hearts();
18
- data.push({ Function: 'hearts()', Emoji: heart.content.trim(), Name: heart.name });
19
-
20
- // Retrieves a random food emoji
21
- const food = random.foods();
22
- data.push({ Function: 'foods()', Emoji: food.content.trim(), Name: food.name });
23
-
24
- // Gets a random circle emoji
25
- const circle = random.circles();
26
- data.push({ Function: 'circles()', Emoji: circle.content.trim(), Name: circle.name });
27
-
28
- // Gets a random squares emoji
29
- const squares = random.squares();
30
- data.push({ Function: 'squares()', Emoji: squares.content.trim(), Name: squares.name });
31
-
32
-
33
- // Fetches random kaomojis
34
- const kaomojis = new random.Kaomojis();
35
- const kaoCat = await kaomojis.cat();
36
- data.push({ Function: 'cat()', Emoji: kaoCat.message.trim(), Name: 'Cat face' });
37
-
38
- const uwu = await kaomojis.uwu();
39
- data.push({ Function: 'uwu()', Emoji: uwu.message.trim(), Name: 'UwU' });
40
-
41
-
42
- // Displays the table
43
- console.table(data);
44
- }
45
-
46
- try {
47
- displayEmojiData().then(() => {
48
- // Displays the current version of the module
49
- console.log(`Module version: v${random.version}`);
50
- });
51
- } catch (err) {
52
- throw new Error(err);
53
- }
File without changes