本文整理汇总了TypeScript中meteor/random.Random类的典型用法代码示例。如果您正苦于以下问题:TypeScript Random类的具体用法?TypeScript Random怎么用?TypeScript Random使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Random类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ballComponent
ballComponent(): { key: string, frame?: string, animation?: { frame: string, frames: string[], speed: number } } {
const ballImage = Random.choice(
[
'abdellah',
'cedric',
'christian',
'christophe',
'david',
'eugenie',
'francois',
'jm',
'jeff',
'julien',
'luc',
'macarena',
'mathieu',
'sarah',
'stephane',
'sylvain',
'vincent',
'yanick',
'yannick'
]
);
return {
key: 'devalto-skin',
frame: 'ball-' + ballImage
};
}
示例2: function
invite: function (user: Invitation) {
// check(partyId, String);
// check(userId, String);
// let party = Parties.findOne(partyId);
// if (!party)
// throw new Meteor.Error('404', 'No such party!');
// if (party.public)
// throw new Meteor.Error('400', 'That party is public. No need to invite people.');
// if (party.owner !== this.userId)
// throw new Meteor.Error('403', 'No permissions!');
// Parties.update(partyId, {$addToSet: {invited: userId}});
let token = Random.hexString( 16 );
let message = {
subject: "Invitation",
text: `Hi, I just invited you to be an user in my brand new app!.
\n\nCome check it out: ${Meteor.absoluteUrl()}acceptinvitation/${token}\n`
};
Invitations.insert({
// company: ['', Validators.required],
company: user.company,
name: user.name,
last_name: user.last_name,
email: user.email,
role: user.role,
phone: user.phone,
address: user.address,
city: user.city,
state: user.state,
postal_code: user.postal_code,
token: token,
invitation_date: user.invitation_date,
message: message,
invited_by: Meteor.userId
});
let _from = "your@e.mail";
let to = user.email;
// console.log(to, Meteor.isServer, user, token);
if (Meteor.isServer && to) {
Email.send({
from: _from,
to: to,
replyTo: _from || undefined,
subject: message.subject,
text: message.text
});
// console.log(token);
}
},
示例3: randomBonus
static randomBonus(gameConfiguration: GameConfiguration): BaseBonus {
let availableBonuses = this.availableBonuses();
if (gameConfiguration.overridesAvailableBonuses()) {
availableBonuses = gameConfiguration.availableBonuses();
}
const bonus = this.fromClassName(Random.choice(availableBonuses));
if (bonus instanceof RandomBonus) {
let availableBonusesForRandom = this.availableBonusesForRandom();
if (gameConfiguration.overridesAvailableBonusesForRandom()) {
availableBonusesForRandom = gameConfiguration.availableBonusesForRandom();
}
bonus.setRandomBonus(this.fromClassName(Random.choice(availableBonusesForRandom)));
}
return bonus;
}
示例4: constructor
constructor () {
this.isCartVisible = false;
if(localStorage.getItem("user_id") == null) {
localStorage.setItem("user_id", Random.id());
}
}
示例5: function
addUserProject: function(projectId: string, userEmail: string) {
let hasCreateUser = false;
if (Meteor.isServer) {
check(userEmail, String);
check(projectId, String);
let project = Projects.findOne(projectId);
let user = Meteor.user();
let pass = Random.id(8);
if (!user || !project) {
throw new Meteor.Error('403', 'not-authorized');
}
if (user._id !== project.owner) {
throw new Meteor.Error('403', 'not-authorized');
}
let userAdd = Meteor.users.findOne({ 'emails.0.address': userEmail });
if (!userAdd) {
let userId = Accounts.createUser({ email: userEmail, password: pass });
userAdd = Meteor.users.findOne(userId);
if (!userAdd) {
throw new Meteor.Error('404', 'user-not-found');
}
hasCreateUser = true;
}
let isIn = false;
project.users.forEach((userP) => {
if (userP.userId === userAdd._id) {
isIn = true;
}
});
if (!isIn) {
Projects.update(projectId, {
$push: {
users: {
email: userEmail,
userId: userAdd._id
}
}
});
}
this.unblock();
if (Meteor.isServer && hasCreateUser) {
// send email with password of account created.
// send the pass to the creator email ( not the invited user ( avoid spam ))
let to = user.emails[0].address
Email.send({
to: to,
from: process.env.MAIL_FROM,
subject: 'New user account created & invited',
text:
'You have invited a new user: "'+userEmail+'", his account has been created for you.\n'+
'Please give the your new collaborator his credentials: \n\n'+
'Login: ' + userEmail+'\n'+
'Password: ' + pass
});
}
}
return { hasCreateUser: hasCreateUser };
},