當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript random.Random類代碼示例

本文整理匯總了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
		};
	}
開發者ID:clesquir,項目名稱:js-volemon,代碼行數:30,代碼來源:DevaltoSkin.ts

示例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);
      }
  },
開發者ID:p3140,項目名稱:angular2-meteor-starter-kit,代碼行數:55,代碼來源:methods.ts

示例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;
	}
開發者ID:clesquir,項目名稱:js-volemon,代碼行數:21,代碼來源:BonusFactory.ts

示例4: constructor

 constructor () {
   this.isCartVisible = false;
   if(localStorage.getItem("user_id") == null) {
       localStorage.setItem("user_id", Random.id());
   }
 }
開發者ID:Apetrich,項目名稱:square-meter,代碼行數:6,代碼來源:cart.ts

示例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 };
	},
開發者ID:djulls07,項目名稱:projects-manager,代碼行數:62,代碼來源:projects.ts


注:本文中的meteor/random.Random類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。