GithubHelp home page GithubHelp logo

andreasonny83 / unique-names-generator Goto Github PK

View Code? Open in Web Editor NEW
557.0 5.0 58.0 1.33 MB

Generate unique and memorable name strings

Home Page: https://codesandbox.io/s/unique-names-generator-7fn9r

License: MIT License

TypeScript 99.12% JavaScript 0.88%
npm npm-package nodejs name-generator

unique-names-generator's Introduction

Unique Names Generator

All Contributors

Build Status Known Vulnerabilities devDependencies Status

NPM

More than 50,000,000 name combinations out of the box

What is Unique name generator?

Unique name generator is a tree-shakeable Node package for generating random and unique names.

It comes with a list of dictionaries out of the box, but you can also provide your custom ones.

Docs

This documentation is for the unique-names-generator v4.

If you are using a version 3.x of the library, please refer to the v3 Docs

For the version 1 & 2, please refer to the v2 Docs

Migrating to v4

If you want to migrate, from an older version of the library to v4, please read the Migration guide

Table of contents

Prerequisites

This project requires NodeJS (at least version 6) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.

$ node --version
v7.10.1

$ npm --version
4.2.0

Installation

BEFORE YOU INSTALL: please read the prerequisites

Install the package using npm or Yarn

$ npm i -S unique-names-generator

Or using Yarn

$ yarn add unique-names-generator

Usage

const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator');

const randomName = uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] }); // big_red_donkey

const shortName = uniqueNamesGenerator({
  dictionaries: [adjectives, animals, colors], // colors can be omitted here as not used
  length: 2
}); // big-donkey

Typescript support

This package export a type definition file so you can use it, out of the box, inside your Typescript project.

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const customConfig: Config = {
  dictionaries: [adjectives, colors],
  separator: '-',
  length: 2,
};

const randomName: string = uniqueNamesGenerator({
  dictionaries: [adjectives, colors, animals]
}); // big_red_donkey

const shortName: string = uniqueNamesGenerator(customConfig); // big-donkey

API

uniqueNamesGenerator (options)

Returns a string with a random generated name

options

Type: Config

dictionaries

Type: array

required: true

This is an array of dictionaries. Each dictionary is an array of strings containing the words to use for generating the string.

The provided dictionaries can be imported from the library as a separate modules and provided in the desired order.

import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';

const shortName: string = uniqueNamesGenerator({
  dictionaries: [colors, adjectives, animals]
}); // red_big_donkey

Read more about the dictionaries and how to use them, in the Dictionaries section.

separator

Type: string

required: false

Default: _

A string separator to be used for separate the words generated. The default separator is set to _.

length

Type: number

required: false

Default: 3

The default value is set to 3 and it will return a name composed of 3 words. This values must be equal or minor to the number of dictionaries defined (3 by default). Setting the length to a value of 4 will throw an error when only 3 dictionaries are provided.

style

Type: lowerCase | upperCase | capital

required: false

Default: lowerCase

The default value is set to lowerCase and it will return a lower case name. By setting the value to upperCase, the words, will be returned with all the letters in upper case format. The capital option will capitalize each word of the unique name generated

import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';

const capitalizedName: string = uniqueNamesGenerator({
  dictionaries: [colors, adjectives, animals],
  style: 'capital'
}); // Red_Big_Donkey

const upperCaseName: string = uniqueNamesGenerator({
  dictionaries: [colors, adjectives, animals],
  style: 'upperCase'
}); // RED_BIG_DONKEY

const lowerCaseName: string = uniqueNamesGenerator({
  dictionaries: [colors, adjectives, animals],
  style: 'lowerCase'
}); // red_big_donkey

seed

Type: number | string

required: false

A seed is used when wanting to deterministically generate a name. As long as the provided seed is the same the generated name will also always be the same.

import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';
const config: Config = {
  dictionaries: [adjectives, colors, animals],
  separator: '-',
  seed: 120498,
};

const nameFromSeed: string = uniqueNamesGenerator(config); // continuous-gray-dragonfly
import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';
const config: Config = {
  dictionaries: [adjectives, colors, animals],
  separator: '-',
  seed: 'you can use strings as a seed',
};

const nameFromSeed: string = uniqueNamesGenerator(config); // stable-crimson-porpoise

