Chance

You can use any of the random functions listed below from chance as generators.

The arguments you provide will be forwarded to the underlying chance method.

Let's use sentence as an example:

const { sentence } = require('chance-generators');
expect(sentence.take(3), "to equal", [
  "Gotsalda kodtac ewegute bibro celel taj sibsof buunu bave dolbaw gokim sab ziwiwwuh gib.",
  "Log sezsi ju bu mahbu wot cujduvtih le votevned esohogbi dadeip riide rohu jod tuhdulhak retijic ti luh.",
  "Ril dej fef wijug howeju tu caku vapiz soze wu tumit ede."
]);

You can specify how many words the sentence should have. This option will just be forwarded to the underlying sentence method:

expect(sentence({ words: 4 }).take(3), "to equal", [
  "Ofosid daej wocu ofaufjom.",
  "Be mabuj do lisib.",
  "Valbuunu bave dolbaw gokim."
]);

It is even possible to transform the generated values using map method.

expect(
  sentence({ words: 4 })
    .map(=> s.toUpperCase())
    .take(3),
  "to equal",
  ["OFOSID DAEJ WOCU OFAUFJOM.", "BE MABUJ DO LISIB.", "VALBUUNU BAVE DOLBAW GOKIM."]
);

Basics

Text

Person

Thing

Mobile

Web

Location

Time

Finance

Miscellaneous