本文整理汇总了TypeScript中validator.check函数的典型用法代码示例。如果您正苦于以下问题:TypeScript check函数的具体用法?TypeScript check怎么用?TypeScript check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: function
exports.calculatePrice = function(req: express.Request, res: express.Response) {
var check = require('validator').check; // Validation
var pages = req.query.pages,
destination = req.query.destination,
preferredCurrency = req.query.preferred_currency;
if (["AUD", "EUR", "GBP", "USD"].indexOf(preferredCurrency) < 0) {
res.send(502, {'error': "Your preferred currency is not supported"});
return;
}
// Check the input
check(pages).notNull().isInt();
check(destination).notNull();
check(preferredCurrency).notNull().len(1,6);
var mailClient = new MailClient();
mailClient.calculatePrice(pages, destination, function (error : Error, digest?: CalculatePriceDigest) {
if (error) {
res.send(502, {'error': error.message});
} else {
var finalPrice : number = (digest.priceInEur + 0.20 + BraintreeClient.guessTransactionCost(digest.priceInEur + 0.20)) * 1.27;
var finalPriceShorted : string = finalPrice.toFixed(2);
CurrencyConverter.convert(CurrencyConverter.convertStringToCurrencyType("EUR"), CurrencyConverter.convertStringToCurrencyType(preferredCurrency), finalPrice, function (result: number) {
var preferredPriceShorted : string = result.toFixed(2);
res.send({'preferredCurrency': preferredCurrency, 'priceInEur': finalPriceShorted, 'priceInPreferredCurrency': preferredPriceShorted, 'printingCity': digest.city, 'printingCountry': digest.country, 'courier': digest.courier});
});
}
});
};
开发者ID:arein,项目名称:Mils-Server,代码行数:31,代码来源:letter.ts
示例2: validate
public static validate(req: express.Request) {
var check = require('validator').check,
sanitize = require('validator').sanitize;
check(req.body.pdf).notNull();
check(req.body.recipientName).notNull();
check(req.body.recipientAddress1).notNull();
check(req.body.recipientCity).notNull();
check(req.body.recipientPostalCode).notNull();
var iso = req.body.recipientCountryIso;
var name = req.body.recipientName;
var company = req.body.recipientCompany;
var address1 = req.body.recipientAddress1;
var address2 = req.body.recipientAddress2;
var city = req.body.recipientCity;
var state = req.body.recipientState;
var zip = req.body.recipientPostalCode;
if (name.length > 50) throw new Error("The FaxRecipient Name may not be longer than 50 characters");
if (company != null && typeof company !== 'undefined' && company.length > 50) throw new Error("The FaxRecipient Company may not be longer than 50 characters");
if (address1.length > 50) throw new Error("The FaxRecipient Address Line 1 may not be longer than 50 characters");
if (address2 != null && typeof address2 !== 'undefined' && address2.length > 50) throw new Error("The FaxRecipient Address Line 2 may not be longer than 50 characters");
if (city.length > 50) throw new Error("The FaxRecipient City may not be longer than 50 characters");
if (state != null && typeof state !== 'undefined' && state.length > 50) throw new Error("The FaxRecipient State may not be longer than 50 characters");
if (zip.length > 50) throw new Error("The FaxRecipient Zip may not be longer than 50 characters");
// Sanitize
req.body.recipientName = sanitize(req.body.recipientName).trim();
req.body.recipientName = sanitize(req.body.recipientName).escape();
req.body.recipientName = req.body.recipientName.replace("'", '').replace('"', '');
req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : sanitize(req.body.recipientCompany).trim();
req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : sanitize(req.body.recipientCompany).escape();
req.body.recipientCompany = (typeof req.body.recipientCompany === 'undefined' || req.body.recipientCompany == null) ? undefined : req.body.recipientCompany.replace("'", '').replace('"', '');
req.body.recipientAddress1 = sanitize(req.body.recipientAddress1).trim();
req.body.recipientAddress1 = sanitize(req.body.recipientAddress1).escape();
req.body.recipientAddress1 = req.body.recipientAddress1.replace("'", '').replace('"', '');
req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : sanitize(req.body.recipientAddress2).trim();
req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : sanitize(req.body.recipientAddress2).escape();
req.body.recipientAddress2 = (typeof req.body.recipientAddress2 === 'undefined' || req.body.recipientAddress2 == null) ? undefined : req.body.recipientAddress2.replace("'", '').replace('"', '');
req.body.recipientPostalCode = sanitize(req.body.recipientPostalCode).trim();
req.body.recipientPostalCode = sanitize(req.body.recipientPostalCode).escape();
req.body.recipientPostalCode = req.body.recipientPostalCode.replace("'", '').replace('"', '');
req.body.recipientCity = sanitize(req.body.recipientCity).trim();
req.body.recipientCity = sanitize(req.body.recipientCity).escape();
req.body.recipientCity = req.body.recipientCity.replace("'", '').replace('"', '');
req.body.recipientState = (typeof req.body.recipientState === 'undefined' || req.body.recipientState == null) ? undefined : req.body.recipientState;
req.body.recipientCountryIso = (typeof req.body.recipientCountryIso === 'undefined') ? undefined : sanitize(req.body.recipientCountryIso).escape();
}
开发者ID:arein,项目名称:Mils-Server,代码行数:55,代码来源:UploadValidator.ts
示例3: validate
public static validate(req: express.Request) {
var check = require('validator').check,
sanitize = require('validator').sanitize;
check(req.params.id).notNull();
if (req.params.id.length !== 24) throw new Error("The ID Provided is not Correct");
check(req.body).notNull();
check(req.body.emailAddress).notNull().isEmail();
check(req.body.address).notNull();
check(req.body.creditCard).notNull();
check(req.body.creditCard.number).notNull();
req.body.creditCard.type = undefined; // we do not need this input
check(req.body.creditCard.cvv).notNull();
check(req.body.creditCard.date).notNull();
check(req.body.address.name).notNull();
check(req.body.address.line1).notNull();
check(req.body.address.postalCode).notNull();
check(req.body.address.city).notNull();
check(req.body.address.country).notNull();
}
开发者ID:arein,项目名称:Mils-Server,代码行数:20,代码来源:PurchaseValidator.ts
注:本文中的validator.check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论