How to use the last function from chance

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

112
113
114
115
116
117
118
119
120
121
 */
APIRandom.name = function () {
  var opts = helpers.mix(arguments);
  var g = opts.gender ? {gender: opts.gender} : {};
  if (opts.first) return chance.first(g);
  if (opts.last) return chance.last(g);
  var m = {}, p = {}, prefix = '', name;
  if (opts.middle)
    m = opts.middle === 'full' ? {middle: true} : {middle_initial: true};
  if (opts.prefix) {
fork icon12
star icon33
watch icon3

+ 23 other calls in file

37
38
39
40
41
42
43
44
45
46
const person = {
  names: [{
    givenName: Chance.first({
      gender,
    }),
    familyName: Chance.last({
      gender,
    }),
  }],
  gender: gender.charAt(0),
fork icon8
star icon16
watch icon5

+ 9 other calls in file

26
27
28
29
30
31
32
33
34
35
}

function randUser () {
  return User.build({
    firstName: chance.first(),
    lastName: chance.last(),
    isAdmin: false,
    email: emails.pop(),
    gender: chance.gender(),
    dob: chance.birthday({ string: true }),
fork icon3
star icon12
watch icon6

+ 3 other calls in file

158
159
160
161
162
163
164
165
166
167
        min: -999999,
        max: 999999
    });
    break;
case 'last':
    s += chance.last().toCsv(CSV.delimiter);
    break;

case 'latitude':
    s += chance.latitude();
fork icon2
star icon8
watch icon0

12
13
14
15
16
17
18
19
20
21
exports.random = function(options) {
    return ch.pick(options)
}
exports.pick = exports.random
exports.firstName = function () { return ch.first() }
exports.lastName = function () { return ch.last() }
exports.gender = function () { return ch.gender() }
exports.company = function () { return ch.capitalize(ch.word({syllables: 3})) }
exports.email = function () { return ch.email() }
exports.phone = function () { return ch.phone() }
fork icon0
star icon2
watch icon1

+ 3 other calls in file

166
167
168
169
170
171
172
173
174
175
  },
  function (cb) {
      async.forEach(_.range(1, userCount + 1), function (nr, cb) {
          models.User.create({
              "firstName": chance.first(),
              "lastName": chance.last(),
              "email": "user" + nr + "@domain.com",
              "email_lowered": "user" + nr + "@domain.com",
              "passwordHash": defaultPasswordHash,
"userRoles": [{
fork icon0
star icon1
watch icon0

+ 3 other calls in file

16
17
18
19
20
21
22
23
24
25

const person = {
    type: spec.label,
    prefix: chance.prefix({gender: gender }),
    first: chance.first({gender: gender}),
    last: chance.last(),
    age: chance.age(),
    birthday: chance.birthday({string: true, american: true}),
    gender: gender,
    zip: chance.zip({plusfour: true}),
fork icon0
star icon1
watch icon0

28
29
30
31
32
33
34
35
36
37
38
  return 'http://api.randomuser.me/portraits/' + g + '/' + n + '.jpg'
}


function randUser () {
  return User.build({
    name: [chance.first(), chance.last()].join(' '),
    photo: randPhoto(),
    phone: chance.phone(),
    email: emails.pop(),
    password: chance.word(),
fork icon1
star icon0
watch icon0

+ 2 other calls in file

39
40
41
42
43
44
45
46
47
48
  })
})
describe('Create a user with existing email', () => {
  let res
  before(async () => {
    res = await register(chance.first(), chance.last(), process.env.EMAIL, process.env.PASSWORD)
  })

  it('check response status code', () => {
    expect(res.statusCode).to.eq(409)
fork icon0
star icon0
watch icon0

+ 2 other calls in file

11
12
13
14
15
16
17
18
19
20
const client = new CognitoIdentityProviderClient({region: 'us-east-1'});
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

8
9
10
11
12
13
14
15
16
17

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()
fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
15
16
describe('Space trimming test', ()=> {
  let testEmail = ' james' + Date.now() + '@pirate.com '
  let res


  before(async () => {
    await register(chance.first(), chance.last(), testEmail, process.env.PASSWORD)
    res = await  login(testEmail.trim(), process.env.PASSWORD)
  })


  it('check if spaces are trimmed', () => {
fork icon0
star icon0
watch icon0

8
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

33
34
35
36
37
38
39
40
41
42
43
44
	return chance.floating(options)
}


// last
export function last (options) {
	return chance.last(options)
}


// sentence
export function n (options) {
fork icon0
star icon0
watch icon0

81
82
83
84
85
86
87
88
89
90
}

var gender = chance.pick(['Male', 'Female', 'Other']);
var first = chance.first({gender: genderToBinary(gender)});
var middle = chance.pick(['', chance.first({gender: genderToBinary(gender)})]);
var last = chance.last();

var degree_goal = chance.pick(['', 'D', 'M', 'H', 'S']);

var major;
fork icon0
star icon0
watch icon4

+ 3 other calls in file

123
124
125
126
127
128
129
130
131
132

const generate = () => {
    return {
        name: {
            givenName: chance.first(),
            familyName: chance.last()
        },
        emailAddress: chance.email(),
        emailType: 'Home',
        phoneNumber: chance.phone(),
fork icon0
star icon0
watch icon0

+ 3 other calls in file