MCPcopy
hub / github.com/vercel/ms / parse

Function parse

index.js:48–103  ·  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

46 */
47
48function parse(str) {
49 str = String(str);
50 if (str.length > 100) {
51 return;
52 }
53 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(
54 str
55 );
56 if (!match) {
57 return;
58 }
59 var n = parseFloat(match[1]);
60 var type = (match[2] || 'ms').toLowerCase();
61 switch (type) {
62 case 'years':
63 case 'year':
64 case 'yrs':
65 case 'yr':
66 case 'y':
67 return n * y;
68 case 'weeks':
69 case 'week':
70 case 'w':
71 return n * w;
72 case 'days':
73 case 'day':
74 case 'd':
75 return n * d;
76 case 'hours':
77 case 'hour':
78 case 'hrs':
79 case 'hr':
80 case 'h':
81 return n * h;
82 case 'minutes':
83 case 'minute':
84 case 'mins':
85 case 'min':
86 case 'm':
87 return n * m;
88 case 'seconds':
89 case 'second':
90 case 'secs':
91 case 'sec':
92 case 's':
93 return n * s;
94 case 'milliseconds':
95 case 'millisecond':
96 case 'msecs':
97 case 'msec':
98 case 'ms':
99 return n;
100 default:
101 return undefined;
102 }
103}
104
105/**

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…