How to use timerInstance method in stryker-parent

Best JavaScript code snippet using stryker-parent

timer.jquery.js

Source:timer.jquery.js Github

copy

Full Screen

1/******/ (function(modules) { // webpackBootstrap2/******/ // The module cache3/******/ var installedModules = {};4/******/ // The require function5/******/ function __webpack_require__(moduleId) {6/******/ // Check if module is in cache7/******/ if(installedModules[moduleId])8/******/ return installedModules[moduleId].exports;9/******/ // Create a new module (and put it into the cache)10/******/ var module = installedModules[moduleId] = {11/******/ exports: {},12/******/ id: moduleId,13/******/ loaded: false14/******/ };15/******/ // Execute the module function16/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);17/******/ // Flag the module as loaded18/******/ module.loaded = true;19/******/ // Return the exports of the module20/******/ return module.exports;21/******/ }22/******/ // expose the modules object (__webpack_modules__)23/******/ __webpack_require__.m = modules;24/******/ // expose the module cache25/******/ __webpack_require__.c = installedModules;26/******/ // __webpack_public_path__27/******/ __webpack_require__.p = "";28/******/ // Load entry module and return exports29/******/ return __webpack_require__(0);30/******/ })31/************************************************************************/32/******/ ([33/* 0 */34/***/ function(module, exports, __webpack_require__) {35 'use strict';36 var _Timer = __webpack_require__(1);37 var _Timer2 = _interopRequireDefault(_Timer);38 var _constants = __webpack_require__(2);39 var _constants2 = _interopRequireDefault(_constants);40 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }41 /* global $:true */42 (function () {43 $.fn.timer = function (options) {44 options = options || 'start';45 return this.each(function () {46 if (!($.data(this, _constants2.default.PLUGIN_NAME) instanceof _Timer2.default)) {47 /**48 * Create a new data attribute on the element to hold the plugin name49 * This way we can know which plugin(s) is/are initialized on the element later50 */51 $.data(this, _constants2.default.PLUGIN_NAME, new _Timer2.default(this, options));52 }53 /**54 * Use the instance of this plugin derived from the data attribute for this element55 * to conduct whatever action requested as a string parameter.56 */57 var instance = $.data(this, _constants2.default.PLUGIN_NAME);58 /**59 * Provision for calling a function from this plugin60 * without initializing it all over again61 */62 if (typeof options === 'string') {63 if (typeof instance[options] === 'function') {64 /*65 Pass in 'instance' to provide for the value of 'this' in the called function66 */67 instance[options]();68 }69 } else {70 instance.start();71 }72 });73 };74 })();75/***/ },76/* 1 */77/***/ function(module, exports, __webpack_require__) {78 'use strict';79 Object.defineProperty(exports, "__esModule", {80 value: true81 });82 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global $:true */83 var _constants = __webpack_require__(2);84 var _constants2 = _interopRequireDefault(_constants);85 var _utils = __webpack_require__(3);86 var _utils2 = _interopRequireDefault(_utils);87 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }88 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }89 /**90 * Timer class to be instantiated on every element.91 * All relative values will be stored at instance level.92 */93 var Timer = function () {94 /**95 * Construct a Timer instance on the provided element with the given config.96 * @param {Object} element HTML node as passed by jQuery97 * @param {Object|String} config User extended options or a string (start, pause, resume etc)98 */99 function Timer(element, config) {100 _classCallCheck(this, Timer);101 this.element = element;102 this.originalConfig = $.extend({}, config);103 this.totalSeconds = 0;104 this.intervalId = null;105 // A HTML element will have the html() method in jQuery to inject content,106 this.html = 'html';107 if (element.tagName === 'INPUT' || element.tagName === 'TEXTAREA') {108 // In case of input element or a textarea, jQuery provides the val() method to inject content109 this.html = 'val';110 }111 this.config = _utils2.default.getDefaultConfig();112 if (config.duration) {113 config.duration = _utils2.default.durationTimeToSeconds(config.duration);114 }115 if (typeof config !== 'string') {116 this.config = $.extend(this.config, config);117 }118 if (this.config.seconds) {119 this.totalSeconds = this.config.seconds;120 }121 if (this.config.editable) {122 _utils2.default.makeEditable(this);123 }124 this.startTime = _utils2.default.unixSeconds() - this.totalSeconds;125 // In case duration is set along with a callback as well as repeat,126 // then the update frequency needs to be at least 1000ms to prevent callback from being fired more than once127 if (this.config.duration && this.config.repeat && this.config.updateFrequency < 1000) {128 this.config.updateFrequency = 1000;129 }130 // If countdown is set, ensure duration is set as well131 // Also set the total seconds to the duration so that the first render gets the correct value132 if (this.config.countdown) {133 if (!this.config.duration) {134 throw new Error('Countdown option set without duration!');135 }136 if (this.config.editable) {137 throw new Error('Cannot set editable on a countdown timer!');138 }139 this.config.startTime = _utils2.default.unixSeconds() - this.config.duration;140 this.totalSeconds = this.config.duration;141 }142 }143 _createClass(Timer, [{144 key: 'start',145 value: function start() {146 if (this.state !== _constants2.default.TIMER_RUNNING) {147 _utils2.default.setState(this, _constants2.default.TIMER_RUNNING);148 this.render();149 this.intervalId = setInterval(_utils2.default.intervalHandler.bind(null, this), this.config.updateFrequency);150 }151 }152 }, {153 key: 'pause',154 value: function pause() {155 if (this.state === _constants2.default.TIMER_RUNNING) {156 _utils2.default.setState(this, _constants2.default.TIMER_PAUSED);157 clearInterval(this.intervalId);158 }159 }160 }, {161 key: 'resume',162 value: function resume() {163 if (this.state === _constants2.default.TIMER_PAUSED) {164 _utils2.default.setState(this, _constants2.default.TIMER_RUNNING);165 if (this.config.countdown) {166 this.startTime = _utils2.default.unixSeconds() - this.config.duration + this.totalSeconds;167 } else {168 this.startTime = _utils2.default.unixSeconds() - this.totalSeconds;169 }170 this.intervalId = setInterval(_utils2.default.intervalHandler.bind(null, this), this.config.updateFrequency);171 }172 }173 }, {174 key: 'remove',175 value: function remove() {176 clearInterval(this.intervalId);177 $(this.element).data(_constants2.default.PLUGIN_NAME, null);178 }179 }, {180 key: 'reset',181 value: function reset() {182 var element = this.element;183 var originalConfig = this.originalConfig;184 this.remove();185 $(element).timer(originalConfig);186 }187 }, {188 key: 'render',189 value: function render() {190 if (this.config.format) {191 $(this.element)[this.html](_utils2.default.secondsToFormattedTime(this.totalSeconds, this.config.format));192 } else {193 $(this.element)[this.html](_utils2.default.secondsToPrettyTime(this.totalSeconds));194 }195 // Make total seconds available via timer element's data attribute196 $(this.element).data('seconds', this.totalSeconds);197 }198 }]);199 return Timer;200 }();201 exports.default = Timer;202/***/ },203/* 2 */204/***/ function(module, exports) {205 'use strict';206 Object.defineProperty(exports, "__esModule", {207 value: true208 });209 var Constants = {210 PLUGIN_NAME: 'timer',211 TIMER_RUNNING: 'running',212 TIMER_PAUSED: 'paused',213 DAYINSECONDS: 86400,214 THIRTYSIXHUNDRED: 3600,215 SIXTY: 60,216 TEN: 10217 };218 exports.default = Constants;219/***/ },220/* 3 */221/***/ function(module, exports, __webpack_require__) {222 'use strict';223 Object.defineProperty(exports, "__esModule", {224 value: true225 });226 var _constants = __webpack_require__(2);227 var _constants2 = _interopRequireDefault(_constants);228 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }229 /**230 * Private231 * Convert (a number) seconds to a Object with days, hours, minutes etc as properties232 * Used by secondsToPrettyTime for to format the time display233 * @param {Number} totalSeconds The total seconds that needs to be distributed into an Object234 * @return {Object} Object with days, hours, minutes, totalMinutes, seconds and totalSeconds235 */236 var _secondsToTimeObj = function _secondsToTimeObj() {237 var totalSeconds = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];238 var days = 0;239 var hours = 0;240 var totalMinutes = Math.floor(totalSeconds / _constants2.default.SIXTY);241 var minutes = totalMinutes;242 var seconds = void 0;243 if (totalSeconds >= _constants2.default.DAYINSECONDS) {244 days = Math.floor(totalSeconds / _constants2.default.DAYINSECONDS);245 }246 if (totalSeconds >= _constants2.default.THIRTYSIXHUNDRED) {247 hours = Math.floor(totalSeconds % _constants2.default.DAYINSECONDS / _constants2.default.THIRTYSIXHUNDRED);248 }249 if (totalSeconds >= _constants2.default.SIXTY) {250 minutes = Math.floor(totalSeconds % _constants2.default.THIRTYSIXHUNDRED / _constants2.default.SIXTY);251 }252 seconds = totalSeconds % _constants2.default.SIXTY;253 return { days: days, hours: hours, minutes: minutes, totalMinutes: totalMinutes, seconds: seconds, totalSeconds: totalSeconds };254 };255 /**256 * Private257 * Method to pad a given number with a 0 in case it's less than 10258 * @param {Number} num The number to be padded259 * @return {String|Number} Padded (if less than 10) number260 */261 /* global $:true */262 var _paddedValue = function _paddedValue(num) {263 num = parseInt(num, 10);264 if (num < 10) {265 return '0' + num;266 }267 return num;268 };269 var getDefaultConfig = function getDefaultConfig() {270 return {271 seconds: 0, // Default seconds value to start timer from272 editable: false, // Allow making changes to the time by clicking on it273 duration: null, // Duration to run callback after274 callback: function callback() {275 // Default callback to run after elapsed duration276 console.log('Time up!');277 },278 repeat: false, // this will repeat callback every n times duration is elapsed279 countdown: false, // if true, this will render the timer as a countdown (must have duration)280 format: null, // this sets the format in which the time will be printed281 updateFrequency: 500 // How often should timer display update282 };283 };284 /**285 * @return {Number} Return seconds passed since Jan 1, 1970286 */287 var unixSeconds = function unixSeconds() {288 return Math.round(Date.now() / 1000);289 };290 /**291 * Convert seconds to pretty time.292 * For example 100 becomes 1:40 min, 34 becomes 34 sec and 10000 becomes 2:46:40293 * @param {Number} seconds Seconds to be converted294 * @return {String} Pretty time295 */296 var secondsToPrettyTime = function secondsToPrettyTime(seconds) {297 var timeObj = _secondsToTimeObj(seconds);298 if (timeObj.days) {299 return timeObj.days + ':' + _paddedValue(timeObj.hours) + ':' + _paddedValue(timeObj.minutes) + ':' + _paddedValue(timeObj.seconds);300 }301 if (timeObj.hours) {302 return timeObj.hours + ':' + _paddedValue(timeObj.minutes) + ':' + _paddedValue(timeObj.seconds);303 }304 var prettyTime = '';305 if (timeObj.minutes) {306 prettyTime = timeObj.minutes + ':' + _paddedValue(timeObj.seconds) + ' min';307 } else {308 prettyTime = timeObj.seconds + ' sec';309 }310 return prettyTime;311 };312 /**313 * Convert seconds to user defined format for time314 * @param {Number} seconds Seconds to be converted315 * @param {String} formattedTime User defined format316 * @return {String} Formatted time string317 */318 var secondsToFormattedTime = function secondsToFormattedTime(seconds, formattedTime) {319 var timeObj = _secondsToTimeObj(seconds);320 var formatDef = [{ identifier: '%d', value: timeObj.days }, { identifier: '%h', value: timeObj.hours }, { identifier: '%m', value: timeObj.minutes }, { identifier: '%s', value: timeObj.seconds }, { identifier: '%g', value: timeObj.totalMinutes }, { identifier: '%t', value: timeObj.totalSeconds }, { identifier: '%D', value: _paddedValue(timeObj.days) }, { identifier: '%H', value: _paddedValue(timeObj.hours) }, { identifier: '%M', value: _paddedValue(timeObj.minutes) }, { identifier: '%S', value: _paddedValue(timeObj.seconds) }, { identifier: '%G', value: _paddedValue(timeObj.totalMinutes) }, { identifier: '%T', value: _paddedValue(timeObj.totalSeconds) }];321 formatDef.forEach(function (fmt) {322 formattedTime = formattedTime.replace(fmt.identifier, fmt.value);323 });324 return formattedTime;325 };326 /**327 * Convert duration time format to seconds328 * @param {String} timeFormat e.g. 5m30s329 * @return {Number} Returns 330330 */331 var durationTimeToSeconds = function durationTimeToSeconds(timeFormat) {332 if (!timeFormat) {333 throw new Error('durationTimeToSeconds expects a string argument!');334 }335 // Early return in case a number is passed336 if (!isNaN(Number(timeFormat))) {337 return timeFormat;338 }339 timeFormat = timeFormat.toLowerCase();340 var days = timeFormat.match(/\d{1,2}d/); // Match 10d in 10d5h30m10s341 var hrs = timeFormat.match(/\d{1,2}h/); // Match 5h in 5h30m10s342 var mins = timeFormat.match(/\d{1,2}m/); // Match 30m in 5h30m10s343 var secs = timeFormat.match(/\d{1,2}s/); // Match 10s in 5h30m10s344 if (!days && !hrs && !mins && !secs) {345 throw new Error('Invalid string passed in durationTimeToSeconds!');346 }347 var seconds = 0;348 if (days) {349 seconds += Number(days[0].replace('d', '') * _constants2.default.DAYINSECONDS);350 }351 if (hrs) {352 seconds += Number(hrs[0].replace('h', '') * _constants2.default.THIRTYSIXHUNDRED);353 }354 if (mins) {355 seconds += Number(mins[0].replace('m', '')) * _constants2.default.SIXTY;356 }357 if (secs) {358 seconds += Number(secs[0].replace('s', ''));359 }360 return seconds;361 };362 /**363 * Parse pretty time and return it as seconds364 * Currently only the native pretty time is parseable365 * @param {String} editedTime The time as edited by the user366 * @return {Number} Parsed time367 */368 var prettyTimeToSeconds = function prettyTimeToSeconds(editedTime) {369 var arr = void 0;370 var time = void 0;371 if (editedTime.indexOf('sec') > 0) {372 time = Number(editedTime.replace(/\ssec/g, ''));373 } else if (editedTime.indexOf('min') > 0) {374 editedTime = editedTime.replace(/\smin/g, '');375 arr = editedTime.split(':');376 time = Number(arr[0] * _constants2.default.SIXTY) + Number(arr[1]);377 } else if (editedTime.match(/\d{1,2}:\d{2}:\d{2}:\d{2}/)) {378 arr = editedTime.split(':');379 time = Number(arr[0] * _constants2.default.DAYINSECONDS) + Number(arr[1] * _constants2.default.THIRTYSIXHUNDRED) + Number(arr[2] * _constants2.default.SIXTY) + Number(arr[3]);380 } else if (editedTime.match(/\d{1,2}:\d{2}:\d{2}/)) {381 arr = editedTime.split(':');382 time = Number(arr[0] * _constants2.default.THIRTYSIXHUNDRED) + Number(arr[1] * _constants2.default.SIXTY) + Number(arr[2]);383 }384 return time;385 };386 /**387 * Set the provided state of the timer in the data attr `state` of the timer HTML element388 * @param {Object} timerInstance Instance of the timer object389 * @param {[type]} newState The state to be set on the HTML element390 */391 var setState = function setState(timerInstance, newState) {392 timerInstance.state = newState;393 $(timerInstance.element).data('state', newState);394 };395 /**396 * Convenience method to wire up focus & blur events to pause and resume397 * Makes use of the local `prettyTimeToSeconds` function to convert user edited time to seconds398 * @param {Object} timerInstance Instance of the Timer Class399 */400 var makeEditable = function makeEditable(timerInstance) {401 $(timerInstance.element).on('focus', function () {402 timerInstance.pause();403 });404 $(timerInstance.element).on('blur', function () {405 timerInstance.totalSeconds = prettyTimeToSeconds($(timerInstance.element)[timerInstance.html]());406 timerInstance.resume();407 });408 };409 /**410 * The function that will be called via setInterval based on the timer's update frequency411 * @param {Object} timerInstance Instance of the timer object412 */413 var intervalHandler = function intervalHandler(timerInstance) {414 timerInstance.totalSeconds = unixSeconds() - timerInstance.startTime;415 if (timerInstance.config.countdown) {416 timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds;417 if (timerInstance.totalSeconds === 0) {418 clearInterval(timerInstance.intervalId);419 setState(timerInstance, _constants2.default.TIMER_STOPPED);420 timerInstance.config.callback();421 $(timerInstance.element).data('seconds');422 }423 timerInstance.render();424 return;425 }426 timerInstance.render();427 if (!timerInstance.config.duration) {428 return;429 }430 // If the timer was called with a duration parameter,431 // run the callback if duration is complete432 // and remove the duration if `repeat` is not requested433 if (timerInstance.totalSeconds > 0 && timerInstance.totalSeconds % timerInstance.config.duration === 0) {434 if (timerInstance.config.callback) {435 timerInstance.config.callback();436 }437 if (!timerInstance.config.repeat) {438 clearInterval(timerInstance.intervalId);439 setState(timerInstance, _constants2.default.TIMER_STOPPED);440 timerInstance.config.duration = null;441 }442 }443 };444 exports.default = {445 getDefaultConfig: getDefaultConfig,446 unixSeconds: unixSeconds,447 secondsToPrettyTime: secondsToPrettyTime,448 secondsToFormattedTime: secondsToFormattedTime,449 durationTimeToSeconds: durationTimeToSeconds,450 prettyTimeToSeconds: prettyTimeToSeconds,451 setState: setState,452 makeEditable: makeEditable,453 intervalHandler: intervalHandler454 };455/***/ }...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1/* global $:true */2import Constants from './constants';3/**4 * Private5 * Convert (a number) seconds to a Object with days, hours, minutes etc as properties6 * Used by secondsToPrettyTime for to format the time display7 * @param {Number} totalSeconds The total seconds that needs to be distributed into an Object8 * @return {Object} Object with days, hours, minutes, totalMinutes, seconds and totalSeconds9 */10const _secondsToTimeObj = (totalSeconds = 0) => {11 let days = 0;12 let hours = 0;13 let totalMinutes = Math.floor(totalSeconds / Constants.SIXTY);14 let minutes = totalMinutes;15 let seconds;16 if (totalSeconds >= Constants.DAYINSECONDS) {17 days = Math.floor(totalSeconds / Constants.DAYINSECONDS);18 }19 if (totalSeconds >= Constants.THIRTYSIXHUNDRED) {20 hours = Math.floor(totalSeconds % Constants.DAYINSECONDS / Constants.THIRTYSIXHUNDRED);21 }22 if (totalSeconds >= Constants.SIXTY) {23 minutes = Math.floor(totalSeconds % Constants.THIRTYSIXHUNDRED / Constants.SIXTY);24 }25 seconds = totalSeconds % Constants.SIXTY;26 return {days, hours, minutes, totalMinutes, seconds, totalSeconds};27};28/**29 * Private30 * Method to pad a given number with a 0 in case it's less than 1031 * @param {Number} num The number to be padded32 * @return {String|Number} Padded (if less than 10) number33 */34const _paddedValue = num => {35 num = parseInt(num, 10);36 if (num < 10) {37 return '0' + num;38 }39 return num;40};41const getDefaultConfig = () => ({42 seconds: 0, // Default seconds value to start timer from43 editable: false, // Allow making changes to the time by clicking on it44 duration: null, // Duration to run callback after45 callback: function() { // Default callback to run after elapsed duration46 console.log('Time up!');47 },48 repeat: false, // this will repeat callback every n times duration is elapsed49 countdown: false, // if true, this will render the timer as a countdown (must have duration)50 format: null, // this sets the format in which the time will be printed51 updateFrequency: 500 // How often should timer display update52});53/**54 * @return {Number} Return seconds passed since Jan 1, 197055 */56const unixSeconds = () => (Math.round(Date.now() / 1000));57/**58 * Convert seconds to pretty time.59 * For example 100 becomes 1:40 min, 34 becomes 34 sec and 10000 becomes 2:46:4060 * @param {Number} seconds Seconds to be converted61 * @return {String} Pretty time62 */63const secondsToPrettyTime = seconds => {64 let timeObj = _secondsToTimeObj(seconds);65 if (timeObj.days) {66 return timeObj.days + ':' + _paddedValue(timeObj.hours) + ':' +67 _paddedValue(timeObj.minutes) + ':' + _paddedValue(timeObj.seconds);68 }69 if (timeObj.hours) {70 return timeObj.hours + ':' + _paddedValue(timeObj.minutes) + ':' + _paddedValue(timeObj.seconds);71 }72 let prettyTime = '';73 if (timeObj.minutes) {74 prettyTime = timeObj.minutes + ':' + _paddedValue(timeObj.seconds) + ' min';75 } else {76 prettyTime = timeObj.seconds + ' sec';77 }78 return prettyTime;79};80/**81 * Convert seconds to user defined format for time82 * @param {Number} seconds Seconds to be converted83 * @param {String} formattedTime User defined format84 * @return {String} Formatted time string85 */86const secondsToFormattedTime = (seconds, formattedTime) => {87 let timeObj = _secondsToTimeObj(seconds);88 const formatDef = [89 {identifier: '%d', value: timeObj.days},90 {identifier: '%h', value: timeObj.hours},91 {identifier: '%m', value: timeObj.minutes},92 {identifier: '%s', value: timeObj.seconds},93 {identifier: '%g', value: timeObj.totalMinutes},94 {identifier: '%t', value: timeObj.totalSeconds},95 {identifier: '%D', value: _paddedValue(timeObj.days)},96 {identifier: '%H', value: _paddedValue(timeObj.hours)},97 {identifier: '%M', value: _paddedValue(timeObj.minutes)},98 {identifier: '%S', value: _paddedValue(timeObj.seconds)},99 {identifier: '%G', value: _paddedValue(timeObj.totalMinutes)},100 {identifier: '%T', value: _paddedValue(timeObj.totalSeconds)}101 ];102 formatDef.forEach(function(fmt) {103 formattedTime = formattedTime.replace(fmt.identifier, fmt.value);104 });105 return formattedTime;106};107/**108 * Convert duration time format to seconds109 * @param {String} timeFormat e.g. 5m30s110 * @return {Number} Returns 330111 */112const durationTimeToSeconds = timeFormat => {113 if (!timeFormat) {114 throw new Error('durationTimeToSeconds expects a string argument!');115 }116 // Early return in case a number is passed117 if (!isNaN(Number(timeFormat))) {118 return timeFormat;119 }120 timeFormat = timeFormat.toLowerCase();121 let days = timeFormat.match(/\d{1,2}d/); // Match 10d in 10d5h30m10s122 let hrs = timeFormat.match(/\d{1,2}h/); // Match 5h in 5h30m10s123 let mins = timeFormat.match(/\d{1,2}m/); // Match 30m in 5h30m10s124 let secs = timeFormat.match(/\d{1,2}s/); // Match 10s in 5h30m10s125 if (!days && !hrs && !mins && !secs) {126 throw new Error('Invalid string passed in durationTimeToSeconds!');127 }128 let seconds = 0;129 if (days) {130 seconds += Number(days[0].replace('d', '') * Constants.DAYINSECONDS);131 }132 if (hrs) {133 seconds += Number(hrs[0].replace('h', '') * Constants.THIRTYSIXHUNDRED);134 }135 if (mins) {136 seconds += Number(mins[0].replace('m', '')) * Constants.SIXTY;137 }138 if (secs) {139 seconds += Number(secs[0].replace('s', ''));140 }141 return seconds;142};143/**144 * Parse pretty time and return it as seconds145 * Currently only the native pretty time is parseable146 * @param {String} editedTime The time as edited by the user147 * @return {Number} Parsed time148 */149const prettyTimeToSeconds = editedTime => {150 let arr;151 let time;152 if (editedTime.indexOf('sec') > 0) {153 time = Number(editedTime.replace(/\ssec/g, ''));154 } else if (editedTime.indexOf('min') > 0) {155 editedTime = editedTime.replace(/\smin/g, '');156 arr = editedTime.split(':');157 time = Number(arr[0] * Constants.SIXTY) + Number(arr[1]);158 } else if (editedTime.match(/\d{1,2}:\d{2}:\d{2}:\d{2}/)) {159 arr = editedTime.split(':');160 time = Number(arr[0] * Constants.DAYINSECONDS) + Number(arr[1] * Constants.THIRTYSIXHUNDRED) +161 Number(arr[2] * Constants.SIXTY) + Number(arr[3]);162 } else if (editedTime.match(/\d{1,2}:\d{2}:\d{2}/)) {163 arr = editedTime.split(':');164 time = Number(arr[0] * Constants.THIRTYSIXHUNDRED) + Number(arr[1] * Constants.SIXTY) + Number(arr[2]);165 }166 return time;167};168/**169 * Set the provided state of the timer in the data attr `state` of the timer HTML element170 * @param {Object} timerInstance Instance of the timer object171 * @param {[type]} newState The state to be set on the HTML element172 */173const setState = (timerInstance, newState) => {174 timerInstance.state = newState;175 $(timerInstance.element).data('state', newState);176};177/**178 * Convenience method to wire up focus & blur events to pause and resume179 * Makes use of the local `prettyTimeToSeconds` function to convert user edited time to seconds180 * @param {Object} timerInstance Instance of the Timer Class181 */182const makeEditable = timerInstance => {183 $(timerInstance.element).on('focus', () => {184 timerInstance.pause();185 });186 $(timerInstance.element).on('blur', () => {187 timerInstance.totalSeconds = prettyTimeToSeconds($(timerInstance.element)[timerInstance.html]());188 timerInstance.resume();189 });190};191/**192 * The function that will be called via setInterval based on the timer's update frequency193 * @param {Object} timerInstance Instance of the timer object194 */195const intervalHandler = timerInstance => {196 timerInstance.totalSeconds = unixSeconds() - timerInstance.startTime;197 if (timerInstance.config.countdown) {198 timerInstance.totalSeconds = timerInstance.config.duration - timerInstance.totalSeconds;199 if (timerInstance.totalSeconds === 0) {200 clearInterval(timerInstance.intervalId);201 setState(timerInstance, Constants.TIMER_STOPPED);202 timerInstance.config.callback();203 $(timerInstance.element).data('seconds');204 }205 timerInstance.render();206 return;207 }208 timerInstance.render();209 if (!timerInstance.config.duration) {210 return;211 }212 // If the timer was called with a duration parameter,213 // run the callback if duration is complete214 // and remove the duration if `repeat` is not requested215 if (timerInstance.totalSeconds > 0 && timerInstance.totalSeconds % timerInstance.config.duration === 0) {216 if (timerInstance.config.callback) {217 timerInstance.config.callback();218 }219 if (!timerInstance.config.repeat) {220 clearInterval(timerInstance.intervalId);221 setState(timerInstance, Constants.TIMER_STOPPED);222 timerInstance.config.duration = null;223 }224 }225};226export default {227 getDefaultConfig: getDefaultConfig,228 unixSeconds: unixSeconds,229 secondsToPrettyTime: secondsToPrettyTime,230 secondsToFormattedTime: secondsToFormattedTime,231 durationTimeToSeconds: durationTimeToSeconds,232 prettyTimeToSeconds: prettyTimeToSeconds,233 setState: setState,234 makeEditable: makeEditable,235 intervalHandler: intervalHandler...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1timerInstance.log("Hello");2timerInstance.log("Hello");3timerInstance.log("Hello");4timerInstance.log("Hello");5timerInstance.log("Hello");6timerInstance.log("Hello");7timerInstance.log("Hello");8timerInstance.log("Hello");9timerInstance.log("Hello");10timerInstance.log("Hello");11timerInstance.log("Hello");12timerInstance.log("Hello");13timerInstance.log("Hello");14timerInstance.log("Hello");15timerInstance.log("Hello");16timerInstance.log("Hello");17timerInstance.log("Hello");18timerInstance.log("Hello");19timerInstance.log("Hello");20timerInstance.log("Hello");21timerInstance.log("Hello");22timerInstance.log("Hello");23timerInstance.log("Hello");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { timerInstance } = require('stryker-parent');2timerInstance.start('myTimer');3timerInstance.stop('myTimer');4const { timerInstance } = require('stryker-parent');5timerInstance.start('myTimer');6timerInstance.stop('myTimer');7module.exports = function (config) {8 config.set({9 timer: {10 },11 });12};13module.exports = function (config) {14 config.set({15 timer: {16 },17 });18};19module.exports = function (config) {20 config.set({21 timer: {22 },23 });24};25module.exports = function (config) {26 config.set({27 timer: {28 },29 });30};31module.exports = function (config) {32 config.set({33 timer: {34 },35 });36};37module.exports = function (config) {38 config.set({39 timer: {40 },41 });42};43module.exports = function (config) {44 config.set({45 timer: {46 },47 });48};49module.exports = function (config) {50 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1var timerInstance = require('stryker-parent').timerInstance;2var timer = timerInstance.getInstance();3timer.startTimer("test");4setTimeout(function() {5timer.stopTimer("test");6}, 1000);7var timerInstance = require('stryker-parent').timerInstance;8var timer = timerInstance.getInstance();9timer.startTimer("test2");10setTimeout(function() {11timer.stopTimer("test2");12}, 1000);13var timerInstance = require('stryker-parent').timerInstance;14var timer = timerInstance.getInstance();15timer.startTimer("test3");16setTimeout(function() {17timer.stopTimer("test3");18}, 1000);19var timerInstance = require('stryker-parent').timerInstance;20var timer = timerInstance.getInstance();21timer.startTimer("test4");22setTimeout(function() {23timer.stopTimer("test4");24}, 1000);25var timerInstance = require('stryker-parent').timerInstance;26var timer = timerInstance.getInstance();27timer.startTimer("test5");28setTimeout(function() {29timer.stopTimer("test5");30}, 1000);31var timerInstance = require('stryker-parent').timerInstance;32var timer = timerInstance.getInstance();33timer.startTimer("test6");34setTimeout(function() {35timer.stopTimer("test6");36}, 1000);37var timerInstance = require('stryker-parent').timerInstance;38var timer = timerInstance.getInstance();39timer.startTimer("test7");40setTimeout(function() {41timer.stopTimer("test7");42}, 1000);43var timerInstance = require('stryker-parent').timerInstance;44var timer = timerInstance.getInstance();45timer.startTimer("test8");46setTimeout(function() {47timer.stopTimer("test8");48}, 1000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var timer = stryker.Timer.instance();3timer.on('start', function () {4});5timer.on('stop', function () {6});7timer.start();8timer.stop();9var stryker = require('stryker-parent');10var timer = stryker.Timer.instance();11timer.on('start', function () {12});13timer.on('stop', function () {14});15timer.start();16timer.stop();

Full Screen

Using AI Code Generation

copy

Full Screen

1var timerInstance = require('stryker-parent').timerInstance;2var timer = timerInstance();3timer.start();4timer.stop();5console.log(timer.result());6var timerInstance = require('stryker-parent').timerInstance;7var timer = timerInstance();8timer.start();9timer.stop();10console.log(timer.result());11var timerInstance = require('stryker-parent').timerInstance;12var timer = timerInstance();13timer.start();14timer.stop();15console.log(timer.result());16module.exports = function (config) {17 config.set({18 mochaOptions: {19 }20 });21};

Full Screen

Using AI Code Generation

copy

Full Screen

1const timerInstance = require('stryker-parent').timerInstance;2timerInstance.start('myTimer');3timerInstance.stop('myTimer');4### `timerInstance.start(name: string)`5### `timerInstance.stop(name: string)`6### `timerInstance.get(name: string)`7### `timerInstance.clear(name: string)`8### `timerInstance.clearAll()`9### `timerInstance.getTimers()`

Full Screen

Using AI Code Generation

copy

Full Screen

1var timer = require('stryker-parent').timerInstance;2timer.start('my-timer');3timer.stop('my-timer');4var timer = require('stryker-parent').timerInstance;5timer.start('my-timer');6timer.stop('my-timer');7start(name: string): void8stop(name: string): void9report(name: string): void10reset(name: string): void11resetAll(): void

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful