Skip to content

This library generates a word that (most likely) does not exist in English language yet.

Notifications You must be signed in to change notification settings

przemyslaw-zan/unique-word-generator

Repository files navigation

Unique word generator

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.

Usage

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

Options

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.

Output

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.

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 numbers
  • minLength above 20
  • maxLength below 2
  • minLength above maxLength
  • Such combination of prefix, suffix, useFullPrefix and useFullSuffix options that makes fulfillment of passed or default values of minLength or maxLength impossible

About

This library generates a word that (most likely) does not exist in English language yet.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published