Dictionaries available

Numbers

This is a dynamic dictionary. Read more in the Numbers Dictionary section

Adjectives

A list of more than 1,400 adjectives ready for you to use

import { uniqueNamesGenerator, Config, adjectives } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives]
}

const characterName: string = uniqueNamesGenerator(config); // big

Animals

A list of more than 350 animals ready to use

import { uniqueNamesGenerator, Config, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [animals]
}

const characterName: string = uniqueNamesGenerator(config); // donkey

Colors

A list of more than 50 different colors

import { uniqueNamesGenerator, Config, colors } from 'unique-names-generator';

const config: Config = {
  dictionaries: [colors]
}

const characterName: string = uniqueNamesGenerator(config); // red

Countries

A list of more than 250 different countries

import { uniqueNamesGenerator, Config, countries } from 'unique-names-generator';

const config: Config = {
  dictionaries: [countries]
}

const characterName: string = uniqueNamesGenerator(config); // United Arab Emirates

Names

A list of more than 4,900 unique names

import { uniqueNamesGenerator, Config, names } from 'unique-names-generator';

const config: Config = {
  dictionaries: [names]
}

const characterName: string = uniqueNamesGenerator(config); // Winona

Languages

A list of languages

import { uniqueNamesGenerator, Config, languages } from 'unique-names-generator';

const config: Config = {
  dictionaries: [languages]
}

const characterName: string = uniqueNamesGenerator(config); // polish

Star Wars

A list of more than 80 unique character names from Star Wars

import { uniqueNamesGenerator, Config, starWars } from 'unique-names-generator';

const config: Config = {
  dictionaries: [starWars]
}

const characterName: string = uniqueNamesGenerator(config); // Han Solo

Default dictionaries

By default, the Unique name generator library comes with 3 dictionaries out of the box, so that you can use them straight away. Starting from the version 4 of the library, however, you must explicitly provide the dictionaries within the configuration object. This is for reducing the bundle size and allowing tree shaking to remove the extra dictionaries from your bundle when using custom ones.

The new syntax for using the default dictionaries is the following:

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives, colors, animals]
}

const characterName: string = uniqueNamesGenerator(config); // red_big_donkey

Custom dictionaries

You might want to provide your custom dictionaries to use for generating your unique names, in order to meet your business requirements.

You can easily do that using the dictionaries option.

import { uniqueNamesGenerator } from 'unique-names-generator';

const starWarsCharacters = [
  'Han Solo',
  'Jabba The Hutt',
  'R2-D2',
  'Luke Skywalker',
  'Princess Leia Organa'
];
const colors = [
  'Green', 'Red', 'Yellow', 'Black'
]

const characterName: string = uniqueNamesGenerator({
  dictionaries: [colors, starWarsCharacters],
  length: 2,
  separator: ' '
}); // Green Luke Skywalker

Numbers Dictionary

You can easily generate random numbers inside your unique name using the Numbers dictionary helper.

import { uniqueNamesGenerator, NumberDictionary } from 'unique-names-generator';

const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 });
const characterName: string = uniqueNamesGenerator({
dictionaries: [['Dangerous'], ['Snake'], numberDictionary],
  length: 3,
  separator: '',
  style: 'capital'
}); // DangerousSnake123

Numbers Dictionary API

generate (options)

Returns a string with a random generated number between 1 and 999

options

Type: Config

min

Type: number

required: false

default: 1

The minimum value to be returned as a random number

max

Type: number

required: false

default: 999

The maximum value to be returned as a random number

length

Type: number

required: false

The length of the random generated number to be returned.

Setting a length of 3 will always return a random number between 100 and 999. This is the same as setting 100 and 999 as min and max option.

Note If set, this will ignore any min and max options provided.

Combining custom and provided dictionaries

You can reuse the dictionaries provided by the library. Just import the ones that you need and use them directly in your app.

import { uniqueNamesGenerator, adjectives, colors } from 'unique-names-generator';

const improvedAdjectives = [
  ...adjectives,
  'abrasive',
  'brash',
  'callous',
  'daft',
  'eccentric',
];
const xMen = [
'professorX',
'beast',
'colossus',
'cyclops',
'iceman',
'wolverine',
];

