Show HN: Injectable time and timers with custom Date types for TypeScript

  • Posted 3 hours ago by jaenyf
  • 1 points
https://github.com/jaenyf/time-provider
I find TypeScript js/node environment is missing a Time-Provider (just like *.*NET TimeProvider for instance ships with its framework).

So for this purpose I built a small library (@time-provider) tailored for js/node environment.

Obviously the goal is to both avoid using global monkey-patching with fake-timers or re-writing your clock interface... and still use your date library (native or custom).

I propose four clock strategies: system (real time), fixed manual (advance time explicitly), and sequential (replay of a sequence of timestamps).

I also benchmarked slightly better performances than jest / sinon.

The project is still young, so the API may still receive refinements as real usage appears.

I would be happy to hear feedback on this ! Take care.

You can check it out on GitHub: https://github.com/jaenyf/time-provider

Jaenyf

0 comments