How to use the string function from chance

Find comprehensive JavaScript chance.string code examples handpicked from public code repositorys.

26
27
28
29
30
31
32
33
34

deferred.then(() => {
  console.log(); // eslint-disable-line no-console
  for (let i = 0; i < numPatients; i++) {
    const gender = Chance.gender();
    const omrsId = Chance.string({
      pool: REFAPP_OPENMRS_ID_CHARS,
    });
    const bday = Chance.birthday();
fork icon8
star icon16
watch icon5

+ 9 other calls in file

64
65
66
67
68
69
70
71
72
73
 * @param {number} min
 * @param {number} max
 * @param {string} pool
 */
string(min = 5, max = 20, pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_') {
  return chance.string({ length: rand(min, max), pool });
},

/**
 * Return a random floating point number. By default it will return a fixed number of at most 2 digits after the decimal.
fork icon5
star icon0
watch icon1

+ 3 other calls in file

38
39
40
41
42
43
44
45
46
47
    s += chance.age();
    break;
case 'alpha': //alpha or alpha(n)
    n = hdr[k].arg;
    if (n != "") {
        s += chance.string({
            pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
            length: n
        });
    } else {
fork icon2
star icon8
watch icon0

+ 5 other calls in file

11
12
13
14
15
16
17
18
19
20
21
22
} = require('../../test-helpers/queries-and-mutations')
const chance = require('chance').Chance()


describe('e2e test for tweet', () => {
  let token, tweetAResp, userAId, userBId, userBsReply, userBToken
  const text = chance.string({length: 16})


  before(() => {
    cy.task('signInUser').then(({username, accessToken}) => {
      userAId = username
fork icon0
star icon3
watch icon0

+ 11 other calls in file

12
13
14
15
16
17
18
19
20
21
const suffix = chance.string({
  length: 4,
  pool: 'abcdefghijklmnopqrstuvwxyz',
});
const name = `${firstName} ${lastName} ${suffix}`;
const password = chance.string({ length: 8 });
const email = `${firstName}-${lastName}-${suffix}@pethost.com`;
const address = chance.address();
const phone_number = '+15555555555';
const latitude = '-23.6298482';
fork icon0
star icon1
watch icon0

15
16
17
18
19
20
21
22
23
24
    userAttributes = {
        email: chance.email(),
        password: chance.string({min: 8})
    };
    jwtToken = chance.string();
    jwtSecret = chance.string();
});

beforeAll(async () => {
    await databaseService.connectToTestMongoDatabase();
fork icon0
star icon0
watch icon1

+ 2 other calls in file

5
6
7
8
9
10
11
12
13
14
15
16
const catchErrors = require('../Utils/catchErrors')
const customError = require('../Utils/customError')
const sendMail = require('../Utils/Email')


const generateRandomStr = (length) => {
    return chance.string({ length })
}


// Creates Token, Used internally
const createToken = (email) => {
fork icon0
star icon0
watch icon0

1
2
3
4
5
6
7
8
9
10
const AWS = require('aws-sdk')
const velocityUtil = require('amplify-appsync-simulator/lib/velocity/util')
const a_random_user = () => {
    const firstName = chance.first({ nationality: 'en' })
    const lastName = chance.first({ nationality: 'en' })
    const suffix = chance.string({ length: 4, pool: 'abcdefghijklmnopqrstuvwxyz' })
    const name = `${firstName} ${lastName} ${suffix}`
    const password = chance.string({ length: 8 })
    const email = `${firstName}-${lastName}-${suffix}@appsyncmasterclass.com`

fork icon0
star icon0
watch icon0

12
13
14
15
16
17
18
19
20
const userpoolId = process.env.cognito_user_pool_id;
const clientId = process.env.cognito_server_client_id;

const firstName = chance.first({nationality: 'en'});
const lastName = chance.last({nationality: 'en'});
const suffix = chance.string({length: 4, pool: 'abcdefghijklmnopqrstuvwxyz'});
const username = `test-${firstName}-${lastName}-${suffix}`;
const password = randomPassword();
const email = `${firstName}-${lastName}@big-mouth.com`;
fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
const userpoolId = process.env.cognito_user_pool_id
const clientId = process.env.CognitoUserPoolServerClientId

const firstName = chance.first({ nationality: 'en' })
const lastName = chance.last({ nationality: 'en' })
const suffix = chance.string(
  { length: 8, pool: 'abcdefghijklmnopqrstuvwxyz' })
const username = `test-${firstName}-${lastName}-${suffix}`
const password = random_password()
const email = `${firstName}-${lastName}@big-mouth.com`
fork icon0
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
const userpoolId = process.env.cognito_user_pool_id
const clientId = process.env.cognito_server_client_id

const firstName = chance.first({ nationality: "en" })
const lastName  = chance.last({ nationality: "en" })
const suffix    = chance.string({length: 8, pool: "abcdefghijklmnopqrstuvwxyz"})
const username  = `test-${firstName}-${lastName}-${suffix}`
const password  = random_password()
const email     = `${firstName}-${lastName}@big-mouth.com`
fork icon0
star icon0
watch icon0

1
2
3
4
5
6
7
8
9
10
const { dateselection } = require("../library/Login_fn");
const assert = require("chai").assert;
const should = require("chai").should();
const chance = require("chance").Chance();
const nameofuser = chance.name({ length: 5 });
const password = chance.string({
  alpha: true,
  symbols: true,
  length: 8,
  numeric: true,
fork icon0
star icon0
watch icon0

14
15
16
17
18
19
20
21
22
23
beforeEach(() => {
    ticketAttributes = {
        TicketNumber:  String(chance.integer({min: 0})),
        Ship_by_Date: chance.date({string: true}),
        OrderDate: chance.date({string: true}),
        CustPONum: chance.string(),
        Priority: chance.pickone(getAllPriorities()),
        BillZip: chance.string(),
        BillCity: chance.string(),
        BillAddr1: chance.string(),
fork icon0
star icon0
watch icon0

+ 147 other calls in file

121
122
123
124
125
126
127
128
129
130

beforeEach(() => {
    ticket = {
        [TICKET_ITEM_KEY]: [
            {
                'attribute1': chance.string(),
                'attribute2': undefined,
                'attribute3': '',
                'attribute4': {},
                'attribute5': [{}, {}],
fork icon0
star icon0
watch icon0

+ 5 other calls in file

10
11
12
13
14
15
16
17
18

    expect(actualValue).toEqual(expectedValue);
});

it ('should return the value passed in if value is defined', () => {
    const value = chance.string();
    const expectedValue = value;
    
    const actualValue = helperService.getEmptyObjectIfUndefined(value);
fork icon0
star icon0
watch icon0

2
3
4
5
6
7
8
9
10
11
12


const createRandomVideo = index => ({
  id: index,
  name: chance.sentence({ words: 3 }),
  downloadurl: chance.url(),
  sha256: chance.string({ length: 64, pool: "abcdef0123456789" }),
  description: chance.sentence({ word: 10 }),
  created_at: chance.date().toJSON(),
  updated_at: chance.date().toJSON()
});
fork icon0
star icon0
watch icon0

109
110
111
112
113
114
115
116
117
function gen_phone() {
   var digits = '0123456789';
   function maybeHyphen() {
      return chance.pick(['', '-']);
   }
   return chance.string({pool: digits, length: 3}) +
      maybeHyphen() + chance.string({pool: digits, length: 3}) +
      maybeHyphen() + chance.string({pool: digits, length: 4});
}
fork icon0
star icon0
watch icon4

+ 19 other calls in file