const characterName: string = uniqueNamesGenerator({
  dictionaries: [improvedAdjectives, color, xMen],
  length: 2,
  separator: '-'
}); // eccentric-blue-iceman

Migration guide

Migration guide from version 3 to version 4

Unique names generator v4 implement a new breaking change.

Mandatory dictionaries config

You must now explicitly provide the library with the dictionaries to use. This is for improving flexibility and allowing tree-shaking to remove the unused dictionaries from your bundle size.

Read more about the dictionaries in the Dictionaries section.

v3

import { uniqueNamesGenerator } from 'unique-names-generator';

const randomName = uniqueNamesGenerator(); // big_red_donkey

v4

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives, colors, animals]
}

const randomName = uniqueNamesGenerator(config); // big_red_donkey

Migration guide from version 1 or 2

Unique names generator v3 implements a couple of breaking changes. If are upgrading your library from a version 1 or 2, you might be interested in knowing the following:

uniqueNamesGenerator

This will now work only when a dictionaries array is provided according to the v4 breaking change.

v2

import { uniqueNamesGenerator } from 'unique-names-generator';

const randomName = uniqueNamesGenerator();

v4

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives, colors, animals]
}

const randomName = uniqueNamesGenerator(config); // big_red_donkey

Separator

v2

import { uniqueNamesGenerator } from 'unique-names-generator';

const shortName = uniqueNamesGenerator('-'); // big-red-donkey

v4

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives, colors, animals],
  separator: '-'
}

const shortName = uniqueNamesGenerator(config); // big-red-donkey

Short

The short property has been replaced by length so you can specify as many word as you want

v2

import { uniqueNamesGenerator } from 'unique-names-generator';

const shortName = uniqueNamesGenerator(true); // big-donkey

v4

import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';

const config: Config = {
  dictionaries: [adjectives, colors, animals],
  length: 2
}

const shortName = uniqueNamesGenerator(config); // big-donkey

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request 😎

License

MIT License © Andrea SonnY

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Andrea Sonny

💻 📖 💬 📆 🤔 🖋

Abhijit Mehta

🤔

Grant Blakeman

💻 🐛

Deepak

📖 🤔

Anurag Jain

🤔

Digibake

🐛

Chase Moskal

🤔

tholst

📖

Johan Gustafsson

💻 🤔

Alex Wild

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

unique-names-generator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

unique-names-generator's Issues

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.18.1 to 1.18.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for 1.18.2

🔗 Changelog

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Seperator Doesn't Affect Name

With Below Code i got a result of availablesly moore625
which after inspection is a combination of available and sly moore and 625
where sly moore has a space in between not truncated

 let uniqueName = uniqueNamesGenerator({
      dictionaries: [adjectives, starWars, numberDictionary],
      length: 3,
      separator: '',
      style: 'lowerCase',
    });

    let exists = await this.workspaceModel.exists({
      workspace_url: `${uniqueName}`,
    });

    while (!!exists) {
      uniqueName = uniqueNamesGenerator({
        dictionaries: [adjectives, starWars, numberDictionary],
        length: 3,
        separator: '',
        style: 'lowerCase',
      });
      exists = await this.workspaceModel.exists({ workspace_url: uniqueName });
    }

An in-range update of @typescript-eslint/parser is breaking the build 🚨

The devDependency @typescript-eslint/parser was updated from 2.19.0 to 2.19.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v2.19.1

2.19.1 (2020-02-10)

