From 1948817152eea53677166ae20e66e4bc3d07fb98 Mon Sep 17 00:00:00 2001 From: Synox Date: Thu, 7 Jul 2016 20:36:16 +0200 Subject: [PATCH] use phonetic package --- package.json | 2 +- src/app/mailbox/service/mailbox.service.js | 29 ++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 1fcabba..71ef0ab 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "autolinker": "^0.27.0", "babel-polyfill": "^6.9.1", "bootstrap": "^3.3.6", - "chance": "^1.0.3" + "phonetic": "^0.1.1" }, "devDependencies": { "angular-mocks": "^1.5.2", diff --git a/src/app/mailbox/service/mailbox.service.js b/src/app/mailbox/service/mailbox.service.js index edaaa6e..292bc1c 100644 --- a/src/app/mailbox/service/mailbox.service.js +++ b/src/app/mailbox/service/mailbox.service.js @@ -1,4 +1,4 @@ -import Chance from 'chance'; +import phonetic from 'phonetic'; class MailboxService { /*@ngInject*/ @@ -10,7 +10,6 @@ class MailboxService { this.$stateParams = $stateParams; this.config = config; this.address = null; - this.chance = new Chance(); } gotoMailbox(username) { @@ -38,20 +37,24 @@ class MailboxService { } generateRandomUsername() { - let username = null; - if (this.chance.bool()) { - username = this.chance.word({syllables: 3}); + let username = ''; + + phonetic.generate({syllables: 3}); + + if (Math.random() >= 0.5) { + username += phonetic.generate({syllables: 3}); } else { - username = this.chance.first(); // first name + username += phonetic.generate({syllables: 2}); + username += phonetic.generate({syllables: 2}); } - if (this.chance.bool()) { - username += this.chance.integer({min: 50, max: 99}); + if (Math.random() >= 0.5) { + username += this.getRandomInt(30, 99); } - if (this.chance.bool()) { - username += this.chance.tld(); - } - username = username.toLowerCase(); - return username; + return username.toLowerCase(); + } + + getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min)) + min; } getCurrentUsername() {