More than 28,000,000 name combinations
This documentation is for the unique-names-generator
v3.
If you are still using an older version of the library, please refer to the
v2 Docs
If you want to migrate from al older version into v3, please read the Migration guide
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
- Unique Names Generator
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
const { uniqueNamesGenerator } = require('unique-names-generator');
const randomName = uniqueNamesGenerator(); // big_red_donkey
const shortName = uniqueNamesGenerator({ length: 2 }); // big-donkey
This package export a type definition file so you can use it, out of the box, inside your Typescript project.
import { uniqueNamesGenerator, UniqueNamesGeneratorConfig } from 'unique-names-generator';
const config: UniqueNamesGeneratorConfig = {
separator: '-',
length: 2.
};
const randomName: string = uniqueNamesGenerator(); // big_red_donkey
const shortName: string = uniqueNamesGenerator(config); // big-donkey
Returns a string
with a random generated name
Type: UniqueNamesGeneratorConfig
Type: string
Default: _
A string separator to be used for separate the words generated.
The default separator is set to _
.
Type: number
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)
Type: lowerCase | upperCase | capital
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: 'capital'
}); // RED_BIG_DONKEY
const lowerCaseName: string = uniqueNamesGenerator({
dictionaries: [colors, adjectives, animals],
style: 'capital'
}); // red_big_donkey
Type: array
Default: [adjectives, colors, animals]
This is an array of dictionaries. Each dictionary is an array of strings containing the words to use for generating the string.
The default dictionaries are provided in the following order: adjectives, colors and animals
. If you don't like them in this order you can still manually import them from the library, then overwrite the dictionaries with your custom order
import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';
const shortName: string = uniqueNamesGenerator({
dictionaries: [colors, adjectives, animals]
}); // red_big_donkey
By default, the Unique name generator library, come with 3 dictionaries out of the box so that you don't have to provide it manually. However, you might want to extend the provided dictionaries or completely replace with your custom ones 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
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, xMen],
length: 2,
separator: '-'
}); // eccentric-iceman
Unique names generator v3 implements a couple of breaking changes. If are bumping your local version to the v3, you might be interested in knowing the following:
This will still work. Invoking the uniqueNamesGenerator
function, will continue work as before 🎉
const { uniqueNamesGenerator } = require('unique-names-generator');
const randomName = uniqueNamesGenerator(); // big_red_donkey
v2
const shortName = uniqueNamesGenerator('-'); // big-red-donkey
v3
const shortName = uniqueNamesGenerator({ separator: '-' }); // big-red-donkey
The short
property has been replaced by length
so you can specify as many word as you want
v2
const shortName = uniqueNamesGenerator(true); // big-donkey
v3
const shortName = uniqueNamesGenerator({ length: 2 }); // big-donkey
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Add your changes:
git add .
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 😎
MIT License © Andrea SonnY
Thanks goes to these wonderful people (emoji key):
Andrea Z 💬 💻 📆 |
Baker 🐛 |
Anurag Jain 🤔 |
Deepak 📖 🤔 |
Abhijit Mehta 🤔 |
This project follows the all-contributors specification. Contributions of any kind welcome!