Sfoglia il codice sorgente

Rewrite with ES6

master
Illia Daynatovich 8 anni fa
parent
commit
4584d89c43

+ 2
- 2
app.js Vedi File

@@ -24,7 +24,7 @@ const LogCollector = Logger.LogCollector;
24 24
 import JitsiMeetLogStorage from "./modules/util/JitsiMeetLogStorage";
25 25
 
26 26
 import URLProcessor from "./modules/config/URLProcessor";
27
-import RoomnameGenerator from './modules/util/RoomnameGenerator';
27
+import { generateRoomWithoutSeparator } from './modules/util/RoomnameGenerator';
28 28
 
29 29
 import UI from "./modules/UI/UI";
30 30
 import settings from "./modules/settings/Settings";
@@ -75,7 +75,7 @@ function buildRoomName () {
75 75
     let roomName = getRoomName();
76 76
 
77 77
     if(!roomName) {
78
-        let word = RoomnameGenerator.generateRoomWithoutSeparator();
78
+        let word = generateRoomWithoutSeparator();
79 79
         roomName = word.toLowerCase();
80 80
         let historyURL = window.location.href + word;
81 81
         //Trying to push state with current URL + roomName

+ 2
- 3
modules/UI/UI.js Vedi File

@@ -25,7 +25,7 @@ import SettingsMenu from "./side_pannels/settings/SettingsMenu";
25 25
 import Profile from "./side_pannels/profile/Profile";
26 26
 import Settings from "./../settings/Settings";
27 27
 import RingOverlay from "./ring_overlay/RingOverlay";
28
-import RandomUtil from "../util/RandomUtil";
28
+import { randomInt } from "../util/RandomUtil";
29 29
 import UIErrors from './UIErrors';
30 30
 import { debounce } from "../util/helpers";
31 31
 
@@ -1100,8 +1100,7 @@ UI.notifyFocusDisconnected = function (focus, retrySec) {
1100 1100
  */
1101 1101
 UI.showPageReloadOverlay = function (isNetworkFailure, reason) {
1102 1102
     // Reload the page after 10 - 30 seconds
1103
-    PageReloadOverlay.show(
1104
-        10 + RandomUtil.randomInt(0, 20), isNetworkFailure, reason);
1103
+    PageReloadOverlay.show(10 + randomInt(0, 20), isNetworkFailure, reason);
1105 1104
 };
1106 1105
 
1107 1106
 /**

+ 5
- 4
modules/UI/welcome_page/WelcomePage.js Vedi File

@@ -1,8 +1,9 @@
1 1
 /* global $, interfaceConfig, APP */
2
-var animateTimeout, updateTimeout;
3 2
 
4
-var RoomnameGenerator = require("../../util/RoomnameGenerator");
5
-import UIUtil from "../util/UIUtil";
3
+import { generateRoomWithoutSeparator } from '../../util/RoomnameGenerator';
4
+import UIUtil from '../util/UIUtil';
5
+
6
+var animateTimeout, updateTimeout;
6 7
 
7 8
 function enter_room() {
8 9
     var val = $("#enter_room_field").val();
@@ -23,7 +24,7 @@ function animate(word) {
23 24
 }
24 25
 
25 26
 function update_roomname() {
26
-    var word = RoomnameGenerator.generateRoomWithoutSeparator();
27
+    var word = generateRoomWithoutSeparator();
27 28
     $("#enter_room_field").attr("room_name", word);
28 29
     $("#enter_room_field").attr("placeholder", "");
29 30
     clearTimeout(animateTimeout);

+ 57
- 48
modules/util/RandomUtil.js Vedi File

@@ -1,73 +1,82 @@
1 1
 /**
2
+ * Alphanumeric characters.
2 3
  * @const
3 4
  */
4
-var ALPHANUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
+const ALPHANUM
6
+    = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5 7
 
6 8
 /**
7
- * Hexadecimal digits.
9
+ * Hexadecimal digit characters.
8 10
  * @const
9 11
  */
10
-var HEX_DIGITS = '0123456789abcdef';
12
+const HEX_DIGITS = '0123456789abcdef';
11 13
 
12 14
 /**
13
- * Generates random int within the range [min, max]
14
- * @param min the minimum value for the generated number
15
- * @param max the maximum value for the generated number
16
- * @returns random int number
15
+ * Generate a string with random alphanumeric characters with a specific length.
16
+ *
17
+ * @param {number} length - The length of the string to return.
18
+ * @returns {string} A string of random alphanumeric characters with the
19
+ * specified length.
17 20
  */
18
-function randomInt(min, max) {
19
-    return Math.floor(Math.random() * (max - min + 1)) + min;
21
+export function randomAlphanumString(length) {
22
+    return _randomString(length, ALPHANUM);
20 23
 }
21 24
 
22 25
 /**
23
- * Get random element from array or string.
24
- * @param {Array|string} arr source
25
- * @returns array element or string character
26
+ * Get random element of array or string.
27
+ *
28
+ * @param {Array|string} arr - Source.
29
+ * @returns {Array|string} Array element or string character.
26 30
  */
27
-function randomElement(arr) {
28
-    return arr[randomInt(0, arr.length -1)];
31
+export function randomElement(arr) {
32
+    return arr[randomInt(0, arr.length - 1)];
29 33
 }
30 34
 
31 35
 /**
32
- * Generate random alphanumeric string.
33
- * @param {number} length expected string length
34
- * @returns {string} random string of specified length
36
+ * Returns a random hex digit.
37
+ *
38
+ * @returns {Array|string}
35 39
  */
36
-function randomAlphanumStr(length) {
37
-    var result = '';
40
+export function randomHexDigit() {
41
+    return randomElement(HEX_DIGITS);
42
+}
38 43
 
39
-    for (var i = 0; i < length; i += 1) {
40
-        result += randomElement(ALPHANUM);
41
-    }
44
+/**
45
+ * Generates a string of random hexadecimal digits with a specific length.
46
+ *
47
+ * @param {number} length - The length of the string to return.
48
+ * @returns {string} A string of random hexadecimal digits with the specified
49
+ * length.
50
+ */
51
+export function randomHexString(length) {
52
+    return _randomString(length, HEX_DIGITS);
53
+}
42 54
 
43
-    return result;
55
+/**
56
+ * Generates random int within the range [min, max].
57
+ *
58
+ * @param {number} min - The minimum value for the generated number.
59
+ * @param {number} max - The maximum value for the generated number.
60
+ * @returns {number} Random int number.
61
+ */
62
+export function randomInt(min, max) {
63
+    return Math.floor(Math.random() * (max - min + 1)) + min;
44 64
 }
45 65
 
46 66
 /**
47
- * Exported interface.
67
+ * Generates a string of random characters with a specific length.
68
+ *
69
+ * @param {number} length - The length of the string to return.
70
+ * @param {string} characters - The characters from which the returned string is
71
+ * to be constructed.
72
+ * @returns {string} A string of random characters with the specified length.
48 73
  */
49
-var RandomUtil = {
50
-    /**
51
-     * Returns a random hex digit.
52
-     * @returns {*}
53
-     */
54
-    randomHexDigit: function() {
55
-        return randomElement(HEX_DIGITS);
56
-    },
57
-    /**
58
-     * Returns a random string of hex digits with length 'len'.
59
-     * @param len the length.
60
-     */
61
-    randomHexString: function (len) {
62
-        var ret = '';
63
-        while (len--) {
64
-            ret += this.randomHexDigit();
65
-        }
66
-        return ret;
67
-    },
68
-    randomElement: randomElement,
69
-    randomAlphanumStr: randomAlphanumStr,
70
-    randomInt: randomInt
71
-};
74
+function _randomString(length, characters) {
75
+    let result = '';
72 76
 
73
-module.exports = RandomUtil;
77
+    for (let i = 0; i < length; ++i) {
78
+        result += randomElement(characters);
79
+    }
80
+
81
+    return result;
82
+}

+ 205
- 163
modules/util/RoomnameGenerator.js Vedi File

@@ -1,198 +1,240 @@
1
-var RandomUtil = require('./RandomUtil');
2
-//var nouns = [
3
-//];
4
-var pluralNouns = [
5
-    "Aliens", "Animals", "Antelopes", "Ants", "Apes", "Apples", "Baboons",
6
-    "Bacteria", "Badgers", "Bananas", "Bats", "Bears", "Birds", "Bonobos",
7
-    "Brides", "Bugs", "Bulls", "Butterflies", "Cheetahs", "Cherries", "Chicken",
8
-    "Children", "Chimps", "Clowns", "Cows", "Creatures", "Dinosaurs", "Dogs",
9
-    "Dolphins", "Donkeys", "Dragons", "Ducks", "Dwarfs", "Eagles", "Elephants",
10
-    "Elves", "Fathers", "Fish", "Flowers", "Frogs", "Fruit", "Fungi",
11
-    "Galaxies", "Geese", "Goats", "Gorillas", "Hedgehogs", "Hippos", "Horses",
12
-    "Hunters", "Insects", "Kids", "Knights", "Lemons", "Lemurs", "Leopards",
13
-    "LifeForms", "Lions", "Lizards", "Mice", "Monkeys", "Monsters", "Mushrooms",
14
-    "Octopodes", "Oranges", "Orangutans", "Organisms", "Pants", "Parrots",
15
-    "Penguins", "People", "Pigeons", "Pigs", "Pineapples", "Plants", "Potatoes",
16
-    "Priests", "Rats", "Reptiles", "Reptilians", "Rhinos", "Seagulls", "Sheep",
17
-    "Siblings", "Snakes", "Spaghetti", "Spiders", "Squid", "Squirrels",
18
-    "Stars", "Students", "Teachers", "Tigers", "Tomatoes", "Trees", "Vampires",
19
-    "Vegetables", "Viruses", "Vulcans", "Weasels", "Werewolves", "Whales",
20
-    "Witches", "Wizards", "Wolves", "Workers", "Worms", "Zebras"
1
+import { randomElement } from './RandomUtil';
2
+
3
+/*
4
+const _NOUN_ = [
5
+];
6
+*/
7
+
8
+/**
9
+ * The list of plural nouns.
10
+ * @const
11
+ */
12
+const _PLURALNOUN_ = [
13
+    'Aliens', 'Animals', 'Antelopes', 'Ants', 'Apes', 'Apples', 'Baboons',
14
+    'Bacteria', 'Badgers', 'Bananas', 'Bats', 'Bears', 'Birds', 'Bonobos',
15
+    'Brides', 'Bugs', 'Bulls', 'Butterflies', 'Cheetahs', 'Cherries', 'Chicken',
16
+    'Children', 'Chimps', 'Clowns', 'Cows', 'Creatures', 'Dinosaurs', 'Dogs',
17
+    'Dolphins', 'Donkeys', 'Dragons', 'Ducks', 'Dwarfs', 'Eagles', 'Elephants',
18
+    'Elves', 'Fathers', 'Fish', 'Flowers', 'Frogs', 'Fruit', 'Fungi',
19
+    'Galaxies', 'Geese', 'Goats', 'Gorillas', 'Hedgehogs', 'Hippos', 'Horses',
20
+    'Hunters', 'Insects', 'Kids', 'Knights', 'Lemons', 'Lemurs', 'Leopards',
21
+    'LifeForms', 'Lions', 'Lizards', 'Mice', 'Monkeys', 'Monsters', 'Mushrooms',
22
+    'Octopodes', 'Oranges', 'Orangutans', 'Organisms', 'Pants', 'Parrots',
23
+    'Penguins', 'People', 'Pigeons', 'Pigs', 'Pineapples', 'Plants', 'Potatoes',
24
+    'Priests', 'Rats', 'Reptiles', 'Reptilians', 'Rhinos', 'Seagulls', 'Sheep',
25
+    'Siblings', 'Snakes', 'Spaghetti', 'Spiders', 'Squid', 'Squirrels',
26
+    'Stars', 'Students', 'Teachers', 'Tigers', 'Tomatoes', 'Trees', 'Vampires',
27
+    'Vegetables', 'Viruses', 'Vulcans', 'Weasels', 'Werewolves', 'Whales',
28
+    'Witches', 'Wizards', 'Wolves', 'Workers', 'Worms', 'Zebras'
29
+];
30
+
31
+/*
32
+const _PLACE_ = [
33
+    'Pub', 'University', 'Airport', 'Library', 'Mall', 'Theater', 'Stadium',
34
+    'Office', 'Show', 'Gallows', 'Beach', 'Cemetery', 'Hospital', 'Reception',
35
+    'Restaurant', 'Bar', 'Church', 'House', 'School', 'Square', 'Village',
36
+    'Cinema', 'Movies', 'Party', 'Restroom', 'End', 'Jail', 'PostOffice',
37
+    'Station', 'Circus', 'Gates', 'Entrance', 'Bridge'
38
+];
39
+*/
40
+
41
+/**
42
+ * The list of verbs.
43
+ * @const
44
+ */
45
+const _VERB_ = [
46
+    'Abandon', 'Adapt', 'Advertise', 'Answer', 'Anticipate', 'Appreciate',
47
+    'Approach', 'Argue', 'Ask', 'Bite', 'Blossom', 'Blush', 'Breathe', 'Breed',
48
+    'Bribe', 'Burn', 'Calculate', 'Clean', 'Code', 'Communicate', 'Compute',
49
+    'Confess', 'Confiscate', 'Conjugate', 'Conjure', 'Consume', 'Contemplate',
50
+    'Crawl', 'Dance', 'Delegate', 'Devour', 'Develop', 'Differ', 'Discuss',
51
+    'Dissolve', 'Drink', 'Eat', 'Elaborate', 'Emancipate', 'Estimate', 'Expire',
52
+    'Extinguish', 'Extract', 'Facilitate', 'Fall', 'Feed', 'Finish', 'Floss',
53
+    'Fly', 'Follow', 'Fragment', 'Freeze', 'Gather', 'Glow', 'Grow', 'Hex',
54
+    'Hide', 'Hug', 'Hurry', 'Improve', 'Intersect', 'Investigate', 'Jinx',
55
+    'Joke', 'Jubilate', 'Kiss', 'Laugh', 'Manage', 'Meet', 'Merge', 'Move',
56
+    'Object', 'Observe', 'Offer', 'Paint', 'Participate', 'Party', 'Perform',
57
+    'Plan', 'Pursue', 'Pierce', 'Play', 'Postpone', 'Pray', 'Proclaim',
58
+    'Question', 'Read', 'Reckon', 'Rejoice', 'Represent', 'Resize', 'Rhyme',
59
+    'Scream', 'Search', 'Select', 'Share', 'Shoot', 'Shout', 'Signal', 'Sing',
60
+    'Skate', 'Sleep', 'Smile', 'Smoke', 'Solve', 'Spell', 'Steer', 'Stink',
61
+    'Substitute', 'Swim', 'Taste', 'Teach', 'Terminate', 'Think', 'Type',
62
+    'Unite', 'Vanish', 'Worship'
63
+];
64
+
65
+/**
66
+ * The list of adverbs.
67
+ * @const
68
+ */
69
+const _ADVERB_ = [
70
+    'Absently', 'Accurately', 'Accusingly', 'Adorably', 'AllTheTime', 'Alone',
71
+    'Always', 'Amazingly', 'Angrily', 'Anxiously', 'Anywhere', 'Appallingly',
72
+    'Apparently', 'Articulately', 'Astonishingly', 'Badly', 'Barely',
73
+    'Beautifully', 'Blindly', 'Bravely', 'Brightly', 'Briskly', 'Brutally',
74
+    'Calmly', 'Carefully', 'Casually', 'Cautiously', 'Cleverly', 'Constantly',
75
+    'Correctly', 'Crazily', 'Curiously', 'Cynically', 'Daily', 'Dangerously',
76
+    'Deliberately', 'Delicately', 'Desperately', 'Discreetly', 'Eagerly',
77
+    'Easily', 'Euphoricly', 'Evenly', 'Everywhere', 'Exactly', 'Expectantly',
78
+    'Extensively', 'Ferociously', 'Fiercely', 'Finely', 'Flatly', 'Frequently',
79
+    'Frighteningly', 'Gently', 'Gloriously', 'Grimly', 'Guiltily', 'Happily',
80
+    'Hard', 'Hastily', 'Heroically', 'High', 'Highly', 'Hourly', 'Humbly',
81
+    'Hysterically', 'Immensely', 'Impartially', 'Impolitely', 'Indifferently',
82
+    'Intensely', 'Jealously', 'Jovially', 'Kindly', 'Lazily', 'Lightly',
83
+    'Loudly', 'Lovingly', 'Loyally', 'Magnificently', 'Malevolently', 'Merrily',
84
+    'Mightily', 'Miserably', 'Mysteriously', 'NOT', 'Nervously', 'Nicely',
85
+    'Nowhere', 'Objectively', 'Obnoxiously', 'Obsessively', 'Obviously',
86
+    'Often', 'Painfully', 'Patiently', 'Playfully', 'Politely', 'Poorly',
87
+    'Precisely', 'Promptly', 'Quickly', 'Quietly', 'Randomly', 'Rapidly',
88
+    'Rarely', 'Recklessly', 'Regularly', 'Remorsefully', 'Responsibly',
89
+    'Rudely', 'Ruthlessly', 'Sadly', 'Scornfully', 'Seamlessly', 'Seldom',
90
+    'Selfishly', 'Seriously', 'Shakily', 'Sharply', 'Sideways', 'Silently',
91
+    'Sleepily', 'Slightly', 'Slowly', 'Slyly', 'Smoothly', 'Softly', 'Solemnly',
92
+    'Steadily', 'Sternly', 'Strangely', 'Strongly', 'Stunningly', 'Surely',
93
+    'Tenderly', 'Thoughtfully', 'Tightly', 'Uneasily', 'Vanishingly',
94
+    'Violently', 'Warmly', 'Weakly', 'Wearily', 'Weekly', 'Weirdly', 'Well',
95
+    'Well', 'Wickedly', 'Wildly', 'Wisely', 'Wonderfully', 'Yearly'
21 96
 ];
22
-//var places = [
23
-//    "Pub", "University", "Airport", "Library", "Mall", "Theater", "Stadium",
24
-//    "Office", "Show", "Gallows", "Beach", "Cemetery", "Hospital", "Reception",
25
-//    "Restaurant", "Bar", "Church", "House", "School", "Square", "Village",
26
-//    "Cinema", "Movies", "Party", "Restroom", "End", "Jail", "PostOffice",
27
-//    "Station", "Circus", "Gates", "Entrance", "Bridge"
28
-//];
29
-var verbs = [
30
-    "Abandon", "Adapt", "Advertise", "Answer", "Anticipate", "Appreciate",
31
-    "Approach", "Argue", "Ask", "Bite", "Blossom", "Blush", "Breathe", "Breed",
32
-    "Bribe", "Burn", "Calculate", "Clean", "Code", "Communicate", "Compute",
33
-    "Confess", "Confiscate", "Conjugate", "Conjure", "Consume", "Contemplate",
34
-    "Crawl", "Dance", "Delegate", "Devour", "Develop", "Differ", "Discuss",
35
-    "Dissolve", "Drink", "Eat", "Elaborate", "Emancipate", "Estimate", "Expire",
36
-    "Extinguish", "Extract", "Facilitate", "Fall", "Feed", "Finish", "Floss",
37
-    "Fly", "Follow", "Fragment", "Freeze", "Gather", "Glow", "Grow", "Hex",
38
-    "Hide", "Hug", "Hurry", "Improve", "Intersect", "Investigate", "Jinx",
39
-    "Joke", "Jubilate", "Kiss", "Laugh", "Manage", "Meet", "Merge", "Move",
40
-    "Object", "Observe", "Offer", "Paint", "Participate", "Party", "Perform",
41
-    "Plan", "Pursue", "Pierce", "Play", "Postpone", "Pray", "Proclaim",
42
-    "Question", "Read", "Reckon", "Rejoice", "Represent", "Resize", "Rhyme",
43
-    "Scream", "Search", "Select", "Share", "Shoot", "Shout", "Signal", "Sing",
44
-    "Skate", "Sleep", "Smile", "Smoke", "Solve", "Spell", "Steer", "Stink",
45
-    "Substitute", "Swim", "Taste", "Teach", "Terminate", "Think", "Type",
46
-    "Unite", "Vanish", "Worship"
97
+
98
+/**
99
+ * The list of adjectives.
100
+ * @const
101
+ */
102
+const _ADJECTIVE_ = [
103
+    'Abominable', 'Accurate', 'Adorable', 'All', 'Alleged', 'Ancient', 'Angry',
104
+    'Anxious', 'Appalling', 'Apparent', 'Astonishing', 'Attractive', 'Awesome',
105
+    'Baby', 'Bad', 'Beautiful', 'Benign', 'Big', 'Bitter', 'Blind', 'Blue',
106
+    'Bold', 'Brave', 'Bright', 'Brisk', 'Calm', 'Camouflaged', 'Casual',
107
+    'Cautious', 'Choppy', 'Chosen', 'Clever', 'Cold', 'Cool', 'Crawly',
108
+    'Crazy', 'Creepy', 'Cruel', 'Curious', 'Cynical', 'Dangerous', 'Dark',
109
+    'Delicate', 'Desperate', 'Difficult', 'Discreet', 'Disguised', 'Dizzy',
110
+    'Dumb', 'Eager', 'Easy', 'Edgy', 'Electric', 'Elegant', 'Emancipated',
111
+    'Enormous', 'Euphoric', 'Evil', 'Fast', 'Ferocious', 'Fierce', 'Fine',
112
+    'Flawed', 'Flying', 'Foolish', 'Foxy', 'Freezing', 'Funny', 'Furious',
113
+    'Gentle', 'Glorious', 'Golden', 'Good', 'Green', 'Green', 'Guilty',
114
+    'Hairy', 'Happy', 'Hard', 'Hasty', 'Hazy', 'Heroic', 'Hostile', 'Hot',
115
+    'Humble', 'Humongous', 'Humorous', 'Hysterical', 'Idealistic', 'Ignorant',
116
+    'Immense', 'Impartial', 'Impolite', 'Indifferent', 'Infuriated',
117
+    'Insightful', 'Intense', 'Interesting', 'Intimidated', 'Intriguing',
118
+    'Jealous', 'Jolly', 'Jovial', 'Jumpy', 'Kind', 'Laughing', 'Lazy', 'Liquid',
119
+    'Lonely', 'Longing', 'Loud', 'Loving', 'Loyal', 'Macabre', 'Mad', 'Magical',
120
+    'Magnificent', 'Malevolent', 'Medieval', 'Memorable', 'Mere', 'Merry',
121
+    'Mighty', 'Mischievous', 'Miserable', 'Modified', 'Moody', 'Most',
122
+    'Mysterious', 'Mystical', 'Needy', 'Nervous', 'Nice', 'Objective',
123
+    'Obnoxious', 'Obsessive', 'Obvious', 'Opinionated', 'Orange', 'Painful',
124
+    'Passionate', 'Perfect', 'Pink', 'Playful', 'Poisonous', 'Polite', 'Poor',
125
+    'Popular', 'Powerful', 'Precise', 'Preserved', 'Pretty', 'Purple', 'Quick',
126
+    'Quiet', 'Random', 'Rapid', 'Rare', 'Real', 'Reassuring', 'Reckless', 'Red',
127
+    'Regular', 'Remorseful', 'Responsible', 'Rich', 'Rude', 'Ruthless', 'Sad',
128
+    'Scared', 'Scary', 'Scornful', 'Screaming', 'Selfish', 'Serious', 'Shady',
129
+    'Shaky', 'Sharp', 'Shiny', 'Shy', 'Simple', 'Sleepy', 'Slow', 'Sly',
130
+    'Small', 'Smart', 'Smelly', 'Smiling', 'Smooth', 'Smug', 'Sober', 'Soft',
131
+    'Solemn', 'Square', 'Square', 'Steady', 'Strange', 'Strong', 'Stunning',
132
+    'Subjective', 'Successful', 'Surly', 'Sweet', 'Tactful', 'Tense',
133
+    'Thoughtful', 'Tight', 'Tiny', 'Tolerant', 'Uneasy', 'Unique', 'Unseen',
134
+    'Warm', 'Weak', 'Weird', 'WellCooked', 'Wild', 'Wise', 'Witty', 'Wonderful',
135
+    'Worried', 'Yellow', 'Young', 'Zealous'
47 136
 ];
48
-var adverbs = [
49
-    "Absently", "Accurately", "Accusingly", "Adorably", "AllTheTime", "Alone",
50
-    "Always", "Amazingly", "Angrily", "Anxiously", "Anywhere", "Appallingly",
51
-    "Apparently", "Articulately", "Astonishingly", "Badly", "Barely",
52
-    "Beautifully", "Blindly", "Bravely", "Brightly", "Briskly", "Brutally",
53
-    "Calmly", "Carefully", "Casually", "Cautiously", "Cleverly", "Constantly",
54
-    "Correctly", "Crazily", "Curiously", "Cynically", "Daily", "Dangerously",
55
-    "Deliberately", "Delicately", "Desperately", "Discreetly", "Eagerly",
56
-    "Easily", "Euphoricly", "Evenly", "Everywhere", "Exactly", "Expectantly",
57
-    "Extensively", "Ferociously", "Fiercely", "Finely", "Flatly", "Frequently",
58
-    "Frighteningly", "Gently", "Gloriously", "Grimly", "Guiltily", "Happily",
59
-    "Hard", "Hastily", "Heroically", "High", "Highly", "Hourly", "Humbly",
60
-    "Hysterically", "Immensely", "Impartially", "Impolitely", "Indifferently",
61
-    "Intensely", "Jealously", "Jovially", "Kindly", "Lazily", "Lightly",
62
-    "Loudly", "Lovingly", "Loyally", "Magnificently", "Malevolently", "Merrily",
63
-    "Mightily", "Miserably", "Mysteriously", "NOT", "Nervously", "Nicely",
64
-    "Nowhere", "Objectively", "Obnoxiously", "Obsessively", "Obviously",
65
-    "Often", "Painfully", "Patiently", "Playfully", "Politely", "Poorly",
66
-    "Precisely", "Promptly", "Quickly", "Quietly", "Randomly", "Rapidly",
67
-    "Rarely", "Recklessly", "Regularly", "Remorsefully", "Responsibly",
68
-    "Rudely", "Ruthlessly", "Sadly", "Scornfully", "Seamlessly", "Seldom",
69
-    "Selfishly", "Seriously", "Shakily", "Sharply", "Sideways", "Silently",
70
-    "Sleepily", "Slightly", "Slowly", "Slyly", "Smoothly", "Softly", "Solemnly",
71
-    "Steadily", "Sternly", "Strangely", "Strongly", "Stunningly", "Surely",
72
-    "Tenderly", "Thoughtfully", "Tightly", "Uneasily", "Vanishingly",
73
-    "Violently", "Warmly", "Weakly", "Wearily", "Weekly", "Weirdly", "Well",
74
-    "Well", "Wickedly", "Wildly", "Wisely", "Wonderfully", "Yearly"
137
+
138
+/*
139
+const _PRONOUN_ = [
75 140
 ];
76
-var adjectives = [
77
-    "Abominable", "Accurate", "Adorable", "All", "Alleged", "Ancient", "Angry",
78
-    "Anxious", "Appalling", "Apparent", "Astonishing", "Attractive", "Awesome",
79
-    "Baby", "Bad", "Beautiful", "Benign", "Big", "Bitter", "Blind", "Blue",
80
-    "Bold", "Brave", "Bright", "Brisk", "Calm", "Camouflaged", "Casual",
81
-    "Cautious", "Choppy", "Chosen", "Clever", "Cold", "Cool", "Crawly",
82
-    "Crazy", "Creepy", "Cruel", "Curious", "Cynical", "Dangerous", "Dark",
83
-    "Delicate", "Desperate", "Difficult", "Discreet", "Disguised", "Dizzy",
84
-    "Dumb", "Eager", "Easy", "Edgy", "Electric", "Elegant", "Emancipated",
85
-    "Enormous", "Euphoric", "Evil", "Fast", "Ferocious", "Fierce", "Fine",
86
-    "Flawed", "Flying", "Foolish", "Foxy", "Freezing", "Funny", "Furious",
87
-    "Gentle", "Glorious", "Golden", "Good", "Green", "Green", "Guilty",
88
-    "Hairy", "Happy", "Hard", "Hasty", "Hazy", "Heroic", "Hostile", "Hot",
89
-    "Humble", "Humongous", "Humorous", "Hysterical", "Idealistic", "Ignorant",
90
-    "Immense", "Impartial", "Impolite", "Indifferent", "Infuriated",
91
-    "Insightful", "Intense", "Interesting", "Intimidated", "Intriguing",
92
-    "Jealous", "Jolly", "Jovial", "Jumpy", "Kind", "Laughing", "Lazy", "Liquid",
93
-    "Lonely", "Longing", "Loud", "Loving", "Loyal", "Macabre", "Mad", "Magical",
94
-    "Magnificent", "Malevolent", "Medieval", "Memorable", "Mere", "Merry",
95
-    "Mighty", "Mischievous", "Miserable", "Modified", "Moody", "Most",
96
-    "Mysterious", "Mystical", "Needy", "Nervous", "Nice", "Objective",
97
-    "Obnoxious", "Obsessive", "Obvious", "Opinionated", "Orange", "Painful",
98
-    "Passionate", "Perfect", "Pink", "Playful", "Poisonous", "Polite", "Poor",
99
-    "Popular", "Powerful", "Precise", "Preserved", "Pretty", "Purple", "Quick",
100
-    "Quiet", "Random", "Rapid", "Rare", "Real", "Reassuring", "Reckless", "Red",
101
-    "Regular", "Remorseful", "Responsible", "Rich", "Rude", "Ruthless", "Sad",
102
-    "Scared", "Scary", "Scornful", "Screaming", "Selfish", "Serious", "Shady",
103
-    "Shaky", "Sharp", "Shiny", "Shy", "Simple", "Sleepy", "Slow", "Sly",
104
-    "Small", "Smart", "Smelly", "Smiling", "Smooth", "Smug", "Sober", "Soft",
105
-    "Solemn", "Square", "Square", "Steady", "Strange", "Strong", "Stunning",
106
-    "Subjective", "Successful", "Surly", "Sweet", "Tactful", "Tense",
107
-    "Thoughtful", "Tight", "Tiny", "Tolerant", "Uneasy", "Unique", "Unseen",
108
-    "Warm", "Weak", "Weird", "WellCooked", "Wild", "Wise", "Witty", "Wonderful",
109
-    "Worried", "Yellow", "Young", "Zealous"
110
-    ];
111
-//var pronouns = [
112
-//];
113
-//var conjunctions = [
114
-//"And", "Or", "For", "Above", "Before", "Against", "Between"
115
-//];
141
+*/
116 142
 
117 143
 /*
144
+const _CONJUNCTION_ = [
145
+    'And', 'Or', 'For', 'Above', 'Before', 'Against', 'Between'
146
+];
147
+*/
148
+
149
+/**
118 150
  * Maps a string (category name) to the array of words from that category.
151
+ * @const
119 152
  */
120
-var CATEGORIES =
121
-{
122
-    //"_NOUN_": nouns,
123
-    "_PLURALNOUN_": pluralNouns,
124
-    //"_PLACE_": places,
125
-    "_VERB_": verbs,
126
-    "_ADVERB_": adverbs,
127
-    "_ADJECTIVE_": adjectives
128
-    //"_PRONOUN_": pronouns,
129
-    //"_CONJUNCTION_": conjunctions,
153
+const CATEGORIES = {
154
+    _ADJECTIVE_,
155
+    _ADVERB_,
156
+    _PLURALNOUN_,
157
+    _VERB_
158
+
159
+//    _CONJUNCTION_,
160
+//    _NOUN_,
161
+//    _PLACE_,
162
+//    _PRONOUN_,
130 163
 };
131 164
 
132
-var PATTERNS = [
133
-    "_ADJECTIVE__PLURALNOUN__VERB__ADVERB_"
165
+/**
166
+ * The list of room name patterns.
167
+ * @const
168
+ */
169
+const PATTERNS = [
170
+    '_ADJECTIVE__PLURALNOUN__VERB__ADVERB_'
134 171
 
135 172
     // BeautifulFungiOrSpaghetti
136
-    //"_ADJECTIVE__PLURALNOUN__CONJUNCTION__PLURALNOUN_",
173
+//    '_ADJECTIVE__PLURALNOUN__CONJUNCTION__PLURALNOUN_',
137 174
 
138 175
     // AmazinglyScaryToy
139
-    //"_ADVERB__ADJECTIVE__NOUN_",
176
+//    '_ADVERB__ADJECTIVE__NOUN_',
140 177
 
141 178
     // NeitherTrashNorRifle
142
-    //"Neither_NOUN_Nor_NOUN_",
143
-    //"Either_NOUN_Or_NOUN_",
179
+//    'Neither_NOUN_Nor_NOUN_',
180
+//    'Either_NOUN_Or_NOUN_',
144 181
 
145 182
     // EitherCopulateOrInvestigate
146
-    //"Either_VERB_Or_VERB_",
147
-    //"Neither_VERB_Nor_VERB_",
183
+//    'Either_VERB_Or_VERB_',
184
+//    'Neither_VERB_Nor_VERB_',
148 185
 
149
-    //"The_ADJECTIVE__ADJECTIVE__NOUN_",
150
-    //"The_ADVERB__ADJECTIVE__NOUN_",
151
-    //"The_ADVERB__ADJECTIVE__NOUN_s",
152
-    //"The_ADVERB__ADJECTIVE__PLURALNOUN__VERB_",
186
+//    'The_ADJECTIVE__ADJECTIVE__NOUN_',
187
+//    'The_ADVERB__ADJECTIVE__NOUN_',
188
+//    'The_ADVERB__ADJECTIVE__NOUN_s',
189
+//    'The_ADVERB__ADJECTIVE__PLURALNOUN__VERB_',
153 190
 
154 191
     // WolvesComputeBadly
155
-    //"_PLURALNOUN__VERB__ADVERB_",
192
+//    '_PLURALNOUN__VERB__ADVERB_',
156 193
 
157 194
     // UniteFacilitateAndMerge
158
-    //"_VERB__VERB_And_VERB_",
195
+//    '_VERB__VERB_And_VERB_',
159 196
 
160
-    //NastyWitchesAtThePub
161
-    //"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
197
+    // NastyWitchesAtThePub
198
+//    '_ADJECTIVE__PLURALNOUN_AtThe_PLACE_',
162 199
 ];
163 200
 
164
-/*
165
- * Returns true if the string 's' contains one of the
166
- * template strings.
201
+/**
202
+ * Generates a new room name.
203
+ *
204
+ * @returns {string} A newly-generated room name.
167 205
  */
168
-function hasTemplate(s) {
169
-    for (var template in CATEGORIES){
170
-        if (s.indexOf(template) >= 0){
171
-            return true;
206
+export function generateRoomWithoutSeparator() {
207
+    // XXX Note that if more than one pattern is available, the choice of 'name'
208
+    // won't have a uniform distribution amongst all patterns (names from
209
+    // patterns with fewer options will have higher probability of being chosen
210
+    // that names from patterns with more options).
211
+    let name = randomElement(PATTERNS);
212
+
213
+    while (hasTemplate(name)) {
214
+        for (const template in CATEGORIES) { // eslint-disable-line guard-for-in
215
+            const word = randomElement(CATEGORIES[template]);
216
+
217
+            name = name.replace(template, word);
172 218
         }
173 219
     }
220
+
221
+    return name;
174 222
 }
175 223
 
176 224
 /**
177
- * Generates new room name.
225
+ * Determines whether a specific string contains at least one of the
226
+ * templates/categories.
227
+ *
228
+ * @param {string} s - String containing categories.
229
+ * @returns {boolean} True if the specified string contains at least one of the
230
+ * templates/categories; otherwise, false.
178 231
  */
179
-var RoomnameGenerator = {
180
-    generateRoomWithoutSeparator: function() {
181
-        // Note that if more than one pattern is available, the choice of
182
-        // 'name' won't have a uniform distribution amongst all patterns (names
183
-        // from patterns with fewer options will have higher probability of
184
-        // being chosen that names from patterns with more options).
185
-        var name = RandomUtil.randomElement(PATTERNS);
186
-        var word;
187
-        while (hasTemplate(name)) {
188
-            for (var template in CATEGORIES) {
189
-                word = RandomUtil.randomElement(CATEGORIES[template]);
190
-                name = name.replace(template, word);
191
-            }
232
+function hasTemplate(s) {
233
+    for (const template in CATEGORIES) {
234
+        if (s.indexOf(template) >= 0) {
235
+            return true;
192 236
         }
193
-
194
-        return name;
195 237
     }
196
-};
197 238
 
198
-module.exports = RoomnameGenerator;
239
+    return false;
240
+}

Loading…
Annulla
Salva