This library generates a word that (most likely) does not exist in English language yet. It does that by mixing random parts of two already existing english words together. By using existing words, results sound a lot more believable than random string of characters. To see example implementation of the library, go here.
Import with ES modules...
import getUniqueWord from 'unique-word-generator';
...or with CommonJS...
const getUniqueWord = require( 'unique-word-generator' );
... and execute!
const options = {
prefix: 'foo',
maxLength: 10
};
const result = getUniqueWord( options );
console.log( result.word );
None of those options are required. They can be used to influence the outcome of the randomness.
Name | Type | Description |
---|---|---|
prefix |
string |
Word to use as the source for the new word. |
suffix |
||
useFullPrefix |
boolean |
Whether to use the entire word instead of random part of it. |
useFullSuffix |
||
minLength |
number |
Minimal lenght of the generated word. This value can not exceed 20. |
maxLength |
Maximal length of the generated word. This value can not be lower than 2. |
Object with following values is returned buy the function:
Name | Type | Description |
---|---|---|
word |
string |
Freshly generated word. |
prefix |
Component string used to generate the word. |
|
suffix |
||
prefixSource |
Word that was used as a source of the component string used to generate the word. Absent if useFullPrefix option was set to true . |
|
suffixSource |
Word that was used as a source of the component string used to generate the word. Absent if useFullSuffix option was set to true . |
|
prefixCutIndex |
number |
Index along which source word was split. Absent if useFullPrefix option was set to true . |
suffixCutIndex |
Index along which source word was split. Absent if useFullSuffix option was set to true . |
|
error |
array<string> |
Mutually exclusive with all other values. Contains array of strings with descriptions of errors. |
When error happens, it is included in the array errors
of the returned object. In such case, all other values are absent from the returned object. Errors are caused by faulty options:
minLength
/maxLength
are not numbersminLength
above 20maxLength
below 2minLength
abovemaxLength
- Such combination of
prefix
,suffix
,useFullPrefix
anduseFullSuffix
options that makes fulfillment of passed or default values ofminLength
ormaxLength
impossible