MCPcopy
hub / github.com/socketio/socket.io / requireMs

Function requireMs

packages/socket.io/client-dist/socket.io.js:2357–2514  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2355 var ms;
2356 var hasRequiredMs;
2357 function requireMs() {
2358 if (hasRequiredMs) return ms;
2359 hasRequiredMs = 1;
2360 var s = 1000;
2361 var m = s * 60;
2362 var h = m * 60;
2363 var d = h * 24;
2364 var w = d * 7;
2365 var y = d * 365.25;
2366
2367 /**
2368 * Parse or format the given `val`.
2369 *
2370 * Options:
2371 *
2372 * - `long` verbose formatting [false]
2373 *
2374 * @param {String|Number} val
2375 * @param {Object} [options]
2376 * @throws {Error} throw an error if val is not a non-empty string or a number
2377 * @return {String|Number}
2378 * @api public
2379 */
2380
2381 ms = function ms(val, options) {
2382 options = options || {};
2383 var type = _typeof(val);
2384 if (type === 'string' && val.length > 0) {
2385 return parse(val);
2386 } else if (type === 'number' && isFinite(val)) {
2387 return options["long"] ? fmtLong(val) : fmtShort(val);
2388 }
2389 throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
2390 };
2391
2392 /**
2393 * Parse the given `str` and return milliseconds.
2394 *
2395 * @param {String} str
2396 * @return {Number}
2397 * @api private
2398 */
2399
2400 function parse(str) {
2401 str = String(str);
2402 if (str.length > 100) {
2403 return;
2404 }
2405 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(str);
2406 if (!match) {
2407 return;
2408 }
2409 var n = parseFloat(match[1]);
2410 var type = (match[2] || 'ms').toLowerCase();
2411 switch (type) {
2412 case 'years':
2413 case 'year':
2414 case 'yrs':

Callers 1

setupFunction · 0.85

Calls 4

_typeofFunction · 0.85
fmtLongFunction · 0.85
fmtShortFunction · 0.85
parseFunction · 0.70

Tested by

no test coverage detected