MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / parse

Function parse

sdk/src/CloudSocketClientLib.js:4052–4097  ·  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

4050 */
4051
4052 function parse(str) {
4053 str = '' + str;
4054 if (str.length > 10000)
4055 return;
4056 var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
4057 if (!match)
4058 return;
4059 var n = parseFloat(match[1]);
4060 var type = (match[2] || 'ms').toLowerCase();
4061 switch (type) {
4062 case 'years':
4063 case 'year':
4064 case 'yrs':
4065 case 'yr':
4066 case 'y':
4067 return n * y;
4068 case 'days':
4069 case 'day':
4070 case 'd':
4071 return n * d;
4072 case 'hours':
4073 case 'hour':
4074 case 'hrs':
4075 case 'hr':
4076 case 'h':
4077 return n * h;
4078 case 'minutes':
4079 case 'minute':
4080 case 'mins':
4081 case 'min':
4082 case 'm':
4083 return n * m;
4084 case 'seconds':
4085 case 'second':
4086 case 'secs':
4087 case 'sec':
4088 case 's':
4089 return n * s;
4090 case 'milliseconds':
4091 case 'millisecond':
4092 case 'msecs':
4093 case 'msec':
4094 case 'ms':
4095 return n;
4096 }
4097 }
4098
4099 /**
4100 * Short format for `ms`.

Callers 2

hasFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected