Gathering detailed insights and metrics for unique-names-generator
Gathering detailed insights and metrics for unique-names-generator
Gathering detailed insights and metrics for unique-names-generator
Gathering detailed insights and metrics for unique-names-generator
Generate unique and memorable name strings
npm install unique-names-generator
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
608 Stars
105 Commits
64 Forks
5 Watching
26 Branches
11 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
TypeScript (99.12%)
JavaScript (0.88%)
Cumulative downloads
Total Downloads
Last day
-3.1%
39,969
Compared to previous day
Last week
6.7%
223,423
Compared to previous week
Last month
3.4%
951,329
Compared to previous month
Last year
94.3%
11,228,501
Compared to previous year
More than 50,000,000 name combinations out of the box
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.
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
If you want to migrate, from an older version of the library to v4, 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.
1$ node --version 2v7.10.1 3 4$ npm --version 54.2.0
BEFORE YOU INSTALL: please read the prerequisites
Install the package using npm or Yarn
1$ npm i -S unique-names-generator
Or using Yarn
1$ yarn add unique-names-generator
1const { uniqueNamesGenerator, adjectives, colors, animals } = require('unique-names-generator');
2
3const randomName = uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] }); // big_red_donkey
4
5const shortName = uniqueNamesGenerator({
6 dictionaries: [adjectives, animals, colors], // colors can be omitted here as not used
7 length: 2
8}); // big-donkey
This package export a type definition file so you can use it, out of the box, inside your Typescript project.
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const customConfig: Config = { 4 dictionaries: [adjectives, colors], 5 separator: '-', 6 length: 2, 7}; 8 9const randomName: string = uniqueNamesGenerator({ 10 dictionaries: [adjectives, colors, animals] 11}); // big_red_donkey 12 13const shortName: string = uniqueNamesGenerator(customConfig); // big-donkey
Returns a string
with a random generated name
Type: Config
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.
1import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator'; 2 3const shortName: string = uniqueNamesGenerator({ 4 dictionaries: [colors, adjectives, animals] 5}); // red_big_donkey
Read more about the dictionaries and how to use them, in the Dictionaries section.
Type: string
required: false
Default: _
A string separator to be used for separate the words generated.
The default separator is set to _
.
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.
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
1import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator'; 2 3const capitalizedName: string = uniqueNamesGenerator({ 4 dictionaries: [colors, adjectives, animals], 5 style: 'capital' 6}); // Red_Big_Donkey 7 8const upperCaseName: string = uniqueNamesGenerator({ 9 dictionaries: [colors, adjectives, animals], 10 style: 'upperCase' 11}); // RED_BIG_DONKEY 12 13const lowerCaseName: string = uniqueNamesGenerator({ 14 dictionaries: [colors, adjectives, animals], 15 style: 'lowerCase' 16}); // red_big_donkey
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.
1import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator'; 2const config: Config = { 3 dictionaries: [adjectives, colors, animals], 4 separator: '-', 5 seed: 120498, 6}; 7 8const nameFromSeed: string = uniqueNamesGenerator(config); // continuous-gray-dragonfly
1import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator'; 2const config: Config = { 3 dictionaries: [adjectives, colors, animals], 4 separator: '-', 5 seed: 'you can use strings as a seed', 6}; 7 8const nameFromSeed: string = uniqueNamesGenerator(config); // stable-crimson-porpoise
This is a dynamic dictionary. Read more in the Numbers Dictionary section
A list of more than 1,400 adjectives ready for you to use
1import { uniqueNamesGenerator, Config, adjectives } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // big
A list of more than 350 animals ready to use
1import { uniqueNamesGenerator, Config, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [animals] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // donkey
A list of more than 50 different colors
1import { uniqueNamesGenerator, Config, colors } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [colors] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // red
A list of more than 250 different countries
1import { uniqueNamesGenerator, Config, countries } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [countries] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // United Arab Emirates
A list of more than 4,900 unique names
1import { uniqueNamesGenerator, Config, names } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [names] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // Winona
A list of languages
1import { uniqueNamesGenerator, Config, languages } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [languages] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // polish
A list of more than 80 unique character names from Star Wars
1import { uniqueNamesGenerator, Config, starWars } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [starWars] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // Han Solo
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:
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives, colors, animals] 5} 6 7const characterName: string = uniqueNamesGenerator(config); // red_big_donkey
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.
1import { uniqueNamesGenerator } from 'unique-names-generator'; 2 3const starWarsCharacters = [ 4 'Han Solo', 5 'Jabba The Hutt', 6 'R2-D2', 7 'Luke Skywalker', 8 'Princess Leia Organa' 9]; 10const colors = [ 11 'Green', 'Red', 'Yellow', 'Black' 12] 13 14const characterName: string = uniqueNamesGenerator({ 15 dictionaries: [colors, starWarsCharacters], 16 length: 2, 17 separator: ' ' 18}); // Green Luke Skywalker
You can easily generate random numbers inside your unique name using the Numbers dictionary helper.
1import { uniqueNamesGenerator, NumberDictionary } from 'unique-names-generator'; 2 3const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 }); 4const characterName: string = uniqueNamesGenerator({ 5dictionaries: [['Dangerous'], ['Snake'], numberDictionary], 6 length: 3, 7 separator: '', 8 style: 'capital' 9}); // DangerousSnake123
Returns a string
with a random generated number between 1 and 999
Type: Config
Type: number
required: false
default: 1
The minimum value to be returned as a random number
Type: number
required: false
default: 999
The maximum value to be returned as a random number
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.
You can reuse the dictionaries provided by the library. Just import the ones that you need and use them directly in your app.
1import { uniqueNamesGenerator, adjectives, colors } from 'unique-names-generator'; 2 3const improvedAdjectives = [ 4 ...adjectives, 5 'abrasive', 6 'brash', 7 'callous', 8 'daft', 9 'eccentric', 10]; 11const xMen = [ 12'professorX', 13'beast', 14'colossus', 15'cyclops', 16'iceman', 17'wolverine', 18]; 19 20const characterName: string = uniqueNamesGenerator({ 21 dictionaries: [improvedAdjectives, color, xMen], 22 length: 2, 23 separator: '-' 24}); // eccentric-blue-iceman
Unique names generator v4 implement a new breaking change.
dictionaries
configYou 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
1import { uniqueNamesGenerator } from 'unique-names-generator'; 2 3const randomName = uniqueNamesGenerator(); // big_red_donkey
v4
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives, colors, animals] 5} 6 7const randomName = uniqueNamesGenerator(config); // big_red_donkey
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:
This will now work only when a dictionaries
array is provided according to the
v4 breaking change.
v2
1import { uniqueNamesGenerator } from 'unique-names-generator'; 2 3const randomName = uniqueNamesGenerator();
v4
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives, colors, animals] 5} 6 7const randomName = uniqueNamesGenerator(config); // big_red_donkey
v2
1import { uniqueNamesGenerator } from 'unique-names-generator'; 2 3const shortName = uniqueNamesGenerator('-'); // big-red-donkey
v4
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives, colors, animals], 5 separator: '-' 6} 7 8const shortName = uniqueNamesGenerator(config); // big-red-donkey
The short
property has been replaced by length
so you can specify as many word as you want
v2
1import { uniqueNamesGenerator } from 'unique-names-generator'; 2 3const shortName = uniqueNamesGenerator(true); // big-donkey
v4
1import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator'; 2 3const config: Config = { 4 dictionaries: [adjectives, colors, animals], 5 length: 2 6} 7 8const shortName = uniqueNamesGenerator(config); // big-donkey
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
git checkout -b my-new-feature
git add .
git commit -am 'Add some feature'
git push origin my-new-feature
MIT License © Andrea SonnY
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!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More