UNPKG

2.25 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function _defineProperty(obj, key, value) {
9 if (key in obj) {
10 Object.defineProperty(obj, key, {
11 value: value,
12 enumerable: true,
13 configurable: true,
14 writable: true
15 });
16 } else {
17 obj[key] = value;
18 }
19 return obj;
20}
21
22/**
23 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
24 *
25 * This source code is licensed under the MIT license found in the
26 * LICENSE file in the root directory of this source tree.
27 *
28 */
29// This file is a heavily modified fork of Jasmine. Original license:
30
31/*
32Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
33
34Permission is hereby granted, free of charge, to any person obtaining
35a copy of this software and associated documentation files (the
36"Software"), to deal in the Software without restriction, including
37without limitation the rights to use, copy, modify, merge, publish,
38distribute, sublicense, and/or sell copies of the Software, and to
39permit persons to whom the Software is furnished to do so, subject to
40the following conditions:
41
42The above copyright notice and this permission notice shall be
43included in all copies or substantial portions of the Software.
44
45THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52*/
53const defaultNow = (function (Date) {
54 return function () {
55 return new Date().getTime();
56 };
57})(Date);
58
59class Timer {
60 constructor(options) {
61 _defineProperty(this, 'start', void 0);
62
63 _defineProperty(this, 'elapsed', void 0);
64
65 options = options || {};
66 const now = options.now || defaultNow;
67 let startTime;
68
69 this.start = function () {
70 startTime = now();
71 };
72
73 this.elapsed = function () {
74 return now() - startTime;
75 };
76 }
77}
78
79exports.default = Timer;