Showing posts from 2020

Semver carets and tilde in npm

If you use npm you have likely seen notation for dependencies in your package.json like ^4.2.7 or ~3.5.3 , etc. Those are respectively caret ranges and tilde ranges . They are well documented on the npm website . And while I have become quite familiar on how to use them, I had an epiphany recently that I thought I would share. This could help newbies navigate these powerful yet odd notation. The main power of those notations versus their easier-to-understand cousins x , X and * is that you can fix the lowest version . This is usually critical, because when everybody follows semantic versioning, a library is backward compatible , but your code, as the consumer, does not have to be. Actually, it is only forward compatible . Let’s say you use a library called foo . The authors of foo , at version 1.2 decide to introduce a cool new bar() method in their package. You want to take advantage of bar() in your code. If you used the x notation in your package.json , like this: &

Running Karma in specific TimeZone

Recently, I had to write some tests related to date and time. In order to tests corner cases, in particular when the UTC date was different from the local date, I had to find a way to set the timezone for my tests. There are countless posts and articles out there that explain how you can set a specific time , but I couldn’t find much about how to actually set the timezone . Many articles references how you could use your browser’s profiles to set it up, etc. But all of it seemed too complicated for my taste. In the end, I came across a gitlab-foss commit by Takuya Nogushi . Simply setting the process.env.TZ variable will do the trick. module . exports = function ( config ) { config . set ( { // your karm configuration } ) ; // Fix the timezone process . env . TZ = 'America/New_York' ; } ; I have not tested with other browsers, but this works with Chrome. The possible values for TZ are available on Wikipedia .