GithubHelp home page GithubHelp logo

andreasonny83 / unique-names-generator Goto Github PK

View Code? Open in Web Editor NEW
565.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 Issues

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.

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!

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

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 🌴

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

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: "",
        });

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.

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 🌴

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;
}

What about i18n ?

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

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 });
    }

[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"
]
}

Different string seeds but same results

const seed1 = "0_1B:10_2B:12_3B:5_4B:5_ST:6"; const seed2 = "0_1B:10_2B:10_3B:6_4B:5_ST:7";

Hey!
Recently I noticed that if I passed these two different string to seed, the result would be same.

image

Here is my testing repo. Feel free to check it out.

Currently, I solved this issue by using stringToSeed function, simply convert string to number, and the issue is gone. Yet I'm still curious about the reason of the coincidence shown above.

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?

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
};

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?

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!

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.

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!

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

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]
});

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.