本文整理汇总了TypeScript中faker.image.avatar方法的典型用法代码示例。如果您正苦于以下问题:TypeScript image.avatar方法的具体用法?TypeScript image.avatar怎么用?TypeScript image.avatar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类faker.image
的用法示例。
在下文中一共展示了image.avatar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const createMessage = (channelId) => {
return {
id: faker.random.uuid(),
content: faker.lorem.sentence(),
creationTime: faker.date.past().getTime().toString(),
author: {
name: faker.name.firstName() + '.' + faker.name.lastName(),
avatar: faker.image.avatar(),
},
channel: { id: channelId },
};
};
示例2:
users.map(async (userData) => {
const { username, password } = userData;
const user = await AccountsServer.findUserByUsername(username);
if (!user) {
AccountsServer.createUser({
username,
password,
profile: {
avatar: faker.image.avatar(),
name: username + ' ' + username,
}
});
}
});
示例3: createFakeRowObjectData
createFakeRowObjectData(index: number): Object {
return {
id: index,
avartar: faker.image.avatar(),
city: faker.address.city(),
email: faker.internet.email(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
street: faker.address.streetName(),
zipCode: faker.address.zipCode(),
date: faker.date.past(),
bs: faker.company.bs(),
catchPhrase: faker.company.catchPhrase(),
companyName: faker.company.companyName(),
words: faker.lorem.words(),
sentence: faker.lorem.sentence(),
};
}
示例4: getFakerData
/**
* Use faker to generate metadata for the inputs
* @param {type}
* the type of input to generate metadata for
*/
getFakerData(type): any {
switch (type) {
case 'string':
return faker.lorem.sentence();
case 'boolean':
return Math.random() > 0.5;
case 'sentence':
return faker.lorem.sentence();
case 'image':
let width = Math.floor(Math.random() * (500 - 300 + 1) + 300);
let height = Math.floor(Math.random() * (300 - 250 + 1) + 300);
return faker.image.imageUrl(width, height);
case 'avatar':
return faker.image.avatar();
case 'words':
return faker.lorem.words();
case 'phone':
return faker.phone.phoneNumber();
case 'name':
return faker.name.findName();
default:
return null;
}
}
示例5: addFakeUsers
async addFakeUsers(count: number = 20) {
let i = count;
while (i--) {
try {
let password = faker.internet.password();
const { user, channel } = await userController.create({ id: null }, {
_id: undefined,
name: faker.name.findName(),
email: faker.internet.email(),
country: faker.address.countryCode(),
password: password,
profileImg: faker.image.avatar(),
description: faker.lorem.sentence()
});
console.log(i, 'user-id:', user._id, ' channel-id:', channel._id);
} catch (error) {
console.error('USER ERROR', error);
}
}
process.exit();
},
async checkUser(id: string) {
const user = await userController.findById({ id }, id);