• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript randomstring.generate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中randomstring.generate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript generate函数的具体用法?TypeScript generate怎么用?TypeScript generate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了generate函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: test

test('user', async (x) => {
    let usermodel: any = models.User;
    //record the count
    let oldcount = (await usermodel.model.$count({ filter: { _status: 1 } })).data.count;
    let newrecords = [];
   // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await usermodel.model.$create({
            name: randomstring.generate(5),
            password: randomstring.generate(9),
            email: randomstring.generate(6) + '@qq.com',
            phone: randomstring.generate({
                length: 11,
                charset: 'numeric'
            })
        }));
    }
    let curcount = (await usermodel.model.$count({ filter: { _status: 1 } })).data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await usermodel.model.$delete(dellist);
    curcount = (await usermodel.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:28,代码来源:db.ts


示例2: test

test('user', async (x) => {
    //get usergroup
    let usergroupmodel: any = models.UserGroup;
    let usergroupdef = (await usergroupmodel.model.$paginate({ filter: { name: 'test' } })).data;
    usergroupdef = usergroupdef ? usergroupdef.list[0] : {};
    console.log('test usergroup');
    console.log(JSON.stringify(usergroupdef, null, 4));
    let usermodel: any = models.User;
    //record the count
    let countdata = (await usermodel.model.$count({ filter: { _status: 1 } }));
    let oldcount = countdata.data.count;
    let newrecords = [];
    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await usermodel.model.$create({
            name: randomstring.generate(5),
            password: randomstring.generate(9),
            email_value: randomstring.generate(6) + '@qq.com',
            phone_value: randomstring.generate({
                length: 11,
                charset: 'numeric'
            }),
            role: usergroupdef._id
        }));
    }
    let curcountres = (await usermodel.model.$count({ filter: { _status: 1 } }));
    console.log(curcountres);
    let curcount = curcountres.data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await usermodel.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await usermodel.model.$paginate({ limit:10});
    console.log(pageres);
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await usermodel.model.$delete(dellist);
    curcount = (await usermodel.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:57,代码来源:user.ts


示例3: test

test('note', async (x) => {
    let s_model: any = models.Note;
    //record the count
    let countdata = (await s_model.model.$count({ filter: { _status: 1 } }));
    console.log(countdata);
    let oldcount = countdata.data.count;
    let newrecords = [];
    //get one category
    let catamodel: any = models.Category;
    let catares = await catamodel.model.$paginate({ limit: 1 });
    //get two media
    let mediamodel: any = models.Media;
    let mediares = await mediamodel.model.$paginate({ limit: 2 });
    let mediaarr = mediares.data.list.map(x => x._id);
    console.log(mediaarr);

    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await s_model.model.$create({
            name: randomstring.generate(7),
            category: (catares.data.list)[0]._id,
            media: mediaarr.join(','),
            txt: randomstring.generate(40)
        }));
    }
    let curcountres = (await s_model.model.$count({ filter: { _status: 1 } }));
    //console.log(JSON.stringify(newrecords,null,4));
    let curcount = curcountres.data.count;
    //if 10 records have been created
   // x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await s_model.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await s_model.model.$paginate({ limit:10});
    //console.log(JSON.stringify(pageres,null,4));
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await s_model.model.$delete(dellist);
    curcount = (await s_model.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:56,代码来源:note.ts


示例4: test

test('mediaform', async (x) => {
    let s_model: any = models.MediaForm;
    //record the count
    let countdata = (await s_model.model.$count({ filter: { _status: 1 } }));
    let oldcount = countdata.data.count;
    console.log(`Before all tests,the count is ${oldcount}`);
    let newrecords = [];
    
    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await s_model.model.$create({
            name: randomstring.generate(7),
            width: 200,
            height: 300,
            code: randomstring.generate({
                length: 5,
                charset: 'numeric'
            }),
            needToUpload:false
        }));
    }
    //console.log(newrecords)
    let curcountres = (await s_model.model.$count({ filter: { _status: 1 } }));
    //console.log(curcountres);
    let curcount = curcountres.data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await s_model.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await s_model.model.$paginate({ limit:10});
    console.log(pageres);
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await s_model.model.$delete(dellist);
    curcount = (await s_model.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:54,代码来源:mediaform.ts


示例5: test

test('Category', async (x) => {
    let s_model: any = models.Category;
    //record the count
    let countdata = (await s_model.model.$count({ filter: { _status: 1 } }));
    let oldcount = countdata.data.count;
    let newrecords = [];
    //get one cover 
    let covermodel: any = models.Media;
    let coverres = await covermodel.model.$paginate({ limit: 1 });
    //get one user 
    let usermodel:any = models.User;
    let userres = await usermodel.model.$paginate({ limit: 1 });
   // console.log(coverres);
    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await s_model.model.$create({
            name: randomstring.generate(7),
            user: (userres.data.list)[0]._id,
            cover: (coverres.data.list)[0]._id,
            path: randomstring.generate(6) + '.jpg',
        }));
    }
    let curcountres = (await s_model.model.$count({ filter: { _status: 1 } }));
    //console.log(curcountres);
    let curcount = curcountres.data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await s_model.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await s_model.model.$paginate({ limit:10});
    //console.log(pageres);
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await s_model.model.$delete(dellist);
    curcount = (await s_model.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:54,代码来源:catagory.ts


示例6: test

test('Media', async (x) => {
    let s_model: any = models.Media;
    //record the count
    let countdata = (await s_model.model.$count({ filter: { _status: 1 } }));
    let oldcount = countdata.data.count;
    console.log(`Before all tests,the count is ${oldcount}`);
    let newrecords = [];
    //get one MediaForm 
    let i_model:any = models.MediaForm;
    let mediaform = await i_model.model.$paginate({ limit: 1 });
    console.log(JSON.stringify(mediaform,null,4));
    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await s_model.model.$create({
            name: randomstring.generate(6),
            form: (mediaform.data.list)[0]._id,
            path: randomstring.generate(10)
        }));
    }
    let curcountres = (await s_model.model.$count({ filter: { _status: 1 } }));
    //console.log(curcountres);
    let curcount = curcountres.data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await s_model.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await s_model.model.$paginate({ limit:10});
    //console.log(JSON.stringify(pageres,null,4));
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await s_model.model.$delete(dellist);
    curcount = (await s_model.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:51,代码来源:media.ts


示例7: test

test('usergroup', async (x) => {
    let s_model: any = models.UserGroup;
    //record the count
    let countdata = (await s_model.model.$count({ filter: { _status: 1 } }));
    let oldcount = countdata.data.count;
    let newrecords = [];
    
    // create 10 records
    for (let i = 0; i < 10; i++) {
        newrecords.push(await s_model.model.$create({
            name: randomstring.generate(7),
            code: randomstring.generate({
                length: 6,
                charset: 'numeric'
            })
        }));
    }
    let curcountres = (await s_model.model.$count({ filter: { _status: 1 } }));
  //  console.log(JSON.stringify(newrecords,null,4));
    let curcount = curcountres.data.count;
    //if 10 records have been created
    x.is(curcount, oldcount + 10);
    console.log('10 records have been created');
    //update 
    for (let i = 0; i < newrecords.length; i++) {
        let tt = newrecords[i];
        let uptbody = {
            id: tt.data._id,
            data: {
                name: tt.data.name + 'changed'
            }
        };
        //console.log(tt);
        //console.log(uptbody);
        let uptresult = await s_model.model.$update(uptbody);
        //console.log(uptresult);
       x.is(uptresult.data.name, tt.data.name + 'changed');
    }
    console.log('update finished');
    //pagination
    let pageres = await s_model.model.$paginate({ limit:10});
    //console.log(pageres);
    //delete them
    let dellist = newrecords.map(x => x.data._id);
    let delresult = await s_model.model.$delete(dellist);
    curcount = (await s_model.model.$count({ filter: { _status: 1 } })).data.count;
    x.is(curcount, oldcount);
    console.log('10 records have been deleted');
});
开发者ID:goumang2010,项目名称:NetTxtNote,代码行数:49,代码来源:usergroup.ts


示例8: callback

        user.repository.findOne({ username: username }, (err, u) => {

            if (err || !u) {
                return callback('Username not found');
            }

            var newPass = randomstring.generate(8);
            u.password = createHash(newPass);
            u.save();
            var subject = replaceAll(config.forgotTemplate.subject, '{{username}}', u.username);
            var text = replaceAll(config.forgotTemplate.text, '{{username}}', u.username);
            var html = replaceAll(config.forgotTemplate.html, '{{username}}', u.username);
            subject = replaceAll(subject, '{{password}}', newPass);
            text = replaceAll(text, '{{password}}', newPass);
            html = replaceAll(html, '{{password}}', newPass);

            mailerAPI.sendMail({
                from: config.forgotTemplate.sender, // sender address
                to: u.username, // list of receivers
                subject: subject, // Subject line
                text: text, // plaintext body
                html: html // html body
            }, (err, info) => {
                    if (err) {
                        logger.error("Error sending new password email", err);
                    }
                    callback('Email sent!');
                });


        });
开发者ID:portalTS,项目名称:portalTS,代码行数:31,代码来源:users.ts


示例9: createUser

	public static async createUser(ctx: Context, userObj: UserDocument, confirmUserEmail: boolean): Promise<UserDocument> {

		let user = new state.models.User(assign(userObj, {
			created_at: new Date(),
			roles: ['member'],
			_plan: config.vpdb.quota.defaultPlan,
		}));

		if (confirmUserEmail) {
			user.email_status = {
				code: 'pending_registration',
				token: randomString.generate(16),
				expires_at: new Date(new Date().getTime() + 86400000), // 1d valid
				value: userObj.email,
			};
		} else {
			user.email_status = { code: 'confirmed' };
			user.is_active = true;
			user.validated_emails = [userObj.email];
		}
		await user.validate();

		const count = await state.models.User.countDocuments({}).exec();

		user.roles = count ? ['member'] : ['root'];
		user = await user.save();

		await acl.addUserRoles(user.id, user.roles);

		logger.info(ctx.state, '[UserUtil.createUser] %s <%s> successfully created with ID "%s" and plan "%s".', count ? 'User' : 'Root user', user.email, user.id, user._plan);
		return user;
	}
开发者ID:freezy,项目名称:node-vpdb,代码行数:32,代码来源:user.util.ts


示例10: it

 it('should reject how much owed text with more than max allowed characters', () => {
   const text = randomstring.generate({
     length: ValidationConstraints.FREE_TEXT_MAX_LENGTH + 1,
     charset: 'alphabetic'
   })
   const errors = validator.validateSync(new HowMuchOwed(300, text))
   expect(errors.length).to.equal(1)
   expectValidationError(errors, ValidationErrors.TEXT_TOO_LONG)
 })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:9,代码来源:howMuchOwed.ts



注:本文中的randomstring.generate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript ratelimiter.get函数代码示例发布时间:2022-05-25
下一篇:
TypeScript random-js.engines类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap