<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bramus! on Medium]]></title>
        <description><![CDATA[Stories by Bramus! on Medium]]></description>
        <link>https://medium.com/@bramus?source=rss-98dbbf2e6abc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3IWcPLRAfEn_EIcRAqMDTg.jpeg</url>
            <title>Stories by Bramus! on Medium</title>
            <link>https://medium.com/@bramus?source=rss-98dbbf2e6abc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:22:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bramus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Speed up build times with this little Git trick]]></title>
            <link>https://medium.com/@bramus/speed-up-build-times-with-this-little-git-trick-64158a6771e3?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/64158a6771e3</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[build-pipeline]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 10:44:03 GMT</pubDate>
            <atom:updated>2020-11-12T10:44:03.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1dvW9PADZl18OvZX.jpg" /></figure><p>When building applications on build pipelines like GitHub Actions, Google Cloud Build, CircleCI, etc. every second counts. Here’s this small trick I use to speed up build times: when cloning the repo from its Git source, I instruct Git to do a shallow clone of the single branch it is building.</p><p><em>💡 If you’re running a prebuilt “git clone” step on your Build Pipeline it most likely already uses this trick. Be sure to double check though.</em></p><h3>Shallow Cloning</h3><p>When doing a git clone you, by default, get the entire history of the project along with that. Take this clone of Laravel for example:</p><pre>$ git clone git@github.com:laravel/laravel.git<br>Cloning into &#39;laravel&#39;...<br>remote: Enumerating objects: 19, done.<br>remote: Counting objects: 100% (19/19), done.<br>remote: Compressing objects: 100% (15/15), done.<br>remote: Total 32004 (delta 5), reused 11 (delta 3), pack-reused 31985<br>Receiving objects: 100% (32004/32004), 9.94 MiB | 6.98 MiB/s, done.<br>Resolving deltas: 100% (18934/18934), done.</pre><p>That’s a whopping 32004 objects totalling ±10MiB that have been downloaded, even though the default Laravel branch only counts 66 files spread across 36 directories.</p><p>The objects contained in this ±10MiB make up the entire history of every file and folder the project. To build the project we don’t really need all that, as we’re only interested in the latest version of each file and folder. By leveraging the --depth argument of our git clone command, we can enforce just that. This is what we call Shallow Cloning.</p><pre>$ git clone --depth 1 git@github.com:laravel/laravel.git<br>Cloning into &#39;laravel&#39;...<br>remote: Enumerating objects: 108, done.<br>remote: Counting objects: 100% (108/108), done.<br>remote: Compressing objects: 100% (88/88), done.<br>remote: Total 108 (delta 6), reused 49 (delta 1), pack-reused 0<br>Receiving objects: 100% (108/108), 41.80 KiB | 535.00 KiB/s, done.<br>Resolving deltas: 100% (6/6), done.</pre><p>That’s a much speedier clone with only 108 objects, totalling a mere ±40KiB!</p><p><em>🤔 You could argue that </em><em>10MiB worth of objects is still OK to clone, but think of scenarios where you have a big “monorepo” with plenty of branches … then you’ll be talking about hundreds of wasted MiBs, if not GiBs.</em></p><h3>Single Branch Cloning</h3><p>When building a project you’re building only one certain branch. Information about the other branches is irrelevant at that time. To directly clone one specific branch we can use the --branch option to target said branch. With that alone we won’t get there though, we we still need to discard information about other branches. This is where the --single-branch option comes into play:</p><pre>$ git clone --branch 3.0 --single-branch git@github.com:laravel/laravel.git<br>Cloning into &#39;laravel&#39;...<br>remote: Enumerating objects: 20392, done.<br>remote: Total 20392 (delta 0), reused 0 (delta 0), pack-reused 20392<br>Receiving objects: 100% (20392/20392), 5.79 MiB | 853.00 KiB/s, done.<br>Resolving deltas: 100% (12731/12731), done.</pre><p>Here we’ve cloned only the 3.0 branch of Laravel, resulting in roughly 10000 fewer objects to be downloaded.</p><p>By checking the contents of git branch -a we can also verify that other branch info has not been fetched:</p><pre>$ cd laravel<br>$ git branch -a<br>* 3.0<br>  remotes/origin/3.0</pre><h3>Shallow Cloning + Single Branch Cloning</h3><p>By combining both we can download only the latest files of a specific branch. Since the use of --single-branch is implied when using --depth, we can drop the former and our command will look like this:</p><pre>$ git clone --depth 1 --branch &lt;branchname&gt; &lt;repo&gt;</pre><p>Here’s an example downloading the Laravel 3.0 branch:</p><pre>$ git clone --depth 1 --branch 3.0 git@github.com:laravel/laravel.git<br>Cloning into &#39;laravel&#39;...<br>remote: Enumerating objects: 545, done.<br>remote: Counting objects: 100% (545/545), done.<br>remote: Compressing objects: 100% (465/465), done.<br>remote: Total 545 (delta 78), reused 293 (delta 45), pack-reused 0<br>Receiving objects: 100% (545/545), 1.34 MiB | 832.00 KiB/s, done.<br>Resolving deltas: 100% (78/78), done.</pre><p>With this in place you’ll see your build times drop by minutes, especially when working on a monorepo with many branches.</p><p><em>💡 This post </em><a href="https://www.bram.us/2020/11/11/speed-up-build-times-with-this-little-git-trick/"><em>first appeared on my blog bram.us</em></a><em>. You can follow it via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64158a6771e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESNext: Declarations in Conditionals]]></title>
            <link>https://medium.com/front-end-weekly/esnext-declarations-in-conditionals-c9122d99dc11?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9122d99dc11</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ecmascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[esnext]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 08:48:17 GMT</pubDate>
            <atom:updated>2020-08-17T13:15:07.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*lDk8AmRdr5yR-Q2S.jpg" /></figure><p>An ECMAScript Language Feature that I’m <a href="https://www.bram.us/series/esnext-talk/">looking forward to</a> is <a href="https://github.com/tc39/proposal-Declarations-in-Conditionals">Declarations in Conditionals</a>. It adds the capability to declare variables inside conditional statements. Let’s take a look …</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F788447%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F788447%2F&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/18214d8333adbb5668f31791a3202b60/href">https://medium.com/media/18214d8333adbb5668f31791a3202b60/href</a></iframe><h3>Setting the Scene</h3><p>Say you want to iterate over an array which <em>might be</em> tucked away inside an object. To do so, you’d most likely first check for that variable’s existence using a simple if</p><pre>if (user.meta.interests) {<br>    for (let interest of user.meta.interests) {<br>        // …<br>    }<br>}</pre><p>As we’re now typing user.meta.interests twice in our code you might declare an intermediary variable, and use that further down in your code:</p><pre>let interests = user.meta.interests;<br>if (interests) {<br>    for (let interest of interests) {<br>        // …<br>    }<br>}</pre><p>But now you have a nasty side-effect: you’re loitering the scope with this extra interests variable. This is quite useless, as you’re only using it inside the if statement.</p><p><em>💁‍♂️ To make it totally failsafe, you might also want to add some </em><a href="https://www.bram.us/2017/01/30/javascript-null-propagation-operator/"><em>Optional Chaining</em></a><em> in there and check if </em><em>interests is iterable, but that’s beyond the scope of this post.</em></p><h3>Hello “Declarations in Conditionals”</h3><p>With the “Declarations in Conditionals” proposal we can keep this extra interests variable, yet without loitering the outer scope. <strong>We do this by declaring the variable directly inside the conditional (e.g. </strong><strong>if statement)</strong>, like so:</p><pre>if (let interests = user.meta.interests) {<br>    for (let interest of interests) {<br>        // …<br>    }<br>}</pre><p><em>⚠️ Note that this is an assignment right there, not an equality check!</em></p><p>With that one line the interests variable:</p><ol><li>will be declared</li><li>will have a value assigned to it</li><li>will be checked for being <em>falsy</em> or not</li></ol><p>Scope-wise the interests variable will have its scope limited local to the conditional (e.g. only visible inside the if).</p><p>The proposal limits declarations to use either const or let; declarations in conditionals with var are currently not allowed.</p><h3>Sidenote: you’re already familiar with this!</h3><p>You might not 100% realize it, but you’re already doing this kind of thing when using a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for">for</a> loop. Inside its initialization part (e.g. its first part) you are also declaring variables.</p><pre><em>for (let i = 0; i &lt; 5; i++) {<br>  console.log(i);<br>}</em></pre><p>Did you know that you can declare more than one variable there, separated by a comma? In the example below I declare an extra variable len right after declaring i:</p><pre><em>const cars = [&#39;Ford&#39;, &#39;Mercedes&#39;, &#39;BMW&#39;];</em></pre><pre><em>for (let i = 0, len = cars.length; i &lt; len; i++) {<br>  console.log(cars[i]);<br>}</em></pre><p>What about the scope of len you might ask? Variables declared using let are scoped to the statement (e.g. local to the loop). Variables declared using var get hoisted. And oh, it’s not allowed to declare variables using const here.</p><h3>So, when can we use it?</h3><p>The proposal is currently Stage-1, so it still has a long way to go before it can become an official part of the standard.</p><p><strong><em>❓ Stage-1?</em></strong></p><p><em>The Technical Committee which is concerned with the standardization of ECMAScript (e.g. </em><a href="https://tc39.es/"><em>TC39</em></a><em>) has </em><a href="https://tc39.github.io/process-document/"><em>a 5 stage process in place, ranging from stage-0 to stage-4</em></a><em>, by which it develops a new language feature.</em></p><p><em>Stage-1 is the Proposal stage. It signals that the committee is showing interest in the proposal and that it is seeking further investigation on how to tackle it.</em></p><p><em>At this stage the proposal is still subject to heavy changes. It is only when a proposal reaches Stage 4 that it is ready to become part of the ECMAScript Specification.</em></p><p>As it’s still Stage-1, it can change quite a lot before it to be finished. And I’m quite sure it will change, as right now:</p><ul><li>It only allows declaring one variable.</li><li>It only checks for values being <em>falsy</em> or not.</li></ul><p>These two feature are currently listed under <a href="https://github.com/tc39/proposal-Declarations-in-Conditionals#future-work">“Future Work”</a> of the proposal, which I hope to see included in the proposal before it is finalized. The proposed syntax looks like this:</p><pre><em>if (let x = 1, y = 2; x || y) {<br>    // …<br>}</em></pre><p>Must say I’m pretty curious how this one will evolve, as I’m already quite excited about it: it’s one of those small additions that will have a pretty big impact on how I write my code.</p><p>If you have an addition to this proposal, feel free to <a href="https://github.com/tc39/proposal-Declarations-in-Conditionals">join the discussion in the Declarations in Conditionals GitHub repository</a>.</p><p><em>💡 This post </em><a href="https://www.bram.us/2020/08/04/esnext-declarations-in-conditionals/"><em>first appeared on my blog bram.us</em></a><em>. You can follow it via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><p><em>📚 I’ve collected more articles on upcoming ECMAScript Language Features in </em><a href="https://www.bram.us/series/esnext-proposals/"><em>a series which you can also read on my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9122d99dc11" width="1" height="1" alt=""><hr><p><a href="https://medium.com/front-end-weekly/esnext-declarations-in-conditionals-c9122d99dc11">ESNext: Declarations in Conditionals</a> was originally published in <a href="https://medium.com/front-end-weekly">Frontend Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add Dark Mode to a JavaScript App (React / Angular / Vue / etc)]]></title>
            <link>https://medium.com/@bramus/how-to-add-dark-mode-to-a-javascript-app-react-angular-vue-etc-4430c1547e9a?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4430c1547e9a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Fri, 13 Dec 2019 08:28:16 GMT</pubDate>
            <atom:updated>2019-12-13T08:29:52.590Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this post I’ll cover how to add Dark Mode to a JavaScript App. All major frameworks (React, Angular, Vue, etc.) are covered!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*EzECXNEGP_GcNME1.png" /></figure><p>👉 <a href="https://www.bram.us/2019/05/23/css-color-scheme-queries-dark-mode-css/#how">Use CSS</a>.</p><p><em>💡 This post </em><a href="https://www.bram.us/2019/12/10/how-to-add-dark-mode-to-a-javascript-app-react-angular-vue-etc/"><em>first appeared on my blog bram.us</em></a><em>. You should subscribe to it either via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, or</em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4430c1547e9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RE: The React is “just” JavaScript Myth]]></title>
            <link>https://medium.com/@bramus/re-the-react-is-just-javascript-myth-2f48c4e790e9?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f48c4e790e9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[esnext]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 13:53:45 GMT</pubDate>
            <atom:updated>2018-06-28T11:26:41.637Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*-i6KGvbyqtEXM1qT.png" /></figure><p><em>🗣 This was originally posted as a reply over at Dave’s blog. Unfortunately Disqus — the commenting system Dave uses — thinks it’s spam, so I’m posting it here as a full post instead.</em></p><p>In his blogpost <a href="https://daverupert.com/2018/06/the-react-is-just-javascript-myth/">The React is “just” JavaScript Myth</a>, Dave Rupert said this:</p><blockquote>React shows up on the scene with Babel, Webpack, and JSX (which each have their own learning curve) then quickly branches out into technologies like Redux, React-Router, Immutable.js, Axios, Jest, Next.js, Create-React-App, GraphQL, and whatever weird plugin you need for your app.</blockquote><p>As a JavaScript developer <em>(who happens to be writing mostly React (Native) these days)</em> I’d like to counter that though …</p><p>Babel + Webpack + JSX: Yes, those are the basics. To run a train you need a locomotive, tracks, and a power source.</p><p>Although … thanks to things like create-react-app (CRA) you can start coding out-of-the-box as it has a babel-webpack thing set up for you. Even though highly interesting <strong>you don’t really need to know the inner workings of Babel nor Webpack when starting out with React</strong>.</p><p>As for JSX: JSX syntax essentially compiles down to functions. You don’t really need JSX, but if you wouldn’t use it your code would grow exponentially (&lt;b&gt;vs. React.createElement(&#39;b&#39;, { children, … })). <strong>If you know HTML, JSX can be learnt quite easily.</strong></p><p>As for the rest of the things Dave mentions: these are not mandatory. Don’t let this list of fast- and ever-changing technologies overwhelm you, as you can easily create a React app without ‘m:</p><ul><li>Redux — Even the author of Redux himself says you might not need it. <em>(It is nice to work with though 😉)</em></li><li>React-Router — You can perfectly use different pages if you want. Additionally you don’t need a router when refactoring one or two components from your site to React implementations.</li><li>Immutable.js — I’ve written quite a lot of React apps by now and have used it only once so far.</li><li>Axios — You can use ES’ built-in fetch instead. No need to learn another library 😉</li><li>Jest — Only if you want to write tests</li><li>Next.js — Never used it</li><li>CRA — Never used it.</li><li>GraphQL — Never used it (but I am really interested in it).</li></ul><p>Of course, as your code and knowledge evolves, you most likely will start using one / a few / all of those 😉</p><p>The one thing Dave hasn’t mentioned (by name) in his post is ES2015. To me that was the biggest hurdle to take when starting out with React.</p><p>Reading Dave’s post I think his — and many others’ — gripe with React comes from exactly this. <strong>It’s easy to confuse React-specifics with ES2015-specifics</strong> since React uses a lot of the new ES language features.</p><p>Take Array.prototype.map for example (which Dave mentions): that’s an ES feature and has nothing to do with React itself. There’s even an article dedicated to this distinction: <a href="https://zendev.com/2018/05/15/learning-react-is-this-es6-or-react.html">“Learning React: Is This ES6 or React?”</a></p><p>Once one embraces these new ES features — which I have <a href="https://www.bram.us/2018/06/01/whats-next-for-javascript/">a full presentation</a> about — and uses ‘m more often one will start loving them … I know I have 😊</p><p><em>TL;DR To start with React, learning ES2015 is essential. Sprinkle some JSX on top and you’re good to go. It’s ES2015 that’s the hardest part to learn. React itself builds on top of these language features. So yes, React really is “Just JavaScript”.</em></p><p><em>💡 This post </em><a href="https://www.bram.us/2018/06/05/re-the-react-is-just-javascript-myth/"><em>first appeared on my blog bram.u</em></a><em>s. You can follow my blog via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f48c4e790e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grid Time (or “Why are clocks in Europe lagging behind by 5 minutes?”)]]></title>
            <link>https://medium.com/@bramus/grid-time-or-why-are-clocks-in-europe-lagging-behind-by-5-minutes-dbc2dd028bfa?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbc2dd028bfa</guid>
            <category><![CDATA[energy]]></category>
            <category><![CDATA[time]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Wed, 07 Mar 2018 17:56:52 GMT</pubDate>
            <atom:updated>2018-03-08T08:44:38.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wl0K7fchR8lb_jB1LfyEjw.png" /></figure><p>Yesterday I heard on the news that clocks in Europe have started to lag behind on the official time. The culprit is a fluctuation in Europe’s electricity grid. Clocks, like the ones in your microwave, that are reliant on <strong>Grid Time</strong> are affected by these fluctuations.</p><blockquote>Grid Time is a time measurement which is based on the standard grid frequency of 50Hz in Europe. Fifty oscillations in alternating current equate to one second of grid time. Frequency fluctuations lead to deviations in grid time. If the frequency is lower than 50Hz, the fifty oscillations last slightly longer. If, on the other hand, the frequency is higher than 50Hz, the fifty oscillations are shorter. Since one second of grid time always constitutes precisely fifty oscillations, the grid seconds therefore last slightly shorter or longer depending on the frequency.</blockquote><p>Due to <a href="https://www.entsoe.eu/news-events/announcements/announcements-archive/Pages/News/2018-03-06-press-release-continuing-frequency-deviation-in-the-continental-european-power-system.aspx">a disruption of the power system originating in Serbia/Kosovo</a> since mid January 2018, a total of 113GWh of the energy production in Europe has been missing. Electrical generators in other European countries had to do more work, as they tried to cover this loss. This however has some side-effects.</p><blockquote>The electrical generators of an electricity grid rotate more readily and faster when consumption is low. Consequently, they rotate with a higher frequency. Conversely, the <strong>electrical generators rotate more laboriously and with a lower frequency when consumption is greater</strong>.</blockquote><p>With Europe’s grid running at a frequency slightly slower than 50Hz, Grid Time has started to drift off. This is known as <strong>Grid Time Deviation.</strong></p><blockquote>The Grid Time Deviation is calculated by comparing Grid Time with UTC time (coordinated universal time), which is determined using highly precise atomic clocks.</blockquote><p>Ever since mid January 2018 this Grid Time Deviation has been building up. At the time of writing Grid Time Deviation is about -5 minutes <em>(e.g. clocks are lagging behind by 5 minutes)</em>. You can check the Grid Frequency and Grid Time Deviation yourself on <a href="https://www.swissgrid.ch/swissgrid/en/home/experts/topics/frequency.html">Swiss Grid’s frequency page</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4HZs95GvzlSe3qG9TDGMhg.png" /><figcaption><em>Grid Time Drift, dd 2018–03–07</em></figcaption></figure><p>Usually the maintainers of the electricity grid adjust the frequency to keep Grid Time in sync with UTC.</p><blockquote>The Grid Time Deviation is constantly balanced out. If the time deviation is more than twenty seconds the frequency is corrected in the grid. In order to balance out the time deviation again the otherwise customary frequency of 50 Hz (Europe) is changed as follows:</blockquote><blockquote>– 49.990 Hz, if the grid time is running ahead of UTC time<br>– 50.010 Hz, if the grid time is lagging behind UTC time</blockquote><p>This time however they couldn’t keep up, as 113GWh is a huge amount of energy. Thankfully it didn’t drop below 47.5Hz, because then we’d be having blackouts.</p><p><em>💡 This post </em><a href="https://www.bram.us/2018/03/07/grid-time-or-why-are-clocks-in-europe-lagging-behind-by-5-minutes/"><em>first appeared on my blog bram.us</em></a><em>. You can follow my blog via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbc2dd028bfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cancel a JavaScript Promise with AbortController]]></title>
            <link>https://medium.com/@bramus/cancel-a-javascript-promise-with-abortcontroller-3540cbbda0a9?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3540cbbda0a9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Mon, 19 Feb 2018 21:45:14 GMT</pubDate>
            <atom:updated>2019-01-22T12:00:57.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2USQFRPHkmpnXI8Ty-OloA.png" /></figure><p>In <a href="http://how%20to%20cancel%20your%20promise/">How to Cancel Your Promise</a> Seva Zaikov has done a nice writeup on several techniques on how to “cancel” promises. After also touching generators and async/await the conclusion is that you can’t actually cancel a promise with the techniques mentioned <em>(you may introduce some workarounds to track the cancelled state yourself, yet that won’t actually cancel an ongoing promise)</em>.</p><p>At the end of the article the author mentions <a href="https://developers.google.com/web/updates/2017/09/abortable-fetch">abortable fetch</a>, but doesn’t dig deeper into it. A shame though, as the shiny AbortController – the driving force behind the abortable fetch – is something which will allow you to actually cancel any promise <em>(and not just </em><em>fetch)</em>!</p><p>To use the AbortController, create an instance of it, and pass its signal into a promise.</p><pre>// Creation of an AbortController signal<br>const controller = new AbortController();<br>const signal = controller.signal;<br><br>// Call a promise, with the signal injected into it<br>doSomethingAsync({ signal })<br>	.then(result =&gt; {<br>		console.log(result);<br>	})<br>	.catch(err =&gt; {<br>		if (err.name === &#39;AbortError&#39;) {<br>			console.log(&#39;Promise Aborted&#39;);<br>		} else {<br>			console.log(&#39;Promise Rejected&#39;);<br>		}<br>	});</pre><p>Inside the actual promise you listen for the abort event to be fired on the given signal, upon which the promise will be cancelled.</p><pre>// Example Promise, which takes signal into account<br>function doSomethingAsync({signal}) {<br>	if (signal.aborted) {<br>		return Promise.reject(new DOMException(&#39;Aborted&#39;, &#39;AbortError&#39;));<br>	}<br><br>	return new Promise((resolve, reject) =&gt; {<br>		console.log(&#39;Promise Started&#39;);<br><br>		// Something fake async<br>		const timeout = window.setTimeout(resolve, 2500, &#39;Promise Resolved&#39;)<br><br>		// Listen for abort event on signal<br>		signal.addEventListener(&#39;abort&#39;, () =&gt; {<br>			window.clearTimeout(timeout);<br>			reject(new DOMException(&#39;Aborted&#39;, &#39;AbortError&#39;));<br>		});<br>	});<br>}</pre><p>With this set up, you can call controller.abort(); from anywhere you like in order to abort/cancel the promise:</p><pre>document.getElementById(&#39;stop&#39;).addEventListener(&#39;click&#39;, (e) =&gt; {<br>	e.preventDefault();<br>	controller.abort();<br>});</pre><p>Below is a combined example with two buttons. The “start” button starts a promise which resolves after 2.5 seconds. When hitting “stop/abort” during that timeframe however, the promise will be cancelled.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fbramus%2Fembed%2Fpreview%2FKZKYmr%3Fheight%3D600%26slug-hash%3DKZKYmr%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fbramus%2Fpen%2FKZKYmr&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F89905.KZKYmr.small.a7e5dcea-6efc-4e17-b27f-1921da5e252f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c747360d908710da4898bec7c896b92e/href">https://medium.com/media/c747360d908710da4898bec7c896b92e/href</a></iframe><p>My personal nitpick with AbortController is the fact that it’s part of the DOM spec, and not the ECMAScript Spec. This makes it a browser feature, not a language feature. There <a href="https://github.com/tc39/proposal-cancelable-promises">once was a proposal for cancelable promises</a>, yet it got withdrawn at Stage-1.</p><p>AbortController is available in Firefox 57 and Edge 16. Chrome and Safari are still working on it.</p><p><em>💡 This post </em><a href="https://www.bram.us/2017/12/13/cancel-a-javascript-promise-with-abortcontroller/"><em>first appeared on my blog bram.u</em></a><em>s. You can follow my blog via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3540cbbda0a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESNext: JavaScript “Nullish Coalescing Operator”]]></title>
            <link>https://medium.com/@bramus/esnext-javascript-nullish-coalescing-operator-3e56afb64b54?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e56afb64b54</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[esnext]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 13:44:29 GMT</pubDate>
            <atom:updated>2018-02-05T15:31:26.866Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2USQFRPHkmpnXI8Ty-OloA.png" /></figure><p>One of my favorite ECMAScript Proposals is the <a href="https://www.bram.us/2017/01/30/javascript-null-propagation-operator/">“Optional Chaining Operator”</a>. Another proposal that forms great duo with it is the “Nullish Coalescing Operator” <em>(sometimes also referred to as “Nullary Coalescing Operator”)</em>.</p><p>Both proposals still are Stage-1, but don’t let that stop us from taking a peek into it right now.</p><p><strong><em>❓ Stage-1?<br></em></strong><em>The TC39 Committee has </em><a href="https://tc39.github.io/process-document/"><em>a 5 stage process in place, ranging from stage-0 to stage-4</em></a><em>, by which it develops a new language feature. Stage-1 is the proposal phase.</em></p><h3>The problem</h3><p>As explained in the <a href="https://www.bram.us/2017/01/30/javascript-null-propagation-operator/">“Optional Chaining Operator” post</a> we can get properties of an object in a fail safe way using Short-Circuit Logic or by using the proposed Optional Chaining operator (?.) in the nearby future:</p><pre>// Today: Extract firstName using Short-Circuit Logic<br>const firstName = message.body &amp;&amp; message.body.user &amp;&amp; message.body.user.firstName;</pre><pre>// Near future: Extract firstName using the Optional Chaining Operator<br>const firstName = message.body?.user?.firstName;</pre><p>A common technique used is to add a default fallback value using the logical OR operator (||):</p><pre>const firstName = message.body?.user?.firstName || &#39;Stranger&#39;;</pre><p>Whilst this works fine, there is one problem with <em>falsy</em> values: when the left hand side of the OR expression evaluates to falsy (e.g. null, undefined, false, 0, empty string, …), the right hand side of the expression will be used. For nulland undefined that’s not a problem, but it is for false, 0, empty string, etc.:</p><pre>const message = {<br>    settings: {<br>        animationDuration: 0,<br>        showSplashScreen: false<br>    },<br>};<br><br>const showSplashScreen = message.settings?.showSplashScreen || true;<br>// --&gt; true 🚫</pre><p>The result here is true (the fallback), even though message.settings.showSplashScreenwas defined to be false.</p><h3>The solution</h3><p>The proposed <a href="https://github.com/tc39/proposal-nullish-coalescing">Nullish Coalescing Operator</a> ?? is intended to provide a solution to this problem. It serves as an equality check against <em>nullary</em> values (e.g.<br>null or undefined). Whenever the expression to the left of the ?? operator evaluates to either undefined or null, the value defined to the right will be returned.</p><p>Combined with the Optional Chaining Operator, our code snipped can be fixed like this:</p><pre>const message = {<br>    settings: {<br>        animationDuration: 0,<br>        showSplashScreen: false<br>    },<br>};<br><br>const showSplashScreen = message.settings?.showSplashScreen ?? true;<br>// --&gt; false 🎉</pre><p>Small change, big impact 🙂</p><h3>So, when can we us this?</h3><p>You can use the Nullish Coalescing Operator today already thanks to Babel’s <a href="https://www.npmjs.com/package/@babel/plugin-proposal-nullish-coalescing-operator">plugin-proposal-nullish-coalescing-operator plugin</a> <em>(for use with Babel 7)</em>.</p><p>Do note that the proposal still Stage-1 <em>(soon Stage-2 by the looks of it)</em> and might still change in the future.</p><h3>In Short</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pH4yokLudOD2m3PnLOBEGw.png" /></figure><p>💻 <em>The examples embedded in this post are part of a talk on ESNext named </em><strong><em>“What’s next for JavaScript?”</em></strong><em>, which I recently gave at a </em><a href="https://fronteers.nl/vereniging/commissies/belgie"><em>Fronteers België</em></a><em> meetup. I’m currently still in the process of preparing the slides for publication. I’m available for bringing this talk at your meetup/conference.</em></p><p><em>💡 This post </em><a href="https://www.bram.us/2018/02/05/esnext-javascript-nullish-coalescing-operator/"><em>first appeared on my blog bram.us</em></a><em>. You can follow it via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><p>📚 <em>Other posts in this series include:<br>– </em><a href="https://www.bram.us/2018/01/30/whats-new-in-ecmascript2018/"><em>JavaScript: What’s new in ECMAScript 2018 (ES2018)?</em></a><em><br>– </em><a href="https://www.bram.us/2017/01/30/javascript-null-propagation-operator/"><em>ESNext: JavaScript “Optional Chaining Operator”</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e56afb64b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript: What’s new in ECMAScript 2018 (ES2018)?]]></title>
            <link>https://medium.com/@bramus/javascript-whats-new-in-ecmascript-2018-es2018-17ede97f36d5?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/17ede97f36d5</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Wed, 31 Jan 2018 10:06:47 GMT</pubDate>
            <atom:updated>2019-08-14T08:56:06.595Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*2USQFRPHkmpnXI8Ty-OloA.png" /></figure><p><em>🌐 Available Translations: </em><a href="https://medium.com/@linus2228/javascript-%D1%87%D1%82%D0%BE-%D0%BD%D0%BE%D0%B2%D0%BE%D0%B3%D0%BE-%D0%B2-ecmascript-2018-es2018-e0af4a53cb5c"><em>🇷🇺 Russian</em></a></p><p>At the latest TC39 meeting the new features that will make it into the <strong>“ECMAScript® 2018 Language Specification”</strong> (ES2018) have been selected. All proposals that have reached stage-4 since the consolidation of <a href="https://www.bram.us/2017/07/18/es2017-es8-language-features/">ES2017</a> got selected. This post gives one a quick look at the features that made it into ES2018.</p><p><strong><em>❓ Stage-4 <br></em></strong><em>The TC39 Committee has </em><a href="https://tc39.github.io/process-document/"><em>a 5 stage process in place, ranging from stage-0 to stage-4</em></a><em>, by which it develops a new language feature. Stage-4 is the “Finished” phase. A list of Stage-4 proposals is </em><a href="https://github.com/tc39/proposals/blob/master/finished-proposals.md"><em>available on GitHub</em></a><em>.</em></p><h3>Object Rest/Spread Properties</h3><p>When destructuring an object, <a href="https://github.com/tc39/proposal-object-rest-spread">Object Rest Properties</a> allow you to collect the remaining properties of an object onto a new object. Think of it as a magic magnet attracting all leftovers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9x6JBbf8RvAbtNDecUhLQ.png" /></figure><p>I use this one myself a lot, especially in a React (Native) context where I pluck certain values from this.props for internal use, and then forward on all other props to the returned child component by spreading them again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLrYwcDW3G20NBPBiAIZFw.png" /></figure><p>Additionally, if you turn your thinking-logic around a bit, Object Rest Properties provide you with a good way to <a href="https://www.bram.us/2018/01/10/javascript-removing-a-property-from-an-object-immutably-by-destructuring-it/">remove a property from an object in an immutable way</a>.</p><h3>Asynchronous Iteration</h3><p>With <a href="https://github.com/tc39/proposal-async-iteration">Asynchronous Iteration</a> we get asynchronous iterators and asynchronous iterables. Asynchronous iterators just like regular iterators, except their next()method returns a promise for a { value, done } pair. To consume asynchronous iterables, we can now use the await keyword with for … ofloops.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_7kNH0_rFeicKi9tObdZw.png" /></figure><h3>Promise.prototype.finally()</h3><p><a href="https://github.com/tc39/proposal-promise-finally">Promise.prototype.finally()</a> finalizes the whole promises implementation, allowing you to register a callback to be invoked when a promise is settled (either fulfilled, or rejected).</p><p>A typical use case is to hide a spinner after a fetch() request: instead of duplicating the logic inside the last .then() and .catch(), one can now place it inside .finally()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zLMfcqCqEc5avr8d84xTQ.png" /></figure><h3>RegExp related features</h3><p>In total 4 RegExp related proposals made it into ES2018:</p><ul><li><a href="https://github.com/tc39/proposal-regexp-dotall-flag">s (</a><a href="https://github.com/tc39/proposal-regexp-dotall-flag">dotAll) flag for regular expressions</a></li><li><a href="https://github.com/tc39/proposal-regexp-named-groups">RegExp named capture groups</a></li><li><a href="https://github.com/tc39/proposal-regexp-lookbehind">RegExp Lookbehind Assertions</a></li><li><a href="https://github.com/tc39/proposal-regexp-unicode-property-escapes">RegExp Unicode Property Escapes</a></li></ul><p>I especially digg the “RegExp named capture groups” feature, as it improves readability:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GuYqQQ29T3eULUlUFLOR0g.png" /></figure><p>More info on these features can be found at Mathias Bynens — one of the driving forces behind these proposals — his blog: <a href="https://mathiasbynens.be/notes/es-regexp-proposals">ECMAScript regular expressions are getting better!</a></p><h3>Other new Features</h3><p>To top it off <a href="https://github.com/tc39/proposal-template-literal-revision">a tweak to template literals</a> landed: when using tagged template literals the restriction on escape sequences are removed, thus allowing things like \xerxes. Before this tweak an error would be thrown because \x is the start of a hex escape with erxes not being a valid hex value.</p><p><strong><em>❓ Tagged template literal<br></em></strong><em>As per </em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals"><em>MDN</em></a><em>: If there is an expression preceding the template literal, the template string is called a “tagged template literal”. In that case, the tag expression (usually a function) gets called with the processed template literal, which you can then manipulate before outputting.</em></p><h3>What now?</h3><p>Do note that not all these features are readily available in all browsers. Meaning that they’re Stage-4 means that they are finished, and that browser vendors should implement them <em>(some already have, others are in the process)</em>.</p><p>As for the future, I’m already looking forward at what’s next to come for JavaScript. Things like the <a href="https://www.bram.us/2017/01/30/javascript-null-propagation-operator/">Optional Chaining Operator</a> already get me very excited 😊</p><p><em>💻 The examples embedded in this post are part of a talk on ESNext named </em><strong><em>“What’s next for JavaScript?”</em></strong><em>, which I recently gave at a </em><a href="https://fronteers.nl/vereniging/commissies/belgie"><em>Fronteers België</em></a><em> meetup. I’m currently still in the process of preparing the slides for publication. I’m available for bringing this talk at your meetup/conference.</em></p><p><em>💡 This post </em><a href="https://www.bram.us/2018/01/30/whats-new-in-ecmascript2018/"><em>first appeared on my blog bram.us</em></a><em>. You can follow it via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17ede97f36d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stealing Usernames, Passwords, and other (Personal) Data via Browsers and NPM Packages]]></title>
            <link>https://medium.com/@bramus/stealing-usernames-passwords-and-other-personal-data-via-browsers-and-npm-packages-30938725ebc8?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/30938725ebc8</guid>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[browsers]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 22:58:24 GMT</pubDate>
            <atom:updated>2018-01-18T09:56:45.443Z</atom:updated>
            <content:encoded><![CDATA[<p>Late 2016, Stoyan Stefanov published <a href="https://www.phpied.com/oversharing-with-the-browsers-autofill/">“Oversharing with the browser’s autofill”</a>. It’s an article on stealing personal data using a browser’s form autofill feature. The attack works by abusing the fact that autocompletion will also complete fields which are visually hidden.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*WChv_tXK8rqUASVNxrqNSw.gif" /><figcaption>Stealing Personal Data through Browser Autocomplete</figcaption></figure><p><em>Note: it was only in January 2017 that this type of exploit gained traction, and was accredited to the wrong person (see </em><a href="http://www.zdnet.com/article/new-phishing-attack-steals-personal-data-through-browser-autofill/"><em>this ZDNet article</em></a><em> for example). As Stoyan points out in his article: </em><a href="http://blog.elevenpaths.com/2013/10/how-to-take-advantage-of-chrome.html"><em>it’s been warned about as early since 2013</em></a><em>.</em></p><p>If it’s a comfort: it’s not until you enter data in one field and successively choose to autocomplete, that you’re leaking data.</p><p>Fast forward to late 2017: In <a href="https://freedom-to-tinker.com/2017/12/27/no-boundaries-for-user-identities-web-trackers-exploit-browser-login-managers/">“No boundaries for user identities: Web trackers exploit browser login managers”</a> the autocomplete feature of password managers is abused by rogue advertising scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xlGsG4apmGtsvel-QcVS6Q.png" /><figcaption>Web Trackers exploit Browser Login Managers</figcaption></figure><p>Since your password manager (and your browser itself) will prefill usernames and passwords, any script loaded can read these out and do whatever they want to with it. Unlike the autocomplete above this kind of leak will happen automatically. At least two advertising scripts have been identified to using this technique to collect usernames.</p><p>The only way to prevent this is that browsers return empty strings for autocompleted values when reading them in via input.value, or at least present a confirm dialog (and pause the JS runtime) until approved.</p><p>In <a href="https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5">“I’m harvesting credit card numbers and passwords from your site. Here’s how.”</a> David Gilbertson notched it up a little:</p><blockquote>I can’t believe people spend so much time messing around with cross-site scripting to get code into a single site. It’s so easy to ship malicious code to thousands of websites, with a little help from my web developer friends.</blockquote><p><em>(I know, the previous attacks mentioned weren’t XSS attacks, yet one could perform them through after injecting a remote script.)</em></p><p>All you have to do is write a successful NPM package which others will use. Popular ones are things like logging libraries, which have many many downloads. If you then release a version with some rogue code …</p><p>Would this kind of hack code be detected easily? Not really. The versions that get published on NPM are compiled and minified versions which are nowhere to be found in the source repo. Above that the compiled code can be obfuscated, so that words like fetch don’t appear in it. And requests performed via dynamically injected links that have a rel=&quot;prefetch&quot; attribute set can bypass Content Security Policies.</p><p>Yesterday evening there was a small debacle on the NPM front as <a href="https://status.npmjs.org/incidents/41zfb8qpvrdj">several packages had gone missing</a> … it was <a href="https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/">left-pad chaos</a> all over again, albeit for only a short period of time.</p><p>One of the packages missing — namely <a href="https://www.npmjs.com/package/pinkie-promise">pinkie-promise</a> – is used in eslint, which itself is used just about everywhere. Installing dependencies in React-based apps didn’t work anymore because of this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkkJ1ghF2OPqTRSbwFjz2g.jpeg" /><figcaption>Where did pinkie-promise go?</figcaption></figure><p>By now the issue has been resolved <em>(</em><a href="http://blog.npmjs.org/post/169432444640/npm-operational-incident-6-jan-2018"><em>postmortem here</em></a><em>)</em>, yet the window between Jan 06, 2018 - 19:45 UTC <em>(identified)</em> and Jan 06, 2018 - 21:58 UTC<em>(resolved)</em> was a very dangerous one. In said window any developer could release <em>(and have released!)</em> packages with the same name. Mostly they were re-publishes of the actual thing, yet one could’ve also published rogue versions such as the ones described above.</p><p><a href="http://blog.npmjs.org/post/168978377570/new-package-moniker-rules">NPM is already fighting name squatters</a> by disallowing variants with punctuations and promoting the use of username-scoped packages, but I personally think an extra feat is missing: <strong>Upon unpublishing of a package <em>(be it by accident or not)</em>, its name should be quarantined for 30 days. In that 30 day window no NPM user other than the original one should be able to republish a package having the same name.</strong> Additionally there should be an option for the original author to release or transfer a package name to another NPM user.</p><p>FIN.</p><p><em>This post </em><a href="https://www.bram.us/2018/01/07/stealing-usernames-passwords-and-other-personal-data-via-browsers-and-npm-packages/"><em>first appeared on my blog bram.us</em></a><em>. You can follow it via </em><a href="https://www.bram.us/feed/"><em>RSS</em></a><em>, </em><a href="https://www.twitter.com/bramusblog/"><em>Twitter</em></a><em>, and </em><a href="https://www.facebook.com/bramusblog"><em>Facebook</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30938725ebc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I’m excited about Yarn]]></title>
            <link>https://medium.com/@bramus/why-im-excited-about-yarn-75037a198bef?source=rss-98dbbf2e6abc------2</link>
            <guid isPermaLink="false">https://medium.com/p/75037a198bef</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[yarn]]></category>
            <dc:creator><![CDATA[Bramus!]]></dc:creator>
            <pubDate>Wed, 12 Oct 2016 13:50:02 GMT</pubDate>
            <atom:updated>2016-10-12T13:50:02.399Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, Facebook — in collaboration with Google and others — released Yarn, a new package manager for JavaScript.</p><h3>Yarn on Twitter</h3><p>Introducing Yarn: a new package manager for JavaScript from @fbOpenSource, @tildeio, @googledevs &amp;amp; @exponentjs. https://t.co/2LfN5OXjOv</p><p>In comparison to npm, <a href="https://yarnpkg.com/">the Yarn website</a> pushes these three main benefits forwards:</p><ol><li>Speed</li><li>Reliability</li><li>Security</li></ol><p>Not in that list, and something that I’m really super excited about, is the fact that Yarn is architected in such a way that it basically is a drop-in replacement fornpm <em>(the binary)</em> itself. <strong>Yarn does not bring extra </strong><a href="https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4#.edtw4pnnv"><strong>fatigue</strong></a><strong> to the JavaScript game</strong>:</p><ul><li>You don’t need to learn an entirely new (*) syntax <em>(unlike the switch from grunt to gulp to webpack)</em>.</li><li>You don’t need to find your packages on a different repository/website <em>(unlike the switch from bower to npm)</em>.</li><li>You don’t need to change your directory structure <em>(Yarn still uses</em><em>package.json and puts everything in the </em><em>node_modules subfolder)</em>.</li><li>…</li></ul><p><strong>For us, the end user, not much changes. Everything that was, still is. From a UX perspective that can count.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*RSIgNaeUo7CDzBb6ehi6OQ.gif" /><figcaption><em>Working with Yarn: “It’s a Unix System, I know this!”</em></figcaption></figure><p><em>(*) I know. The syntax is a tad different, but not that much: Once yarn is </em><a href="https://yarnpkg.com/en/docs/install"><em>installed</em></a><em>, just run </em><em>yarn (or </em><em>yarn install) instead of </em><em>npm install. To add a package to your </em><em>package.json run </em><em>yarn add packagename(instead of </em><em>npm i packagename --save). Slightly different indeed, but nothing big.</em></p><p>Of course I’m also excited about the initial benefits listed. Take reliability for example. Coming from a PHP background — where we have <a href="https://getcomposer.org/">Composer</a> for dependency management — I applaud the fact that Yarn — like Composer — automatically generates lock files.</p><h3>Wes Bos on Twitter</h3><p>Yarn Review so far: 👉 It&#39;s Super Fast. Like woah. 👉 Creates package.json if one doesn&#39;t exist 👉 Saves Exact versions in a .lock file</p><p>Thanks to the yarn.lock file you can no longer end up with different versions of dependencies on different machines should a new version of a dependency be released in between two runs of yarn install. The lock file, as its name indicates, locks the dependencies down to exact versions (cfr. npm shrinkwrap, but then by default and on steroids). That way you have reproducible installs, on all machines.</p><p>The magic clue behind it? Whenever you run yarn install, the yarn.lockfile has precedence over the package.json.</p><ul><li>If the yarn.lock file exists, the (exact) versions defined in it will be used.</li><li>If no yarn.lock exists, the (loosely defined) versions defined inpackage.json will be used, and a yarn.lock is generated.</li></ul><p>That way you, as a developer, have true control over which exact versions will be installed on every machine. As long as you commit your yarn.lock file into Git <em>(or whatever VCS floats your boat)</em> of course.</p><p>Let me rephrase and repeat that for you, as it’s really important: <strong>you must commit the </strong><strong>yarn.lock file into Git</strong>.</p><p>To update the versions locked in the yarn.lock file <a href="https://yarnpkg.com/en/docs/cli/upgrade">run </a><a href="https://yarnpkg.com/en/docs/cli/upgrade">yarn upgrade</a>. After having verified that your project <em>Works On My Machine</em>™, it’s safe to commit the updated yarn.lock file into Git.</p><p>Oh, and about the aforementioned speed benefit (thanks to parallelization and the use of a global cache on disk), let this tweet convince you:</p><h3>Sebastian【ツ】 on Twitter</h3><p>NPM install: 2m23s, Yarn first install: 40s, yarn second install: 18s 🚀</p><p>So, what are you waiting for?</p><p><a href="https://code.facebook.com/posts/1840075619545360">Facebook Engineering Blog: Yarn: A new package manager for JavaScript →</a><br><a href="https://yarnpkg.com/">Yarn — Fast, reliable, and secure dependency management →</a></p><p><em>This is a blogpost which first appeared on my blog at </em><a href="https://www.bram.us/2016/10/11/why-im-excited-about-yarn/"><em>https://www.bram.us/2016/10/11/why-im-excited-about-yarn/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75037a198bef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>