Skip to content

Commit

Permalink
fixed dictionaries path
Browse files Browse the repository at this point in the history
  • Loading branch information
m15r committed Apr 19, 2023
1 parent 4c62af8 commit 34d6aa4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type Options = {
maxLength?: number;
capitalize?: boolean;
seperator?: string;
separator?: string;
numberLength?: number;
};
export declare function generateUsername(options?: Options): string;
Expand Down
26 changes: 15 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateUsername = void 0;
const adjectives = require('./dictionaries/adjectives.json');
const adjectives = require('../dictionaries/adjectives.json');
const nouns = [
...require('./dictionaries/nouns/animals.json'),
...require('./dictionaries/nouns/household.json')
...require('../dictionaries/nouns/animals.json'),
...require('../dictionaries/nouns/household.json')
];
function generateRandomNumber(length) {
const min = parseInt('1' + (length > 0 ? '0'.repeat(length - 1) : ''));
Expand All @@ -15,15 +15,19 @@ function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function generateUsername(options) {
var _a;
var _a, _b;
const dictionaries = [adjectives, nouns];
const parts = dictionaries.map(dy => {
const word = dy[Math.floor((Math.random() * dy.length))];
return (options === null || options === void 0 ? void 0 : options.capitalize) ? capitalize(word) : word;
});
let username = parts.join((_a = options === null || options === void 0 ? void 0 : options.seperator) !== null && _a !== void 0 ? _a : '');
if (options === null || options === void 0 ? void 0 : options.numberLength)
username += generateRandomNumber(options.numberLength).toString();
const maxLength = (_a = options === null || options === void 0 ? void 0 : options.maxLength) !== null && _a !== void 0 ? _a : 32;
let username = undefined;
while (!username || (username === null || username === void 0 ? void 0 : username.length) > maxLength) {
const parts = dictionaries.map(dy => {
const word = dy[Math.floor((Math.random() * dy.length))];
return (options === null || options === void 0 ? void 0 : options.capitalize) ? capitalize(word) : word;
});
username = parts.join((_b = options === null || options === void 0 ? void 0 : options.separator) !== null && _b !== void 0 ? _b : '');
if (options === null || options === void 0 ? void 0 : options.numberLength)
username += generateRandomNumber(options.numberLength).toString();
}
return username;
}
exports.generateUsername = generateUsername;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gen-username",
"description": "Random Unique Username Generator",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ type Options = {
numberLength?: number
}

const adjectives = require('./dictionaries/adjectives.json')
const adjectives = require('../dictionaries/adjectives.json')

const nouns = [
...require('./dictionaries/nouns/animals.json'),
...require('./dictionaries/nouns/household.json')
...require('../dictionaries/nouns/animals.json'),
...require('../dictionaries/nouns/household.json')
]

function generateRandomNumber(length: number) {
Expand Down

0 comments on commit 34d6aa4

Please sign in to comment.