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 thev3 Docs
For the version 1 & 2, please refer to thev2 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.
$ node --version
v7.10.1
$ npm --version
4.2.0
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, 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
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
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.
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.
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
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
Type: number
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.
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
import { uniqueNamesGenerator, Config, adjectives } from 'unique-names-generator';
const config: Config = {
dictionaries: [adjectives]
}
const characterName: string = uniqueNamesGenerator(config); // big
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
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
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
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
A list of languages
import { uniqueNamesGenerator, Config, languages } from 'unique-names-generator';
const config: Config = {
dictionaries: [languages]
}
const characterName: string = uniqueNamesGenerator(config); // polish
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
By default, the Unique name generator library comes with 3 dictionaries out of the box, so that you can use themstraight away.Starting from the version 4 of the library, however, you must explicitly provide the dictionaries within theconfiguration object.This is for reducing the bundle size and allowing tree shaking to remove the extra dictionaries from your bundle whenusing 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
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
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
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.
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
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 fromyour 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
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 thev4 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
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
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
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!
Generator 可选的<generator>子元素是一个Java类的名字, 用来为该持久化类的实例生成唯一的标识。如果这个生成器实例需要某些配置值或者初始化参数, 用<param>元素来传递。 <id name="id" type="long" column="cat_id"> <generator class="org.hibernate.id.TableHiLoGenera
描述 (Description) 我们可以使用由值组成的变量名来定义变量。 Example 以下示例演示了如何使用variable在LESS文件中保存另一个variable - <html> <head> <link rel = "stylesheet" href = "style.css" type = "text/css" /> <title>LESS Varia
此函数返回输入数组中的唯一元素数组。 该函数可以返回唯一值数组的数组和关联索引数组。 索引的性质取决于函数调用中返回参数的类型。 numpy.unique(arr, return_index, return_inverse, return_counts) Where, Sr.No. 参数和描述 1 arr 输入数组。 如果不是一维阵列,将会变平 2 return_index 如果为True,则返
UNIQUE The codebase for Uncertainty-aware blind image quality assessment in the laboratory and wild (TIP2021)and Learning to blindly assess image quality in the laboratory and wild (ICIP2020) Prequisi
主要内容:示例,删除 UNIQUE 约束SQL UNIQUE 约束也称“唯一约束”,设置了 UNIQUE 约束的字段,每条记录的值都必须是唯一的,因此 UNIQUE 约束可以防止两条记录在某个字段上出现重复值。例如在 CUSTOMERS 表中,要防止两个或者多个顾客出现相同的姓名。 UNIQUE 可以约束表的一个字段,也可以约束多个字段。此外,设置了 UNIQUE 约束的字段可以出现 NULL 值。 UNIQUE 和 PRIMARY K
MetaMask uses the Parity on-chain registry of function signatures to display method names on the confirm screen. For many common method names, like token methods, this allows MetaMask to successfully
tags: [DP_Matrix] Question lintcode: (114) Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right a