How to use the toDate function from validator
Find comprehensive JavaScript validator.toDate code examples handpicked from public code repositorys.
GitHub: bevacqua/infer
109 110 111 112 113 114 115 116 117
validator.isDate = function (str) { return !isNaN(Date.parse(str)); }; validator.isAfter = function (str, date) { var comparison = validator.toDate(date || new Date()) , original = validator.toDate(str); return !!(original && comparison && original > comparison); };
2
3
4
+ 15 other calls in file
37 38 39 40 41 42 43 44 45 46
} if (sanitization.toFloat) { sanitizefield = Validator.toFloat(sanitizefield); } if (sanitization.toDate) { sanitizefield = Validator.toDate(sanitizefield); } if (sanitization.toProperPrice) { sanitizefield = parseFloat(sanitizefield.replace(',', '')); }
0
3
0
GitHub: rrrbbbsss/Little-Feeder
6 7 8 9 10 11 12 13 14 15
const { entries } = articles; const formatedArticles = entries.map(({ title, link, published }) => ({ feed_id: feed.id, title, url: link, published: validator.toDate(published), })); return formatedArticles; } catch (err) { console.log("\n-----\n", "worker error: ", err, "\n-----\n");
2
0
0
18 19 20 21 22 23 24 25 26 27
*/ creatOrder: async (req, res) => { try { if (validator.equals(typeof req.body.infoOrder.name, 'string') && validator.matches(req.body.infoOrder.phone, /^(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/) && validator.toDate(req.body.infoOrder.orderDate) && validator.equals(typeof req.body.infoOrder.totalPrice, 'number') && validator.equals(typeof req.body.userInfo, 'number')) { const newOrder = new OrderModel({ number_order: escape(req.body.infoOrder.orderDate + new Date().valueOf()),
0
0
1
218 219 220 221 222 223 224 225 226 227
} if (sanitization.toBoolean) { req.body[field] = Validator.toBoolean(req.body[field]); } if (sanitization.toDate) { req.body[field] = Validator.toDate(req.body[field]); } if (sanitization.toFloat) { req.body[field] = Validator.toFloat(req.body[field]); }
0
0
0
+ 11 other calls in file
303 304 305 306 307 308 309 310 311 312 313 314
console.log(input + " is a boolean: " + (typeof input === 'boolean')) return typeof input === 'boolean'; } function validateDate(input) { console.log(input + " is a date: " + (typeof input === 'string' && validator.toDate(input) !== null)) return typeof input === 'string' && validator.toDate(input) !== null; }
0
0
0
104 105 106 107 108 109 110 111 112 113
/** * 字符串转Date * @param input 输入字符串 */ toDate(input) { return validator1.toDate(input); } /** * 检查字符串是否为float
0
0
0
360 361 362 363 364 365 366 367 368 369
converters: { 'boolean': { converter: (val) => V.toBoolean('' + val) }, 'date': { converter: V.toDate }, // replace <, >, &, ', " and / with HTML entities. 'escape': { converter: V.escape
0
0
0
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
}); app.post('/date', (req, res) => { const response = { sanitizedDate: validator.toDate(req.body.dateForm);// Sanitize date here }; res.json({message: response}) });
0
0
1
validator.escape is the most popular function in validator (548 examples)