File tree 1 file changed +22
-2
lines changed 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
/*@internal */
2
2
namespace ts {
3
3
declare const performance : { now ?( ) : number } | undefined ;
4
+ function tryGlobalPerformanceNow ( ) { // browsers
5
+ if ( typeof performance !== "undefined" ) return ( ) => performance . now ! ( ) ;
6
+ }
7
+ function tryNodePerformanceNow ( ) { // node
8
+ try {
9
+ const perf_hooks = require ( "perf_hooks" ) as typeof import ( "perf_hooks" ) ;
10
+ if ( perf_hooks . performance ) return ( ) => perf_hooks . performance . now ( ) ;
11
+ }
12
+ // eslint-disable-next-line no-empty
13
+ catch {
14
+ }
15
+ }
16
+ function tryDateNow ( ) {
17
+ if ( Date . now ) return ( ) => Date . now ( ) ;
18
+ }
4
19
/** Gets a timestamp with (at least) ms resolution */
5
- export const timestamp = typeof performance !== "undefined" && performance . now ? ( ) => performance . now ! ( ) : Date . now ? Date . now : ( ) => + ( new Date ( ) ) ;
6
- }
20
+ export const timestamp : ( ) => number =
21
+ tryGlobalPerformanceNow ( )
22
+ || tryNodePerformanceNow ( )
23
+ || tryDateNow ( )
24
+ || ( ( ) => + ( new Date ( ) ) ) ;
25
+
26
+ }
You can’t perform that action at this time.
0 commit comments