Code Monkey home page Code Monkey logo

random-words's Introduction

random-words

Generate one or more common English words

random-words generates random words for use as sample text. We use it to generate random blog posts when testing Apostrophe.

Cryptographic-quality randomness is NOT the goal, as speed matters for generating sample text and security does not. As such, Math.random() is used in most cases. Alternatively, the seedrandom package is used when the seed option is used.

Installation:

npm install random-words

Examples:

var randomWords = require('random-words');

console.log(randomWords());
army

console.log(randomWords(5));
['army', 'beautiful', 'became', 'if', 'actually']

console.log(randomWords({ min: 3, max: 10 }));
['became', 'arrow', 'article', 'therefore']

console.log(randomWords({ exactly: 2 }));
['beside', 'between']

console.log(randomWords({ min: 2, max: 3, seed: 'my-seed' }));
console.log(randomWords({ min: 2, max: 3, seed: 'my-seed' }));
['plenty', 'pure']
['plenty', 'pure']

console.log(randomWords({ exactly: 5, join: ' ' }))
'army beautiful became if exactly'

console.log(randomWords({ exactly: 5, join: '' }))
    'armybeautifulbecameifexactly'

console.log(randomWords({exactly: 5, maxLength: 4}))
['army','come','eye','five','fur']

console.log(randomWords({exactly:5, wordsPerString:2}))
[ 'salt practical', 'also brief', 'country muscle', 'neighborhood beyond', 'grew pig' ]

console.log(randomWords({exactly:5, wordsPerString:2, separator:'-'}))
[ 'equator-variety', 'salt-usually', 'importance-becoming', 'stream-several', 'goes-fight' ]

console.log(randomWords({exactly:5, wordsPerString:2, formatter: (word)=> word.toUpperCase()}))
[ 'HAVING LOAD', 'LOST PINE', 'GAME SLOPE', 'SECRET GIANT', 'INDEED LOCATION' ]

console.log(randomWords({exactly:5, wordsPerString:2, formatter: (word, index)=> {
    return index === 0 ? word.slice(0,1).toUpperCase().concat(word.slice(1)) : word;
}}))
[ 'Until smoke', 'Year strength', 'Pay knew', 'Fallen must', 'Chief arrow' ]

random-words's People

Contributors

scoombe avatar mattveraldi avatar boutell avatar stretchkennedy avatar iamparadoxdotexe avatar thechickennagget avatar abea avatar andreigec avatar crlh 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.