use phonetic package

This commit is contained in:
Synox 2016-07-07 20:36:16 +02:00
parent 8c95585e0e
commit 1948817152
2 changed files with 17 additions and 14 deletions

View File

@ -11,7 +11,7 @@
"autolinker": "^0.27.0", "autolinker": "^0.27.0",
"babel-polyfill": "^6.9.1", "babel-polyfill": "^6.9.1",
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"chance": "^1.0.3" "phonetic": "^0.1.1"
}, },
"devDependencies": { "devDependencies": {
"angular-mocks": "^1.5.2", "angular-mocks": "^1.5.2",

View File

@ -1,4 +1,4 @@
import Chance from 'chance'; import phonetic from 'phonetic';
class MailboxService { class MailboxService {
/*@ngInject*/ /*@ngInject*/
@ -10,7 +10,6 @@ class MailboxService {
this.$stateParams = $stateParams; this.$stateParams = $stateParams;
this.config = config; this.config = config;
this.address = null; this.address = null;
this.chance = new Chance();
} }
gotoMailbox(username) { gotoMailbox(username) {
@ -38,20 +37,24 @@ class MailboxService {
} }
generateRandomUsername() { generateRandomUsername() {
let username = null; let username = '';
if (this.chance.bool()) {
username = this.chance.word({syllables: 3}); phonetic.generate({syllables: 3});
if (Math.random() >= 0.5) {
username += phonetic.generate({syllables: 3});
} else { } else {
username = this.chance.first(); // first name username += phonetic.generate({syllables: 2});
username += phonetic.generate({syllables: 2});
} }
if (this.chance.bool()) { if (Math.random() >= 0.5) {
username += this.chance.integer({min: 50, max: 99}); username += this.getRandomInt(30, 99);
} }
if (this.chance.bool()) { return username.toLowerCase();
username += this.chance.tld();
} }
username = username.toLowerCase();
return username; getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
} }
getCurrentUsername() { getCurrentUsername() {