2.0.1 • Published 3 months ago

random-words v2.0.1

Weekly downloads
16,984
License
MIT
Repository
github
Last release
3 months ago

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.

The seed option can be used with the generate function for situations that require deterministic output. When given the same seed with the same input, generate() will yield deterministic results, in regards to both actual word selection and the number of words returned (when using min and max). The underlying implementation of this option utilizes the seedrandom package as a replacement for Math.random().

The count function can be used to calculate the total number of words in the word list that meet the specified minimum and maximum length criteria.

Installation:

npm install random-words

Examples:

import { generate, count } from "random-words";

console.log(generate());
//output: 'army'

console.log(generate(5));
//output: ['army', 'beautiful', 'became', 'if', 'actually']

console.log(generate({ minLength: 2 }));
//output: 'hello'

console.log(generate({ maxLength: 6 }));
//output: 'blue'

console.log(generate({ minLength: 5, maxLength: 5 }));
//output : 'world'

console.log(generate({ minLength: 11, maxLength: 10000 })); //maxLength limited to the longest possible word
//output: 'environment'

console.log(generate({ minLength: 10000, maxLength: 5 })); //minLength limited to the maxLength
//output: 'short'

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

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

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

// this call will yield exactly the same results as the last since the same `seed` was used and the other inputs are identical
console.log(generate({ min: 2, max: 3, seed: "my-seed" }));
//output: ['plenty', 'pure']

console.log(generate({ exactly: 5, join: " " }));
//output: 'army beautiful became if exactly'

console.log(generate({ exactly: 5, join: "" }));
//output: 'armybeautifulbecameifexactly'

console.log(generate({ exactly: 2, minLength: 4 }));
//output: ['atom', 'window']

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

console.log(generate({ exactly: 2, minLength: 3, maxLength: 3 }));
//output: ['you, 'are']

console.log(generate({ exactly: 3, minLength: 5, maxLength: 100000 }));
//output: ['understanding', 'should', 'yourself']

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

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

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

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

console.log(count());
//output: 1952

console.log(count({ minLength: 5 }));
//output: 1318 

console.log(count({ maxLength: 7 }));
//output: 1649

console.log(count({ minLength: 5, maxLength: 7 }));
//output: 1015
@balena/jellyfish-test-harnessklassi-cucumber-jsmoonpay-apibetter-disco-oauthmonochromishuser-verifyejz-helpers-nodefolderbeamwebdriverio-cucumber-jsnodespull@infinitebrahmanuniverse/nolb-random-w@nodespull/corepass-lockerfafboi@everything-registry/sub-chunk-2529machinery-area-did-slightmad-slide-brickmany-ironmaking-month-test-namemanaged-public-desert7manufacturing-sent0manufacturing-detail-electricmany-across-web3-keepman-through3manner-consonant-brick3on-detail-jump-repliedone-bottle-web3-listpack-iron-web3-arrowourselves-shout-web3-woreoutline-below-height5outside-visitorour-several-usual-betown-stop-torn-giftoxygen-missing-different-happenedown-brought-disappearorganized-represent-vegetable-thickorbit-card-cloudpage-top-sunlightpaint-night-web3-globepaint-screen-web3-chosepalace-needs-product-countryproduct-slight-adult-settlersproduct-nest-saidprocess-sometime-shopproblem-fur-everyproblem-post-cabinpromised-spring-were-inventedpower-eager-sizeprepare-magic-planeprepare-next-farmer8pride-lesson-single-heavypretty-zebra-horse0price-instance-directlyprice-forwardprevent-camp8private-organization-kept-whalepractice-needs-very4practice-neighbor-lotproperty-previous-lack-interiorprotection-excited3prove-loss1prove-solidprovide-shaking-problempopular-bus-web3-animalprotection-make-web3-hugepull-sent-notice-tryputting-extra-oneputting-orbit-statementputting-recall-soap-milepurpose-relationship-soundquick-hungry-web3-troublequiet-troops-web3-circusquite-youngquickly-warmrate-today-explanationrate-early-factor-influencerain-hurt-gettingrain-simply-possibly-marriedranch-largest-web3-difficultran-nice-web3-flightrather-went-rate-seriousrather-finest-check-tearsrather-leader-proud0rays-glassrays-better-lungs6program-fifteen-web3-mapmoving-orbit-web3-wonderfulmonkey-been-pair6monkey-tropicalmore-brief-prizemoonchrisir-web3-assetsmaterial-balance-trade-solarmatter-heart-small8matter-hunter-safetymassage-square-studying-crossmaterial-news-web3-gainname-nest-discovermysterious-centmeat-think-stove8me-brain-web3-everybody
2.0.1

3 months ago

2.0.0

11 months ago

1.3.0

1 year ago

1.2.1

1 year ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

4 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.1

11 years ago