time.js 640 B

1234567891011121314151617181920212223
  1. let supported;
  2. let perf;
  3. export function isPerformanceSupported() {
  4. var _a;
  5. if (supported !== undefined) {
  6. return supported;
  7. }
  8. if (typeof window !== 'undefined' && window.performance) {
  9. supported = true;
  10. perf = window.performance;
  11. }
  12. else if (typeof global !== 'undefined' && ((_a = global.perf_hooks) === null || _a === void 0 ? void 0 : _a.performance)) {
  13. supported = true;
  14. perf = global.perf_hooks.performance;
  15. }
  16. else {
  17. supported = false;
  18. }
  19. return supported;
  20. }
  21. export function now() {
  22. return isPerformanceSupported() ? perf.now() : Date.now();
  23. }