forked from bazaarvoice/bv-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 1006 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @fileOverview
* Provides a unified interface for getting the number of
* milliseconds elapsed since 1 Jan 1970
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now
*/
// Imports
var global = require('../global');
// Cache references for speed and to guard against shenanigans
var nativeDate = global.Date;
var nativeNow = nativeDate && nativeDate.now;
// Is Date.now natively supported?
var isNativeSupported = (typeof nativeNow === 'function');
/**
* Native Implementation
* Uses the natively-supported Date.now
*/
function nativeImplementation () {
return nativeNow.call(nativeDate);
}
/**
* Polyfill Implementation
* Provides similar functionality by using new Date().getTime()
*/
function polyfillImplementation () {
return new nativeDate().getTime(); /*eslint new-cap:0*/
}
module.exports = {
now: function () {
var func = (isNativeSupported) ? nativeImplementation : polyfillImplementation;
return func();
}
};