Bug Fixes

  • eslint-plugin: [unbound-method] blacklist a few unbound natives (#1562) (4670aab)
  • typescript-estree: ts returning wrong file with project references (#1575) (4c12dac)
Commits

The new version differs by 5 commits.

  • 1c8f0df chore: publish v2.19.1
  • 4c12dac fix(typescript-estree): ts returning wrong file with project references (#1575)
  • e9cf734 docs(eslint-plugin): fix typo in readme
  • 10d86b1 docs(eslint-plugin): [no-dupe-class-members] fix typo (#1566)
  • 4670aab fix(eslint-plugin): [unbound-method] blacklist a few unbound natives (#1562)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[Feature Request] : - Support for External Dictionaries

As a user, I should be able to pass my own dictionaries to get my preferred style of random names .
Example.
Following input should generate random names like "Brash_ProfessorX" , "Goldern_Wolverine" etc. i.e. formed out of combination of randomly selected values for each key in the input JSON

{
"ADJECTIVES":[
"Abrasive",
"Brash",
"Callous",
"Daft",
"Eccentric",
"Fiesty",
"Golden",
"Holy",
"Ignominious",
"Joltin",
"Killer",
"Luscious",
"Mushy",
"Nasty",
"OldSchool",
"Pompous",
"Quiet",
"Rowdy",
"Sneaky",
"Tawdry",
"Unique",
"Vivacious",
"Wicked",
"Xenophobic",
"Yawning",
"Zesty"
],
" XMEN":[
"ProfessorX",
"Beast",
"Colossus",
"Cyclops",
"Iceman",
"MarvelGirl",
"Storm",
"Wolverine",
"Shadowcat",
"Nightcrawler",
"Rogue",
"Angel",
"Dazzler",
"Syndicate",
"Magician",
"Bishop",
"Pyro",
"Psylocke",
"Toad",
"Firestar"
]
}

Numbers Dictionary does not respect seed

The following code taken from the NumberDictionary example with an added seed: 0 will return different 3 digits when run at different times. This means that, although the generator is stable within the same run, the NumberDictionary.generate call introduces some kind of randomness that is not ruled by the seed:

const { uniqueNamesGenerator, NumberDictionary } = require('unique-names-generator');

const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 });
const characterName = uniqueNamesGenerator({
dictionaries: [['Dangerous'], ['Snake'], numberDictionary],
  length: 3,
  separator: '',
  style: 'capital',
  seed: 0,
}); 

characterName

Copy and paste this code to a node interactive session, then exit the session, enter again and run it again. The characterName is the same except for the numbers.

dictionary of numbers

would be nice to specify a dictionary of numbers with variable length, without having to create it ourselves as a custom dictionary

to create names such as DangerousSnake456

How is uniqueness ensured?

This looks like a nice project!

I browsed through the docs and the code but could not find anything that would ensure uniqueness of the generated names. Am I missing something?

Low number of combinations when using user-provided seed

The word generator uses the same seed for all the dictionaries:

const rnd = Math.floor((this.seed ? getFromSeed(this.seed) : Math.random()) * curr.length);

This results in a low number of combinations when combining dictionaries. See this example with 2 dictionaries with 4 words each:

https://codesandbox.io/s/unique-names-generator-forked-sbxpo?file=/src/index.ts

  const numbers = ["1", "2", "3", "4"];
  const letters = ["A", "B", "C", "D"];

  const config: Config = {
    dictionaries: [numbers, letters],
    separator: "-",
    length: 2,
    style: "capital",
    seed: Math.random() * 4294967296
  };

  const randomString = uniqueNamesGenerator(config);

The only possible outputs are 1-A, 2-B, 3-C, 4-D.

This issue only affects users that provide a seed parameter. The default behavior of using Math.random() works fine, because a new random number is generated for each dictionary.

removing the colors from adjactives

Hi,
When creating random names, with combination of colors+adjactives+animals creates names likes red_grey_monkey etc. It would be nice if the adjective library does not contain colors or maybe some kind of filtering?

cheers!

Name words are in dictionary order only.

I just started using unique names generator, thank you for working on this! My code essentially is:

import { uniqueNamesGenerator, Config, adjectives, colors, animals, names, languages } from 'unique-names-generator';
...
    static NAME_CONFIG: Config = {
        dictionaries: [animals, adjectives, colors, names, languages],
        separator: ' ',
        length: 2,
        style: 'capital'
    };
...
name = uniqueNamesGenerator(GekModel.NAME_CONFIG);

I have generated >100 names, 100% of them are two words, where the first word is whichever dictionary is listed first in the config; and the second word is whichever dictionary is listed second in the config. In the code I've included that means they're all names like "Deer Old" or ""Raccoon Victorious". If I change the config to list dictionaries in the order of "[adjectives, colors, animals, names, languages]" then I only get names like "Flaky Black" or "Combative Beige".

I would expect that the names use all the dictionary words in random order. Is there a configuration option or parameter that I'm missing? Or is this a bug?

THanks!

An in-range update of @typescript-eslint/eslint-plugin is breaking the build 🚨

The devDependency @typescript-eslint/eslint-plugin was updated from 2.19.0 to 2.19.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/eslint-plugin is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v2.19.1

2.19.1 (2020-02-10)

Bug Fixes

  • eslint-plugin: [unbound-method] blacklist a few unbound natives (#1562) (4670aab)
  • typescript-estree: ts returning wrong file with project references (#1575) (4c12dac)
Commits

The new version differs by 5 commits.

  • 1c8f0df chore: publish v2.19.1
  • 4c12dac fix(typescript-estree): ts returning wrong file with project references (#1575)
  • e9cf734 docs(eslint-plugin): fix typo in readme
  • 10d86b1 docs(eslint-plugin): [no-dupe-class-members] fix typo (#1566)
  • 4670aab fix(eslint-plugin): [unbound-method] blacklist a few unbound natives (#1562)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

too long of a seed yields bad result

e.g. 481205670100679769679798 yields one thing but anything longer than this integer gives same result as 0

Ideally I'd like to give a string seed and get a unique name from the string, I was doing some string to int conversions but when they got too long they were all the exact same.

const customConfig = {
  dictionaries: [adjectives, colors, animals],
  length: 2,
  separator: ' ',
  style: 'capital',
  seed: encoded
};

Crashes when using Create-React-App

Hi!

Using Create-React-App (latest version right now) with Typescript in a yarn workspace monorepo, importing and using this library resulted in the following error when trying to start the application for development:

[start:web     ] i 「wds」: Project is running at http://<ip>/
[start:web     ] i 「wds」: webpack output is served from /
[start:web     ] i 「wds」: Content not from webpack is served from D:\Development\app\packages\web\public
[start:web     ] i 「wds」: 404s will fallback to /index.html
[start:web     ] Starting the development server...
[start:web     ] 
[start:web     ] FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[start:web     ]  1: 00007FF76645F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
[start:web     ]  2: 00007FF76643A0C6 node::MakeCallback+4518
[start:web     ]  3: 00007FF76643AA30 node_module_register+2032
[start:web     ]  4: 00007FF7666C20EE v8::internal::FatalProcessOutOfMemory+846
[start:web     ]  5: 00007FF7666C201F v8::internal::FatalProcessOutOfMemory+639
[start:web     ]  6: 00007FF766BE2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
[start:web     ]  7: 00007FF766BD9C46 v8::internal::ScavengeJob::operator=+24310
[start:web     ]  8: 00007FF766BD829C v8::internal::ScavengeJob::operator=+17740
[start:web     ]  9: 00007FF766BE0F87 v8::internal::Heap::MaxHeapGrowingFactor+2327
[start:web     ] 10: 00007FF766BE1006 v8::internal::Heap::MaxHeapGrowingFactor+2454
[start:web     ] 11: 00007FF76679CDB7 v8::internal::Factory::NewFillerObject+55
[start:web     ] 12: 00007FF766832CC6 v8::internal::WasmJs::Install+29414
[start:web     ] 13: 000000D4B275C5C1
[start:web     ] error Command failed with exit code 134.
[start:web     ] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[start:web     ] error Command failed.
[start:web     ] Exit code: 134
[start:web     ] Command: C:\Program Files\nodejs\node.exe
[start:web     ] Arguments: C:\Users\Maurice\AppData\Roaming\npm\node_modules\yarn\lib\cli.js start
[start:web     ] Directory: D:\Development\app\packages\web
[start:web     ] Output:
[start:web     ] 
[start:web     ] info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
[start:web     ] error Command failed with exit code 134.
[start:web     ] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "start:web" exited with 134.

When removing the code snippet below, the application started working again

const randomName = uniqueNamesGenerator({
  length: 2,
  separator: ' ',
  style: 'capital',
  dictionaries: [colors, animals]
});

seeding the generator

hello friend, this looks like a wonderful library!

i was thinking i'd like to generate random nicknames as defaults for my users

i'd like to seed the name generator with the email address of the user -- so that if re-authentication ever occurred, the user would receive the same pseudorandomly generated name

i wonder how we could implement this?

cheers!

  👋 chase

Remove the 'fucking'

This is a good library, but the 'fucking' adjective is too far in my opinion and should be removed.

/lib/dictionaries/adjectives.ts line 903

I used the library to generate data for a quick mockup and it created "fucking_black_beaver" during a demonstration. It did not go down well.

Using Ethereum addresses as seed issue

Hello,

I am using your package with Ethereum addresses as a seed (with the 0x prefix removed) and the dictionaries adjectives and animals. It appears that some adjectives and animals will never (or extremely rarely?) be used when calling uniqueNamesGenerator with the address as a seed but others will be very often.

For instance, if I want to generate a vanity name (i.e. I want my name generated from the ETH address to contains whale, see script below)

  • I generate an ETH address and generate the unique name from it
  • I check if the name contains whale
  • If yes I return the keypair, else I continue

The expected outcome is that every time I run the vanity name generator, I get an {adjective} + Whale nickname, where {adjective} is one of the many adjectives in the dictionary.

But in reality, it will very often be the same adjective, here is a sample of 100 generated names that includes Whale (each one was generated using a different ETH address):

InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
DigitalWhale
InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
InternalWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
DigitalWhale
DigitalWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
DigitalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
DigitalWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
DigitalWhale
RemarkableWhale
RemarkableWhale
InternalWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
RemarkableWhale
InternalWhale
InternalWhale
RemarkableWhale
InternalWhale

I think there is an issue in how the seed is generated from a string, perhaps it is too big? Also, if tou try using a VERY big number as a seed, you will always end up with the same name, so I think there is an issue with the seed.

Script to generate vanity names:

const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator');
var Web3 = require('web3');

const arg = process.argv[2];

const web3 = new Web3();

if (!arg) {
  const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  readline.question('Vanity name should include: ', (contains) => {
    console.log(`Searching name with ${contains}!`);
    readline.close();
    
    generateVanityName(contains);
  });
} else {
  console.log(`Searching name with ${arg}!`);
  generateVanityName(arg);
}

function generateNameFromAddress(address) {
  const customConfig = {
    dictionaries: [adjectives, animals],
    separator: '',
    length: 2,
    seed: address,
    style: 'capital',
  };

  return uniqueNamesGenerator(customConfig);
}

function generateVanityName(contains) {
  let account;
  let name;
  do {
    account = web3.eth.accounts.create();
    name = generateNameFromAddress(account.address.replace('0x', ''));
  } while (!name || !name.toLowerCase().includes(contains.toLowerCase()));

  console.log(account);
  console.log(name);
  return;
}

How to disclude "Ethnic" adjectives?

The adjective dictionary sometimes contains ethnic adjectives such as "american", "jewish", "iraqi", etc. Is there a way to exclude all ethnic adjectives from the generator?

What about i18n ?

Hi!
I would like to know whether you would consider a PR adding support for i18n?

Names not defaulting to lowerCase, or respecting `type` option

This snippet returns names capitalised, but colors and animals lowerCase:

const {
  uniqueNamesGenerator,
  colors,
  animals,
  names,
} = require("unique-names-generator");

const folderName = uniqueNamesGenerator({
  dictionaries: [colors, animals, names],
  separator: "-",
  type: "lowerCase",
});

console.log(folderName);

Using version 4.4.0

Add a link to an online generator demo for mock-ups

Hello, I am looking to use something like this for my project, but I am currently in the note-taking and mock-up phase, so it would be cool to have a website (e.g. hosted on GitHub pages in another repository) that lets me generate plenty of names for testing/fun.

I haven't looked into this project much, but I am assuming this is mostly trivial given the generator is written in typescript.

Thanks in advance!

Feature Proposal

This use case arose in my implementation while i was using the package in a project.
Right now, dictionaries are not being used randomly, for example: if length is 2, and dictionaries are 3 (dic1, dic2, dic3). The package always used first 2 instead of picking any two randomly.

Here's i got around this,

      const customDictionary = [[colors, animals], [adjectives, animals]]
      const whichDictionary = Math.floor(Math.random() * 2);// 0 or 1, chose a combination, this could be generated randomly upto length and those many dictionaries can be chosen and used.
        uniquename: uniqueNamesGenerator({
          dictionaries: customDictionary[whichDictionary],
          length: 2,
          separator: "",
        });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.