@chleauu/emoji-humeur 1.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.
- package/LICENSE +7 -0
- package/README.md +16 -0
- package/emojis.js +21 -0
- package/index.js +55 -0
- package/package.json +19 -0
- package/test.js +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 Chloé Michel
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# 🎭 emoji-humeur
|
|
2
|
+
|
|
3
|
+
Un petit utilitaire simple et fun pour analyser une phrase en français et obtenir l'émoji qui correspond le mieux à l'humeur du texte !
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
Installe le package via npm :
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @chleau/emoji-humeur
|
|
11
|
+
|
|
12
|
+
const { getEmoji } = require("@chleau/emoji-humeur");
|
|
13
|
+
|
|
14
|
+
console.log(getEmoji("C'est super génial !")); // Sortie : 🥳
|
|
15
|
+
|
|
16
|
+
```
|
package/emojis.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// emojis.js
|
|
2
|
+
const emojiDatabase = {
|
|
3
|
+
joy: {
|
|
4
|
+
emojis: ['😊', '😁', '😂', '🥳', '✨'],
|
|
5
|
+
keywords: ['super', 'génial', 'cool', 'top', 'magnifique', 'bravo', 'merci', 'adore', 'aime', 'heureux', 'content']
|
|
6
|
+
},
|
|
7
|
+
sad: {
|
|
8
|
+
emojis: ['😭', '😢', '😞', '🙁', '💔'],
|
|
9
|
+
keywords: ['triste', 'nul', 'dommage', 'pleure', 'déçu', 'marre', 'bad', 'cassé', 'erreur', 'bug']
|
|
10
|
+
},
|
|
11
|
+
angry: {
|
|
12
|
+
emojis: ['🤬', '😡', '😠', '👿', '😤'],
|
|
13
|
+
keywords: ['énerve', 'colère', 'haine', 'saoul', 'pire', 'déteste', 'rage']
|
|
14
|
+
},
|
|
15
|
+
tired: {
|
|
16
|
+
emojis: ['😴', '🥱', '💤', 'tired'],
|
|
17
|
+
keywords: ['fatigué', 'dodo', 'sommeil', 'flemme', 'épuisé']
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = emojiDatabase;
|
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
const emojiDatabase = require('./emojis');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Analyse une phrase et retourne un emoji basé sur le sentiment détecté.
|
|
6
|
+
* @param {string} text - La phrase à analyser.
|
|
7
|
+
* @returns {string} Un emoji.
|
|
8
|
+
*/
|
|
9
|
+
function getEmoji(text) {
|
|
10
|
+
if (!text || typeof text !== 'string') {
|
|
11
|
+
return '🤷'; // Emoji par défaut si le texte est vide ou invalide
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Nettoyage simple du texte (minuscules et suppression de la ponctuation de base)
|
|
15
|
+
const cleanText = text.toLowerCase().replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
|
|
16
|
+
const words = cleanText.split(/\s+/); // Découpe le texte en mots
|
|
17
|
+
|
|
18
|
+
// Compteurs de points pour chaque émotion
|
|
19
|
+
const scores = { joy: 0, sad: 0, angry: 0, tired: 0 };
|
|
20
|
+
|
|
21
|
+
// On parcourt chaque mot de la phrase
|
|
22
|
+
words.forEach(word => {
|
|
23
|
+
// On compare avec notre base de données
|
|
24
|
+
for (const [emotion, data] of Object.entries(emojiDatabase)) {
|
|
25
|
+
if (data.keywords.includes(word)) {
|
|
26
|
+
scores[emotion]++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Trouver l'émotion avec le score le plus élevé
|
|
32
|
+
let maxScore = 0;
|
|
33
|
+
let detectedEmotion = null;
|
|
34
|
+
|
|
35
|
+
for (const [emotion, score] of Object.entries(scores)) {
|
|
36
|
+
if (score > maxScore) {
|
|
37
|
+
maxScore = score;
|
|
38
|
+
detectedEmotion = emotion;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Si une émotion est détectée, on prend un emoji au hasard dans sa liste
|
|
43
|
+
if (detectedEmotion) {
|
|
44
|
+
const emojiList = emojiDatabase[detectedEmotion].emojis;
|
|
45
|
+
const randomIndex = Math.floor(Math.random() * emojiList.length);
|
|
46
|
+
return emojiList[randomIndex];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Si on ne sait pas, on renvoie un emoji neutre au hasard
|
|
50
|
+
const neutralEmojis = ['😐', '🤔', '👀', '🤷♂️'];
|
|
51
|
+
return neutralEmojis[Math.floor(Math.random() * neutralEmojis.length)];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// On exporte la fonction pour qu'elle soit utilisable par d'autres projets
|
|
55
|
+
module.exports = { getEmoji };
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chleauu/emoji-humeur",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"type": "commonjs",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"jest": "^30.4.2"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lisat/calculatrice": "^1.0.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// test.js
|
|
2
|
+
const { getEmoji } = require('./index');
|
|
3
|
+
|
|
4
|
+
console.log("Test 1:", getEmoji("J'ai cassé mon code, c'est une erreur de débutant..."));
|
|
5
|
+
// Devrait afficher un emoji triste ou énervé (ex: 😭 ou 😡)
|
|
6
|
+
|
|
7
|
+
console.log("Test 2:", getEmoji("Le projet est enfin fini, c'est super génial !"));
|
|
8
|
+
// Devrait afficher un emoji joyeux (ex: 🥳 ou 😊)
|
|
9
|
+
|
|
10
|
+
console.log("Test 3:", getEmoji("Trop la flemme ce matin, je suis fatigué."));
|
|
11
|
+
// Devrait afficher un emoji de fatigue (ex: 😴)
|
|
12
|
+
|
|
13
|
+
console.log("Test 4:", getEmoji("La météo est incertaine aujourd'hui."));
|
|
14
|
+
// Devrait afficher un emoji neutre (ex: 🤔)
|