MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / parse

Function parse

lib/models/dav.js:975–1030  ·  view source on GitHub ↗

* Parse the given `str` and return milliseconds. * * @param {String} str * @return {Number} * @api private

(str)

Source from the content-addressed store, hash-verified

973 */
974
975 function parse(str) {
976 str = String(str);
977 if (str.length > 100) {
978 return;
979 }
980 var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
981 str
982 );
983 if (!match) {
984 return;
985 }
986 var n = parseFloat(match[1]);
987 var type = (match[2] || 'ms').toLowerCase();
988 switch (type) {
989 case 'years':
990 case 'year':
991 case 'yrs':
992 case 'yr':
993 case 'y':
994 return n * y;
995 case 'weeks':
996 case 'week':
997 case 'w':
998 return n * w;
999 case 'days':
1000 case 'day':
1001 case 'd':
1002 return n * d;
1003 case 'hours':
1004 case 'hour':
1005 case 'hrs':
1006 case 'hr':
1007 case 'h':
1008 return n * h;
1009 case 'minutes':
1010 case 'minute':
1011 case 'mins':
1012 case 'min':
1013 case 'm':
1014 return n * m;
1015 case 'seconds':
1016 case 'second':
1017 case 'secs':
1018 case 'sec':
1019 case 's':
1020 return n * s;
1021 case 'milliseconds':
1022 case 'millisecond':
1023 case 'msecs':
1024 case 'msec':
1025 case 'ms':
1026 return n;
1027 default:
1028 return undefined;
1029 }
1030 }
1031
1032 /**

Callers 3

handlerFunction · 0.85
webdav_test.tsFile · 0.85
requireMsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected