Giter Site home page Giter Site logo

unique-word-generator's Introduction

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

unique-word-generator's People

Contributors

przemyslaw-zan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.