MCPcopy Index your code
hub / github.com/PrairieLearn/PrairieLearn / parse

Function parse

public/javascripts/socket.io.js:921–970  ·  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

919 */
920
921 function parse(str) {
922 str = String(str)
923 if (str.length > 10000) {
924 return
925 }
926 var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
927 if (!match) {
928 return
929 }
930 var n = parseFloat(match[1])
931 var type = (match[2] || 'ms').toLowerCase()
932 switch (type) {
933 case 'years':
934 case 'year':
935 case 'yrs':
936 case 'yr':
937 case 'y':
938 return n * y
939 case 'days':
940 case 'day':
941 case 'd':
942 return n * d
943 case 'hours':
944 case 'hour':
945 case 'hrs':
946 case 'hr':
947 case 'h':
948 return n * h
949 case 'minutes':
950 case 'minute':
951 case 'mins':
952 case 'min':
953 case 'm':
954 return n * m
955 case 'seconds':
956 case 'second':
957 case 'secs':
958 case 'sec':
959 case 's':
960 return n * s
961 case 'milliseconds':
962 case 'millisecond':
963 case 'msecs':
964 case 'msec':
965 case 'ms':
966 return n
967 default:
968 return undefined
969 }
970 }
971
972 /**
973 * Short format for `ms`.

Callers 3

socket.io.jsFile · 0.70
hasFunction · 0.70
rivets.jsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected