How to use the toDate function from validator

Find comprehensive JavaScript validator.toDate code examples handpicked from public code repositorys.

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);
};
fork icon2
star icon3
watch icon4

+ 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(',', ''));
}
fork icon0
star icon3
watch icon0

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");
fork icon2
star icon0
watch icon0

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()),
fork icon0
star icon0
watch icon1

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]);
}
fork icon0
star icon0
watch icon0

+ 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;
}



fork icon0
star icon0
watch icon0

104
105
106
107
108
109
110
111
112
113
/**
 * 字符串转Date
 * @param input 输入字符串
 */
toDate(input) {
  return validator1.toDate(input);
}

/**
 * 检查字符串是否为float
fork icon0
star icon0
watch icon0

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
fork icon0
star icon0
watch icon0

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})
});
fork icon0
star icon0
watch icon1