<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>tinytip</title><description>tinytip is a collection of small tips &amp; tricks for developers.</description><link>https://tinytip.co/</link><item><title>XState Actors are observables</title><link>https://tinytip.co/tips/xstate-actor-observable/</link><guid isPermaLink="true">https://tinytip.co/tips/xstate-actor-observable/</guid><pubDate>Sun, 03 Aug 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Actors in XState implement an RxJS-compatible Observable interface.
Instead of directly subscribing to the actor, you can use RxJS &lt;code&gt;from()&lt;/code&gt;:&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Create the actor (also works with `fromPromise`, ...)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; machine&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; setup&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;createMachine&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; actor&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; createActor&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(machine).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Subscribe to it, the normal way&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;actor.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;snapshot&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(snapshot));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Subscribe to it using RxJS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(actor).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;snapshot&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(snapshot));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now that’s not much of a difference. But it gets more powerful
when you use operators to transform and filter the snapshot, or combine it with other observables.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(actor)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;pipe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    startWith&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(actor.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getSnapshot&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    map&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;snapshot&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; snapshot.context.value),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    filter&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; checkValue&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    distinctUntilChanged&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>rxjs</category><category>javascript</category></item><item><title>Vitest&apos;s describe() accepts strings, functions and classes</title><link>https://tinytip.co/tips/vitest-describe-fn/</link><guid isPermaLink="true">https://tinytip.co/tips/vitest-describe-fn/</guid><pubDate>Sat, 12 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Vitest’s &lt;code&gt;describe()&lt;/code&gt; function is commonly used with a string to label a test group, like this:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;myFunction&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should return true&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    expect&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;myFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toBe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Did you know you can also pass a &lt;strong&gt;class or function&lt;/strong&gt; instead of a string to &lt;code&gt;describe()&lt;/code&gt;? Vitest won’t execute the function but will use its name as the label for the test group.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;//       ↓ Pass a function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(myFunction, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should return true&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    expect&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;myFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toBe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This approach works well with React components too (since they are just functions):&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(Greeting, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should render correctly&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    render&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Greeting&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    expect&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(screen.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getByText&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;Hello World&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toBeInTheDocument&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>testing</category></item><item><title>Backreference in RegEx allows matching the same text as a previous capturing group</title><link>https://tinytip.co/tips/regex-backreference/</link><guid isPermaLink="true">https://tinytip.co/tips/regex-backreference/</guid><pubDate>Thu, 19 Dec 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A capturing group &lt;code&gt;(...)&lt;/code&gt; groups a subpattern. For example, &lt;code&gt;([A-Z]\d)&lt;/code&gt; matches a letter followed by a digit, like “A1”.
A backreference, denoted by &lt;code&gt;\1&lt;/code&gt;, &lt;code&gt;\2&lt;/code&gt;, etc., refers to a previous capturing group and matches the same text as that group.&lt;/p&gt;
&lt;p&gt;For instance, in the pattern &lt;code&gt;([A-Z]\d)\1&lt;/code&gt;, &lt;code&gt;\1&lt;/code&gt; refers to the first capturing group &lt;code&gt;([A-Z]\d)&lt;/code&gt;, ensuring that the same letter-digit combination is repeated.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; pattern&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; /(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;[A-Z]\d&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;\1&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;pattern.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;A1A1&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;pattern.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;A1B1&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can also use a backreference with quantifiers:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; pattern&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; /(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;\d&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;\1{2}&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;pattern.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;111&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;pattern.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;122&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Inspect your ESLint Flat Config</title><link>https://tinytip.co/tips/eslint-inspect-config/</link><guid isPermaLink="true">https://tinytip.co/tips/eslint-inspect-config/</guid><pubDate>Wed, 18 Dec 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The ESLint Config Inspector allows you to examine your flat configuration.
It displays the rules you have set up and the files to which they apply.
Use the following command to inspect your configuration:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;eslint&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; --inspect-config&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Naming your config objects will help you easily identify them when using the inspector:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// eslint.config.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; default&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    name: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;common&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// &amp;lt;-- Define a name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    rules: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;      &quot;no-console&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    name: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;react&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// &amp;lt;-- Define a name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    plugin: { react },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    rules: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;      &quot;react/jsx-boolean-value&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>tooling</category></item><item><title>Get translated display names with Intl.DisplayNames</title><link>https://tinytip.co/tips/js-intl-display-names/</link><guid isPermaLink="true">https://tinytip.co/tips/js-intl-display-names/</guid><pubDate>Tue, 23 Apr 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When developing features such as a country selector, a currency picker, or a language switcher, you often need to display the names of countries, currencies, and languages translated into the user’s language. JavaScript’s &lt;code&gt;Intl.DisplayNames&lt;/code&gt; object is a handy tool for this purpose.&lt;/p&gt;
&lt;p&gt;To use &lt;code&gt;Intl.DisplayNames&lt;/code&gt;, create a new instance by specifying the user’s current language and the type of display names you need. Then, retrieve the translated display name using the &lt;code&gt;of()&lt;/code&gt; method. In the following example, we generate the display name for the US region in both English and German.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; regionEnglish&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Intl.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;DisplayNames&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { type: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;region&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;regionEnglish.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;US&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// United States&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; regionGerman&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Intl.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;DisplayNames&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;de&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { type: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;region&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;regionGerman.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;US&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Vereinigte Staaten&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;By altering the &lt;code&gt;type&lt;/code&gt; parameter in the &lt;code&gt;Intl.DisplayNames&lt;/code&gt; constructor, you can retrieve display names for different categories such as languages or currencies.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; lang&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Intl.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;DisplayNames&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { type: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;language&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;lang.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;en-US&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// American English&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;lang.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;fr&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// French&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; currency&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Intl.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;DisplayNames&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;en&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { type: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;currency&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;currency.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;USD&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// US Dollar&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>React Context without default value</title><link>https://tinytip.co/tips/react-required-context/</link><guid isPermaLink="true">https://tinytip.co/tips/react-required-context/</guid><pubDate>Thu, 18 Apr 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Creating a React Context using &lt;code&gt;createContext()&lt;/code&gt; requires a default value. If you cannot provide a useful default value, you have to make the context nullable and then, when using the context value, verify that it is not &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;tsx&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; createContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;User&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; useUser&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; useContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(context);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; null&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;throw&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Error&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;UserContext not provided&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Instead of repeating this boilerplate code every time, you can move this logic into a small utility function:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;tsx&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Represents our empty value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; EMPTY&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Symbol&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; createRequiredContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;()&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Provider&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;] {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Context, initialized with EMPTY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; context&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; createContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; typeof&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; EMPTY&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;EMPTY&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Provider with EMPTY excluded (only T values are allowed)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; Provider&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; context.Provider &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Provider&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Hook that throws an error if the value is EMPTY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; useStrictContext&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; useContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(context);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; EMPTY&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    throw&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Error&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;Missing context provider&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [Provider, useStrictContext];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In our approach, we utilize a unique symbol, denoted as &lt;code&gt;EMPTY&lt;/code&gt;, to differentiate between a default value and an actual value. This strategy provides the flexibility to create nullable contexts when necessary. You can then call the &lt;code&gt;createRequiredContext&lt;/code&gt; function to create a new context:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;tsx&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;UserProvider&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;useUser&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; createRequiredContext&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;User&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>react</category></item><item><title>Replace any with generics, not with unknown (in many cases)</title><link>https://tinytip.co/tips/ts-replace-any/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-replace-any/</guid><pubDate>Sun, 25 Feb 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You sure know that &lt;code&gt;any&lt;/code&gt; in TypeScript is bad and should be avoided. But what should you replace it with?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When the type is unknown throughout the application&lt;/strong&gt;: If the type is unknown in the entire application, such as when receiving data from an untrusted third-party API, the &lt;code&gt;unknown&lt;/code&gt; type is your best choice. It’s the type-safe counterpart of &lt;code&gt;any&lt;/code&gt; and informs TypeScript that the type is unknown until you validate it at runtime. You can validate the type using methods like &lt;code&gt;Array.isArray()&lt;/code&gt; or the &lt;code&gt;typeof&lt;/code&gt; operator:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; foo&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; unknown&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (Array.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;isArray&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    // We know it&apos;s an array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;Number of items: &quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;string&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    // We know it&apos;s a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toLowerCase&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;When the type is unknown in a specific context&lt;/strong&gt;: Sometimes, your type might be unknown in one part of the application (where you don’t care about the type) but known in another part. If you try to replace &lt;code&gt;any&lt;/code&gt; with &lt;code&gt;unknown&lt;/code&gt; in this case, you will likely encounter errors.&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; addValidationFn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; ((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; unknown&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; Doesn&apos;t work, you will get: Type &apos;unknown&apos; is not assignable to type &apos;number&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addValidationFn&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; number&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this case, TypeScript is correct. Inside &lt;code&gt;addValidationFn&lt;/code&gt;, you could call the provided function with any value because you’ve specified that the type is unknown, and any value is assignable to &lt;code&gt;unknown&lt;/code&gt;. Therefore, providing a function that expects a number is not valid.&lt;/p&gt;
&lt;p&gt;In such scenarios, you should use generics:&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; addValidationFn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; ((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; V&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; This works&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addValidationFn&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; number&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Generics allow you to capture the type information while maintaining type safety. In the above example, &lt;code&gt;V&lt;/code&gt; is a placeholder for any type, and it will be determined when &lt;code&gt;addValidationFn&lt;/code&gt; is called.&lt;/p&gt;
</content:encoded><category>typescript</category></item><item><title>Show DOM nodes in React DevTools</title><link>https://tinytip.co/tips/react-devtools-nodes/</link><guid isPermaLink="true">https://tinytip.co/tips/react-devtools-nodes/</guid><pubDate>Sat, 14 Oct 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;a href=&quot;https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi&quot;&gt;React Developer Tools&lt;/a&gt; extension for your browser allows you to inspect
your React application and see the component tree. By default, the components tree
only renders your React components but not the DOM nodes. However, you can change
the default filter and show DOM nodes as well.&lt;/p&gt;
&lt;p&gt;Follow these steps to show DOM nodes in the components tree:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 3236px) 3236px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;3236&quot; height=&quot;828&quot; src=&quot;https://tinytip.co/_astro/react-devtools-nodes._93V3svj_Z6bh4c.webp&quot; srcset=&quot;https://tinytip.co/_astro/react-devtools-nodes._93V3svj_1gzYP8.webp 640w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_Z2g4pVM.webp 750w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_1EIIWM.webp 828w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_Z1WCIbu.webp 1080w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_15kK8.webp 1280w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_1MQEU9.webp 1668w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_aT57K.webp 2048w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_2mprLG.webp 2560w, https://tinytip.co/_astro/react-devtools-nodes._93V3svj_Z6bh4c.webp 3236w&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate the React &lt;em&gt;Components&lt;/em&gt; tab in the DevTools&lt;/li&gt;
&lt;li&gt;Click on the settings icon in the top right corner of the tree panel&lt;/li&gt;
&lt;li&gt;Navigate to the &lt;em&gt;Components&lt;/em&gt; tab in the settings overlay&lt;/li&gt;
&lt;li&gt;Disable the toggle in the &lt;em&gt;Hide components where…&lt;/em&gt; section.&lt;/li&gt;
&lt;/ol&gt;
</content:encoded><category>react</category></item><item><title>Query selectors are applied to the whole document, unless you use :scope</title><link>https://tinytip.co/tips/js-query-selector-scope/</link><guid isPermaLink="true">https://tinytip.co/tips/js-query-selector-scope/</guid><pubDate>Mon, 03 Jul 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Here’s a quiz for you: Given the HTML below, what element will be returned by the &lt;code&gt;querySelector()&lt;/code&gt; call?
Note that the &lt;code&gt;.wrapper&lt;/code&gt; is outside the &lt;code&gt;.main&lt;/code&gt; element.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;wrapper&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;main&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;.main&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; content&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; main.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;.wrapper .content&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// What&apos;s the result???&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Don’t cheat! Think about it for a second.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;If you call &lt;code&gt;querySelector()&lt;/code&gt; or &lt;code&gt;querySelectorAll()&lt;/code&gt; on an element, you will only get elements within that element.
However, the query itself will be applied to the whole document. So the above code will return the &lt;code&gt;&amp;lt;div class=&quot;content&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; node.&lt;/p&gt;
&lt;p&gt;You can include the &lt;code&gt;:scope&lt;/code&gt; pseudo-class to apply the query to the element itself:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;.main&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; content&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; main.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;:scope .wrapper .content&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Result: null&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is also useful to query direct children of an element:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;.main&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; content&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; main.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;:scope &amp;gt; .child&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// --&amp;gt; Does not include nested .child elements&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Scope your CSS imports with meta.load-css in Sass</title><link>https://tinytip.co/tips/scss-load-css/</link><guid isPermaLink="true">https://tinytip.co/tips/scss-load-css/</guid><pubDate>Tue, 27 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In contrast to the old &lt;code&gt;@import&lt;/code&gt; rule to import SCSS files in Sass, the newer &lt;code&gt;@use&lt;/code&gt; rule can only be used at the top level of a file,
before any other statements. Using it inside a CSS selector is not allowed. For example:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Works&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  @import&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;./dark-theme.scss&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Does NOT work&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  @use&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;./dark-theme.scss&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But there is still a way for scoped imports.
The &lt;a href=&quot;https://sass-lang.com/documentation/modules/meta#load-css&quot;&gt;&lt;code&gt;meta.load-css&lt;/code&gt;&lt;/a&gt; function allows you to
import a SCSS file inside a CSS selector and scope it to that selector:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;@use&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;sass:meta&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  @include&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt; meta&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;load-css&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;./dark-theme.scss&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Unlike &lt;code&gt;@import&lt;/code&gt;, &lt;code&gt;meta.load-css&lt;/code&gt; does not affect the parent selector &lt;code&gt;&amp;amp;&lt;/code&gt; in the imported file.
Given the following file:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// dark-theme.scss&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;  &amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; + &lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;    margin-inline-start&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;rem&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Importing it with &lt;code&gt;@import&lt;/code&gt; would result in a CSS selector that is technically valid but likely not what you want:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Using @import results in:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt; button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; + &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt; button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  margin-inline-start&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;rem&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Using &lt;code&gt;meta.load-css&lt;/code&gt; however does not break the parent selector:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Using meta.load-css results in:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt; button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; + &lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  margin-inline-start&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;rem&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>css</category></item><item><title>Get IANA timezone of user</title><link>https://tinytip.co/tips/js-timezone/</link><guid isPermaLink="true">https://tinytip.co/tips/js-timezone/</guid><pubDate>Tue, 27 Jun 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you ever have to work with timezones in JavaScript, you can use &lt;code&gt;Intl.DateTimeFormat&lt;/code&gt; to get the IANA timezone of the user:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; timeZone&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Intl.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;DateTimeFormat&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;().&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;resolvedOptions&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;().timeZone;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Result: &quot;Europe/Zurich&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Custom hooks should return named tuples and not use &quot;as const&quot;</title><link>https://tinytip.co/tips/react-hook-tuple/</link><guid isPermaLink="true">https://tinytip.co/tips/react-hook-tuple/</guid><pubDate>Sun, 19 Mar 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you create a custom hook in React that returns a tuple, like &lt;code&gt;setState&lt;/code&gt; does, you must tell TypeScript that you are returning a tuple and not just an array of arbitrary length. For example, the following code will not work:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; usePromise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Promise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [value, isReady];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;TypeScript will tell you that the return type of the hook is &lt;code&gt;(T | boolean)[]&lt;/code&gt;. To make the return value type-safe, you can use &lt;code&gt;as const&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; usePromise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Promise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [value, isReady] &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The return type is now &lt;code&gt;readonly [T, boolean]&lt;/code&gt;. However, as a consumer of the hook you don’t know what these values mean. What’s that &lt;code&gt;boolean&lt;/code&gt; value? Does it indicate if the promise is ready or if it failed? You can solve this by explicitly defining the return value and giving the tuple items a name:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; usePromise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Promise&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;)&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;isReady&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;] {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [value, isReady];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, the return type is &lt;code&gt;[value: T, isReady: boolean]&lt;/code&gt; and the consumer of the hook knows what the values mean.&lt;/p&gt;
</content:encoded><category>react</category><category>typescript</category></item><item><title>Find previous commands in the terminal</title><link>https://tinytip.co/tips/terminal-search-commands/</link><guid isPermaLink="true">https://tinytip.co/tips/terminal-search-commands/</guid><pubDate>Thu, 19 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you want to rerun a previously executed command in the terminal, you can use the up and down arrow keys to navigate through the history of commands. If you want to search for a specific command, press &lt;code&gt;Ctrl + R&lt;/code&gt; and start typing. The terminal will search through the history and show you the latest matching command. Press &lt;code&gt;Ctrl + R&lt;/code&gt; again to search for older commands.&lt;/p&gt;
</content:encoded><category>terminal</category></item><item><title>Create QR codes in Chrome to send URLs to your smartphone</title><link>https://tinytip.co/tips/chrome-qr-code/</link><guid isPermaLink="true">https://tinytip.co/tips/chrome-qr-code/</guid><pubDate>Thu, 19 Jan 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you want to open a website on your smartphone, i.e. to test it on a mobile device, you can use the sharing feature of Chrome to create a QR code that you can scan with your smartphone. Click on the share icon in the address bar and select “Create QR Code”. Then scan the QR code with the camera app of your smartphone to open the website.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Generate QR code in Chrome&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2202px) 2202px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2202&quot; height=&quot;1802&quot; src=&quot;https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_Z28P1U.webp&quot; srcset=&quot;https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_20I33i.webp 640w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_Z1pxPU6.webp 750w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_1820cb.webp 828w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_ZS61M3.webp 1080w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_Z2ucSKs.webp 1280w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_Z1WeSSI.webp 1668w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_M4oc3.webp 2048w, https://tinytip.co/_astro/chrome-qr-code.BjiyYY6o_Z28P1U.webp 2202w&quot;&gt;&lt;/p&gt;
</content:encoded><category>devtools</category></item><item><title>Find the gitignore rule that excludes a file from git</title><link>https://tinytip.co/tips/git-check-ignore-rule/</link><guid isPermaLink="true">https://tinytip.co/tips/git-check-ignore-rule/</guid><pubDate>Thu, 27 Oct 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When a file is ignored by git you can use the &lt;code&gt;check-ignore&lt;/code&gt; command which shows you why the file is ignored. This is useful if you have multiple &lt;code&gt;.gitignore&lt;/code&gt; files or some complex patterns in your rules.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; check-ignore&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; -v&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; path/to/a/file.png&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>git</category></item><item><title>Empty Cache and Hard Reload in Chrome</title><link>https://tinytip.co/tips/chrome-hard-reload/</link><guid isPermaLink="true">https://tinytip.co/tips/chrome-hard-reload/</guid><pubDate>Thu, 27 Oct 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;We all know cache invalidation is hard. If you experience some cache problems while working on a web project in Chrome you can empty the cache and do a hard reload. Just open the DevTools, right click (or long press) on the reload icon in the toolbar and choose “Empty Cache and Hard Reload”:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Empty cache and Hard Reload in Chrome&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1942px) 1942px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1942&quot; height=&quot;1574&quot; src=&quot;https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_Zyfk95.webp&quot; srcset=&quot;https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_ZK7etr.webp 640w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_ZWsGO.webp 750w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_C1QpU.webp 828w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_Z1W9loS.webp 1080w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_44vDI.webp 1280w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_Z1S5qNl.webp 1668w, https://tinytip.co/_astro/chrome-hard-reload.BamcQC_l_Zyfk95.webp 1942w&quot;&gt;&lt;/p&gt;
</content:encoded><category>devtools</category></item><item><title>Search &amp; replace with RegEx groups in VS Code</title><link>https://tinytip.co/tips/vscode-search-regex-groups/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-search-regex-groups/</guid><pubDate>Thu, 22 Sep 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The search &amp;amp; replace feature in VS Code cannot just search for static strings but accepts RegEx patterns.
Just click on the &lt;code&gt;.*&lt;/code&gt; icon in the search input to enable RegEx search.&lt;/p&gt;
&lt;p&gt;For the replace pattern you can reference a RegEx group by using “$” and the index of the group.
&lt;code&gt;$0&lt;/code&gt; references the entire match, &lt;code&gt;$1&lt;/code&gt; references the first group, &lt;code&gt;$2&lt;/code&gt; the second group and so on.&lt;/p&gt;
&lt;p&gt;Let’s make an example: The search pattern &lt;code&gt;Hello (\S+)&lt;/code&gt; will find strings like “Hello John”.
The group &lt;code&gt;(\S+)&lt;/code&gt; captures the name (here “John”) which can be referenced in the replace pattern using &lt;code&gt;$1&lt;/code&gt;.
With the replace pattern &lt;code&gt;Hi $1!&lt;/code&gt; we’ll get the following results:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;diff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B31D28&quot;&gt;&lt;span style=&quot;user-select: none;&quot;&gt;-&lt;/span&gt; Hello John&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;&lt;span style=&quot;user-select: none;&quot;&gt;+&lt;/span&gt; Hi John!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B31D28&quot;&gt;&lt;span style=&quot;user-select: none;&quot;&gt;-&lt;/span&gt; Hello Jane&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;&lt;span style=&quot;user-select: none;&quot;&gt;+&lt;/span&gt; Hi Jane!&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>vscode</category></item><item><title>Let VoiceOver on iOS read a split element as a single element with the text role</title><link>https://tinytip.co/tips/a11y-voiceover-text-role/</link><guid isPermaLink="true">https://tinytip.co/tips/a11y-voiceover-text-role/</guid><pubDate>Thu, 22 Sep 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;VoiceOver on iOS reads each element individually when a user swipes across the screen.
If an element like a link is composed of several span elements, VoiceOver will not read the entire link text but only the text of the active span element (the one that the user has swiped on). Buttons are an exception - VoiceOver will read all child elements at once.&lt;/p&gt;
&lt;p&gt;For cases where you want VoiceOver to read the whole text at once you can use the unofficial role &lt;code&gt;text&lt;/code&gt;
which causes VoiceOver to read the split element as one element. Note that this role is not an official role
but just used by VoiceOver. In addition, the role should not be placed on the &lt;code&gt;a&lt;/code&gt; tag directly but on a child element
because it would overwrite the implicit &lt;code&gt;link&lt;/code&gt; role of the &lt;code&gt;a&lt;/code&gt; tag.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; href&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;https://tinytip.co&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  &amp;lt;!-- Let VoiceOver on iOS read the entire link text at once --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; role&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;text&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;tinytip&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;material-icons&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; aria-label&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;(external)&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;open_in_new&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>a11y</category><category>html</category></item><item><title>VoiceOver reads the title of external SVGs even if the alt text is empty</title><link>https://tinytip.co/tips/a11y-voiceover-svg-title/</link><guid isPermaLink="true">https://tinytip.co/tips/a11y-voiceover-svg-title/</guid><pubDate>Thu, 22 Sep 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;For accessibility reasons every image on a page should have an &lt;code&gt;alt&lt;/code&gt; attribute with a description of the image or, for decorative images,
with an empty value. Images with an empty alt text will be ignored by screen readers.&lt;/p&gt;
&lt;p&gt;However, there is one exception. If the &lt;code&gt;src&lt;/code&gt; attribute points to an SVG file that has a &lt;code&gt;title&lt;/code&gt; tag,
VoiceOver (on macOS and iOS) will read the title and not ignore the image.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;circle.svg&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; alt&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;xml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- /circle.svg --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;DOCTYPE&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; svg&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; PUBLIC &quot;-//W3C//DTD SVG 1.1//EN&quot; &quot;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;svg&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; viewBox&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;0 0 20 10&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; xmlns&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;http://www.w3.org/2000/svg&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;circle&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; cx&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;5&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; cy&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;5&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;5&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    &amp;lt;!-- SVG image with a title tag --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;Circle&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;circle&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;svg&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the example above VoiceOver will read “&lt;em&gt;Circle, image&lt;/em&gt;”, while other screen readers like NVDA will ignore the image.&lt;/p&gt;
&lt;p&gt;SVG files generated via design tools like Sketch often include a title.
The title may be useless (like a description of a decorative icon) or even absolute nonsense (like an auto-generated UUID) and could also be in the wrong language, resulting in a confusing experience for screen reader users.&lt;/p&gt;
&lt;p&gt;Either make sure that your images don’t include a &lt;code&gt;title&lt;/code&gt; tag or use the &lt;code&gt;aria-hidden&lt;/code&gt; attribute to hide the image:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;circle.svg&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; alt&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; aria-hidden&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>a11y</category></item><item><title>RxJS combineLatest() accepts a selector function</title><link>https://tinytip.co/tips/rxjs-combinelatest-selector/</link><guid isPermaLink="true">https://tinytip.co/tips/rxjs-combinelatest-selector/</guid><pubDate>Tue, 12 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The RxJS function &lt;code&gt;combineLatest()&lt;/code&gt; accepts a selector function as last parameter.
This selector function receives the latest value of each observable as argument and can be used to return a new value that will be emitted.&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;combineLatest&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Array of observables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  [stream1$, stream2$, stream3$],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Selector function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;val1&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;val2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;val3&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; val1 &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; val2 &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; val3 &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Return value will be emitted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>rxjs</category></item><item><title>Import Markdown files in your Storybook MDX docs</title><link>https://tinytip.co/tips/storybook-import-markdown/</link><guid isPermaLink="true">https://tinytip.co/tips/storybook-import-markdown/</guid><pubDate>Thu, 23 Jun 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Storybook allows you to import existing Markdown files your MDX docs.
You just need configure the &lt;code&gt;transcludeMarkdown&lt;/code&gt; option in your storybook config:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// .storybook/main.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;exports&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  addons: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      name: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;@storybook/addon-docs&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      options: { transcludeMarkdown: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then you can import your Markdown file in your MDX file and render it as a component:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;md&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;import Example from &quot;./Example.md&quot;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5;font-weight:bold&quot;&gt;# Hello World&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;Example /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>tooling</category></item><item><title>Use @at-root in SCSS to break out of nesting</title><link>https://tinytip.co/tips/scss-at-root/</link><guid isPermaLink="true">https://tinytip.co/tips/scss-at-root/</guid><pubDate>Thu, 23 Jun 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In SCSS, selectors can be deeply nested. In some situations you may want to break out of the current selector hierarchy and emit some styles at the root of the document. SCSS provides the &lt;code&gt;@at-root&lt;/code&gt; rule for this use case:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;scss&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* styles.scss */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;@mixin&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; some-mixin&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;black&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  @at-root&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; body&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;    background&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;lightgray&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.some-class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  @include&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; some-mixin&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will move &lt;code&gt;body&lt;/code&gt; out of the parent selector:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* styles.css */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.some-class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;black&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  background-color&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;lightgray&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>css</category></item><item><title>Create collections from folders in Eleventy</title><link>https://tinytip.co/tips/eleventy-collection-by-glob/</link><guid isPermaLink="true">https://tinytip.co/tips/eleventy-collection-by-glob/</guid><pubDate>Thu, 23 Jun 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you want to create a collection from a folder in your Eleventy project, like a collection of blog posts in the &lt;em&gt;posts&lt;/em&gt; folder, you could manually add a &lt;em&gt;post&lt;/em&gt; tag to every post. But there is an easier way.&lt;/p&gt;
&lt;p&gt;The Collection API in Eleventy lets you filter your pages by glob patterns:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;exports&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;eleventyConfig&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  eleventyConfig.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addCollection&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;posts&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;collectionApi&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; collectionApi.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getFilteredByGlob&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;posts/*.md&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will create a collection “posts” that contains all the markdown files in the &lt;code&gt;posts&lt;/code&gt; folder.&lt;/p&gt;
</content:encoded><category>tooling</category></item><item><title>Type-safe factory deps in Angular with inject()</title><link>https://tinytip.co/tips/angular-inject-factory-providers/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-inject-factory-providers/</guid><pubDate>Sun, 05 Jun 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A factory function provider in Angular can have dependencies using the &lt;code&gt;deps&lt;/code&gt; property.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;NgModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  providers: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      provide: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;SOME_INJECTION_TOKEN&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      deps: [MyService],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;      useFactory&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;myService&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; myService&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; myService.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someMethod&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; MyModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The problem is that you need to write the dependencies twice: once for the &lt;code&gt;deps&lt;/code&gt; property and once as arguments of the &lt;code&gt;useFactory&lt;/code&gt; function. Thanks to the new &lt;code&gt;inject()&lt;/code&gt; function in Angular 14 there is now a better way to inject dependencies.&lt;/p&gt;
&lt;p&gt;Call the &lt;code&gt;inject()&lt;/code&gt; function and pass your dependency (here &lt;code&gt;MyService&lt;/code&gt;) as argument.
It will provide you the dependency and the return value is type-safe.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { inject } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;@angular/core&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;NgModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  providers: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      provide: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;SOME_INJECTION_TOKEN&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;      useFactory&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;        const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; myService&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; inject&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(MyService);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; myService.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someMethod&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;        // Or as a one-liner:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;        // return inject(MyService).someMethod();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; MyModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category></item><item><title>Switch to the previous git branch with git switch</title><link>https://tinytip.co/tips/git-switch-prev-branch/</link><guid isPermaLink="true">https://tinytip.co/tips/git-switch-prev-branch/</guid><pubDate>Tue, 31 May 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;After switching to another branch, you can use the &lt;code&gt;git switch -&lt;/code&gt; command to switch back to the previous branch without having to reenter the name:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Feature branch is active&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; branch&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; --show-current&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;feature/some-feature&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Switch to another branch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; switch&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Do some work ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Switch back to &quot;feature/some-feature&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; switch&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; -&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>git</category></item><item><title>Inject the unique app id of your Angular app</title><link>https://tinytip.co/tips/angular-app-id/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-app-id/</guid><pubDate>Tue, 31 May 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Angular generates a unique id for your app which is available via &lt;code&gt;APP_ID&lt;/code&gt; injection token. This is useful if you are in a micro-frontend with multiple Angular apps on the same page and you need a unique value.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { APP_ID } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;@angular/core&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; MyComponent&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  constructor&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(@&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Inject&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;APP_ID&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt; appId&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;App id:&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, appId); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Example: &quot;pvu&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Angular uses the app id for prefixing your CSS selectors when using &lt;code&gt;ViewEncapsulation.Emulated&lt;/code&gt;.
You can define your own id by providing the token as a provider in your app module:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ts&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { APP_ID } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;@angular/core&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;NgModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  providers: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      provide: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;APP_ID&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;      useValue: &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;42&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; AppModule&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category></item><item><title>Eleventy supports Nunjucks globals</title><link>https://tinytip.co/tips/eleventy-njk-globals/</link><guid isPermaLink="true">https://tinytip.co/tips/eleventy-njk-globals/</guid><pubDate>Thu, 21 Apr 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Eleventy v1.0.0 (and above) supports Nunjucks globals.
This lets you register a global value or function that is available
in all Nunjucks templates.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;exports&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (eleventyConfig) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Register two globals, a static value and a function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  eleventyConfig.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addNunjucksGlobal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;Hello World&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  eleventyConfig.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addNunjucksGlobal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;greeting&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `Hello ${&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now you can use &lt;code&gt;{{ message }}&lt;/code&gt; and &lt;code&gt;{{ greeting(&apos;John&apos;) }}&lt;/code&gt; in your Nunjucks templates.&lt;/p&gt;
&lt;p&gt;A more useful example is a global function that generates a unique id. You may need this if you want to connect a label with its input or for &lt;code&gt;aria-labelledby&lt;/code&gt; and &lt;code&gt;aria-describedby&lt;/code&gt;. Here I use the &lt;a href=&quot;https://www.npmjs.com/package/nanoid&quot;&gt;nanoid package&lt;/a&gt; to generate the id:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;nanoid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; require&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;nanoid&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;exports&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;eleventyConfig&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  eleventyConfig.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addNunjucksGlobal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;nanoid&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; nanoid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now you can create a new unique id, assign it to a local variable and use it to connect two HTML elements:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;liquid&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;{% &lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; id = nanoid() %}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;article&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; aria-labelledby&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;{{ &lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; }}&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;{{ &lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; }}&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;article&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the example above we connect the &lt;code&gt;h2&lt;/code&gt; with the &lt;code&gt;article&lt;/code&gt; element using &lt;code&gt;aria-labelledby&lt;/code&gt;.&lt;/p&gt;
</content:encoded><category>tooling</category></item><item><title>Named lines in CSS grid</title><link>https://tinytip.co/tips/css-grid-line-name/</link><guid isPermaLink="true">https://tinytip.co/tips/css-grid-line-name/</guid><pubDate>Wed, 20 Apr 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When creating a CSS grid with &lt;code&gt;grid-template-columns&lt;/code&gt; you can give your grid lines a name using the square brackets syntax &lt;code&gt;[name]&lt;/code&gt;. Child elements can be positioned using this name.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.grid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  display&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;grid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Lines named &quot;firstline&quot;, &quot;secondline&quot; and &quot;thirdline&quot; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Last line has no name */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  grid-template-columns&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: [firstline] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [secondline] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [thirdline] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.child&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Use the line name to set the position */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  grid-column&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: secondline;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A line can have multiple names by separating them with a space:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.grid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  grid-template-columns&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: [someline] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [somename anothername thirdname] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And using &lt;code&gt;-start&lt;/code&gt; and &lt;code&gt;-end&lt;/code&gt; suffixes you can let a line name span over multiple columns.
In the example below &lt;code&gt;left&lt;/code&gt; spans over the first two columns, &lt;code&gt;center&lt;/code&gt; is used for the column in the middle and &lt;code&gt;right&lt;/code&gt; spans over the last two columns.&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.grid&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  grid-template-columns&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    [left-start] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    [right-start &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;center&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    [left-end] &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [right-end];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.cell-left&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;   { &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;grid-column&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;left&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;; }   &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* 1fr + 2fr */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.cell-center&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;grid-column&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;center&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;; } &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* 2fr */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.cell-right&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  { &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;grid-column&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;right&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;; }  &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* 2fr + 1fr */&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And here is how this looks like:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Visualization of the CSS grid with named columns example.&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2106px) 2106px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2106&quot; height=&quot;1382&quot; src=&quot;https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_ZIeMlO.webp&quot; srcset=&quot;https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_1gOnTL.webp 640w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_Z1JHznu.webp 750w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_Z1IgdSC.webp 828w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_Z1vXczh.webp 1080w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_ZJbRHV.webp 1280w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_ZV9g7x.webp 1668w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_pDDVy.webp 2048w, https://tinytip.co/_astro/css-grid-line-name.tcZftUnO_ZIeMlO.webp 2106w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Your child elements don’t need to know the exact number of columns anymore and can instead use the line name.
And if your grid is responsive and changes the number of columns dynamically, your child elements will still be positioned correctly without an additional media query to update &lt;code&gt;grid-column&lt;/code&gt;.&lt;/p&gt;
</content:encoded><category>css</category></item><item><title>React function component without children in TypeScript</title><link>https://tinytip.co/tips/react-vfc/</link><guid isPermaLink="true">https://tinytip.co/tips/react-vfc/</guid><pubDate>Sat, 26 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Beginning with React 18 you don’t need the &lt;code&gt;VFC&lt;/code&gt; or &lt;code&gt;VoidFunctionComponent&lt;/code&gt; interfaces anymore. The &lt;code&gt;children&lt;/code&gt; property has been removed from the &lt;code&gt;FC&lt;/code&gt; and &lt;code&gt;FunctionComponent&lt;/code&gt; interfaces.&lt;/p&gt;
&lt;p&gt;If you create a function component in React using TypeScript, there’s the &lt;code&gt;FC&lt;/code&gt; or &lt;code&gt;FunctionComponent&lt;/code&gt; interface that you can use to define the type of your component. The interface automatically adds the &lt;code&gt;children&lt;/code&gt; property to let the parent component pass child elements to your component.&lt;/p&gt;
&lt;p&gt;If your component does not accept children, you can use the &lt;code&gt;VCF&lt;/code&gt; or &lt;code&gt;VoidFunctionComponent&lt;/code&gt; interface instead. It does not add the &lt;code&gt;children&lt;/code&gt; property.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { FC, VFC } &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;react&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; interface&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Props&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  msg&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; MyCompWithChildren&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; FC&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Props&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;props&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; const&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; MyCompWithoutChildren&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; VFC&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Props&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;props&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>react</category><category>typescript</category></item><item><title>Run the same test with different data in Jest</title><link>https://tinytip.co/tips/jest-test-each/</link><guid isPermaLink="true">https://tinytip.co/tips/jest-test-each/</guid><pubDate>Tue, 15 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you write a test in Jest and you want to run it with different data, you can use the &lt;code&gt;test.each&lt;/code&gt; function.
The function accepts a data table, which is an array of arrays with the arguments that are passed to the actual test function.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; table&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  [&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;test.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(table)(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;converts %s to %d&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;expected&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Will be called 3 times with &quot;one&quot;, &quot;two&quot;, &quot;three&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; result&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; convertToNumber&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(str);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  expect&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(result).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toBe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(expected);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The title of the test can inject parameters with &lt;code&gt;printf&lt;/code&gt; formatting (like &lt;code&gt;%s&lt;/code&gt; for a string and &lt;code&gt;%d&lt;/code&gt; for a number).&lt;/p&gt;
&lt;p&gt;Read more about this in the &lt;a href=&quot;https://jestjs.io/docs/api#testeachtablename-fn-timeout&quot;&gt;Jest documentation&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>testing</category></item><item><title>Customize the PDF viewer when embedding a PDF</title><link>https://tinytip.co/tips/html-pdf-params/</link><guid isPermaLink="true">https://tinytip.co/tips/html-pdf-params/</guid><pubDate>Fri, 04 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you want to embed a PDF document on your website you can use an iFrame.
The browser will automatically render a PDF viewer.&lt;/p&gt;
&lt;p&gt;Google Chrome, Firefox and Safari accept some parameters to customize the viewer.
Add the parameters as part of the url fragment (after the &lt;code&gt;#&lt;/code&gt;). Multiple parameters can be separated by &lt;code&gt;&amp;amp;&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;iframe&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; src&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;/path/to/document.pdf#toolbar=0&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;iframe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The following parameters are supported:&lt;/p&gt;
&lt;div class=&quot;table-wrapper&quot;&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Support&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;toolbar&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;1&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Show or hide the toolbar&lt;/td&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;view&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;FitV&lt;/code&gt;, &lt;code&gt;FitH&lt;/code&gt;, &lt;code&gt;Fit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Change the zoom level to fit (vertical, horizontal or both)&lt;/td&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;zoom&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;number&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set a specific zoom level in % (example: 300)&lt;/td&gt;
&lt;td&gt;Chrome, FF&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;page&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;number&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set initial position to a specific page (example: 2)&lt;/td&gt;
&lt;td&gt;Chrome, FF, Safari&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;nameddest&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Set initial position to a named destination (like a heading)&lt;/td&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;search&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Search for a string in the document&lt;/td&gt;
&lt;td&gt;FF&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
</content:encoded><category>html</category></item><item><title>How to get the event target inside Shadow DOM</title><link>https://tinytip.co/tips/js-event-composed-path/</link><guid isPermaLink="true">https://tinytip.co/tips/js-event-composed-path/</guid><pubDate>Thu, 03 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The event object in JavaScript has a &lt;code&gt;target&lt;/code&gt; property which is the actual element that triggered the event. The &lt;code&gt;currentTarget&lt;/code&gt; property is the element that the event listener is attached to.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;Click Me&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;click&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;target&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, event.target); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; button&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;currentTarget&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, event.currentTarget); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; div&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works different when using Shadow DOM. When the event was triggered inside an element with Shadow DOM,
the &lt;code&gt;target&lt;/code&gt; property points the Shadow DOM element, not the element that triggered the event:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; id&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  &amp;lt;!-- Web Component with Shadow DOM --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;my-button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;Click Me&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;my-button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;click&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;target&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, event.target); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; my-button&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;currentTarget&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, event.currentTarget); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// =&amp;gt; div&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;While this is good in terms of encapsulation, there are use cases where you need the actual target.
In these cases you can use the &lt;code&gt;composedPath&lt;/code&gt; method to get the actual target:&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;container&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  .&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;click&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;path&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, event.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;composedPath&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    // =&amp;gt; [slot, button, document-fragment, my-button,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    //     div#container, body, html, document, Window]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The method returns all the elements that are in the path of the event. The first element is the one that triggered the event.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: this works only if the Shadow DOM uses encapsulation mode &lt;code&gt;open&lt;/code&gt;.&lt;/p&gt;
</content:encoded><category>javascript</category></item><item><title>Use npm ci for a clean installation of your dependencies</title><link>https://tinytip.co/tips/npm-clean-install/</link><guid isPermaLink="true">https://tinytip.co/tips/npm-clean-install/</guid><pubDate>Wed, 02 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You already now the &lt;code&gt;npm install&lt;/code&gt; command, right? It installs your dependencies defined in your &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt;. It will reuse existing packages in your &lt;code&gt;node_modules&lt;/code&gt; folder and may update the &lt;code&gt;package-lock.json&lt;/code&gt; file to match the actual installed versions. This is fine for development, but it is not what you want on your build or testing server.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;npm ci&lt;/code&gt; command does a clean install of your dependencies.
It removes the &lt;code&gt;node_modules&lt;/code&gt; folder and re-installs the dependencies.
It will make sure that the &lt;code&gt;package-lock.json&lt;/code&gt; is up to date and will exit with an error if it is not.
And will never update the &lt;code&gt;package.json&lt;/code&gt; or &lt;code&gt;package-lock.json&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# On your machine&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;npm&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; install&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# On your build or testing server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;npm&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; ci&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;See the &lt;a href=&quot;https://docs.npmjs.com/cli/v8/commands/npm-ci&quot;&gt;npm documentation&lt;/a&gt; for more information.&lt;/p&gt;
</content:encoded><category>terminal</category></item><item><title>Create clearer tests by nesting describe()</title><link>https://tinytip.co/tips/testing-nested-describe/</link><guid isPermaLink="true">https://tinytip.co/tips/testing-nested-describe/</guid><pubDate>Tue, 01 Mar 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Testing Frameworks like Vitest, Jest and Jasmine provide a &lt;code&gt;describe()&lt;/code&gt; function. It is useful to group your tests into logical groups. The function can be nested to create a hierarchy of tests and make the tests more readable.&lt;/p&gt;
&lt;p&gt;In Angular for example, you will have the following spec file when creating a new component:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;AccordionComponent&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should create&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Instead of adding a lot of &lt;code&gt;it()&lt;/code&gt; calls with long descriptions you can create multiple &lt;code&gt;describe()&lt;/code&gt; blocks.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;AccordionComponent&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;initial state is expanded&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;    // Mock data, test utils, etc. for this describe() block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; initiallyExpanded&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should render the accordion title&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should render the accordion content&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should mark the accordion as expanded&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should collapse the accordion when clicking on the title&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  describe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;initial state is collapsed&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should render the accordion title&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should not render the accordion content&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should mark the accordion as collapsed&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    it&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;should expand the accordion when clicking on the title&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Jasmine shows all &lt;code&gt;describe()&lt;/code&gt; blocks in the output and nests them in a tree structure.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Jasmine shows all nested describe blocks&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1372px) 1372px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1372&quot; height=&quot;592&quot; src=&quot;https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_sNrIf.webp&quot; srcset=&quot;https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_Z1HY2ox.webp 640w, https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_Z2f5xXN.webp 750w, https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_Z2nWbne.webp 828w, https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_Z16mTpo.webp 1080w, https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_25PxKq.webp 1280w, https://tinytip.co/_astro/testing-nested-describe.Dpazp5x2_sNrIf.webp 1372w&quot;&gt;&lt;/p&gt;
</content:encoded><category>testing</category></item><item><title>CSS content-visibility hides the content of an element</title><link>https://tinytip.co/tips/css-content-visibility/</link><guid isPermaLink="true">https://tinytip.co/tips/css-content-visibility/</guid><pubDate>Mon, 28 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;There are several ways to hide an element in CSS. &lt;code&gt;display: none&lt;/code&gt; completely hides the element from view. &lt;code&gt;visibility: hidden&lt;/code&gt; hides the element from view, but the element still occupies space in the layout.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;content-visibility&lt;/code&gt; property allows you to hide the content of an element, but not the element itself. Some styling like background and border will still be visible.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.element&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  content-visibility&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;hidden&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;See &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility&quot;&gt;MDN Web Docs&lt;/a&gt; for more information and Browser support.&lt;/p&gt;
</content:encoded><category>css</category></item><item><title>Angular Outputs can be RxJS Observables</title><link>https://tinytip.co/tips/angular-output-observable/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-output-observable/</guid><pubDate>Sun, 27 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Angular uses the &lt;code&gt;@Output&lt;/code&gt; decorator and the &lt;code&gt;EventEmitter&lt;/code&gt; class to emit events to the parent component. But you can use RxJS streams instead.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;EventEmitter&lt;/code&gt; class is actually a wrapper around the RxJs Subject class. If you have an existing Subject or Observable that you want to use as an output, you can directly use it with the &lt;code&gt;@Output&lt;/code&gt; decorator.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SearchComponent&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // With Angular EventEmitter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  @&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Output&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  search&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; EventEmitter&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // With RxJs Subject / Observable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  @&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Output&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  search&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.form.valueChanges.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;pipe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    debounceTime&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    map&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value.term),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;    distinctUntilChanged&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category><category>rxjs</category></item><item><title>CSS calc() requires unit</title><link>https://tinytip.co/tips/css-calc-unit-required/</link><guid isPermaLink="true">https://tinytip.co/tips/css-calc-unit-required/</guid><pubDate>Sat, 26 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Most CSS properties require a unit, for example &lt;code&gt;padding: 10px&lt;/code&gt;. If you use &lt;code&gt;0&lt;/code&gt; you can omit the unit, like &lt;code&gt;padding: 0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An exception is the &lt;code&gt;calc()&lt;/code&gt; function, which always requires a unit, even for &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.example-class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  padding&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* works */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;calc&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;vh&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* does NOT work */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;calc&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;vh&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* works */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That is mainly important if you use CSS custom properties (aka variables) with a default value of &lt;code&gt;0&lt;/code&gt; inside &lt;code&gt;calc()&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.example-class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;calc&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;vh&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; var&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;--header-height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* does NOT work */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;calc&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;vh&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; var&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;--header-height&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* works */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>css</category></item><item><title>Exclude certain types in TypeScript</title><link>https://tinytip.co/tips/ts-exclude-type/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-exclude-type/</guid><pubDate>Fri, 25 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;Exclude&lt;/code&gt; type in TypeScript is a way to exclude certain types from a union.&lt;/p&gt;
&lt;p&gt;Let’s say you use a third-party package that exports a function with an optional parameter. The parameter uses an inline type which is not exported:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; fetch&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;sortBy&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;name&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;date&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;rating&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You now want to extract the type of &lt;code&gt;sortBy&lt;/code&gt; but exclude &lt;code&gt;undefined&lt;/code&gt; from the union (&lt;code&gt;undefined&lt;/code&gt; is allowed because the param is optional).&lt;/p&gt;
&lt;p&gt;You can use &lt;code&gt;Parameters&amp;lt;T&amp;gt;&lt;/code&gt; to get the parameters of the function and &lt;code&gt;Exclude&amp;lt;T&amp;gt;&lt;/code&gt; to exclude &lt;code&gt;undefined&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SortBy&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Exclude&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Parameters&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; fetch&amp;gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;undefined&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Results in: type SortBy = &quot;name&quot; | &quot;date&quot; | &quot;rating&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Data binding to aria attributes in Angular</title><link>https://tinytip.co/tips/angular-attribute-binding/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-attribute-binding/</guid><pubDate>Fri, 25 Feb 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Data Binding in Angular Templates binds to properties not attributes. As &lt;code&gt;aria-*&lt;/code&gt; attributes are not properties, they cannot be bound to. If you want to bind to aria attributes, you need to use the &lt;code&gt;[attr.aria-*]&lt;/code&gt; syntax.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Does NOT work --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; [aria-hidden]&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;isHidden&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  &amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Works --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; [attr.aria-hidden]&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;isHidden&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  &amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category><category>a11y</category></item><item><title>Keep the separators when splitting a string in JavaScript</title><link>https://tinytip.co/tips/js-split-keep-separator/</link><guid isPermaLink="true">https://tinytip.co/tips/js-split-keep-separator/</guid><pubDate>Fri, 28 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;split()&lt;/code&gt; function in JavaScript splits a string into an array by a separator and &lt;strong&gt;removes the separator&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Split by &quot;-&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello-from-javascript&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;-&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Result: [&quot;hello&quot;, &quot;from&quot;, &quot;javascript&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Split by &quot;-&quot; or &quot;_&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello-from_javascript&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;/-&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;_/&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Result: [&quot;hello&quot;, &quot;from&quot;, &quot;javascript&quot;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Use a RegEx group &lt;code&gt;(...)&lt;/code&gt; if you want to &lt;strong&gt;keep the separator&lt;/strong&gt; in the array:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Split by &quot;-&quot; or &quot;_&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello-from_javascript&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;/(-&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;_)/&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Result: [&quot;hello&quot;, &quot;-&quot;, &quot;from&quot;, &quot;_&quot;, &quot;javascript&quot;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Extract types in TypeScript</title><link>https://tinytip.co/tips/ts-extract-types/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-extract-types/</guid><pubDate>Mon, 17 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;infer&lt;/code&gt; keyword in Typescript makes it possible to extract types. This can be used to extract function parameters, generics and more.&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Given the following types ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; interface&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Stream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; { &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; void&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SpecificStream&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Stream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[]&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... you can extract T into a type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; ValueOfStream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;S&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; S&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; extends&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Stream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;infer&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; T&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; never&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... and use like this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; emitValue&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  stream&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SpecificStream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; ValueOfStream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;SpecificStream&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Extract T from Stream&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;TypeScript provides some built-in types like &lt;code&gt;Parameters&lt;/code&gt; and &lt;code&gt;ReturnType&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Given this type ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SomeFn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;first&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;second&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... you can extract parameters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SecondParam&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Parameters&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;SomeFn&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;[&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... and the return type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; ReturnTypeOfSomeFn&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; ReturnType&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;SomeFn&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Observe values in Browser DevTools with Live Expressions</title><link>https://tinytip.co/tips/devtools-live-expression/</link><guid isPermaLink="true">https://tinytip.co/tips/devtools-live-expression/</guid><pubDate>Sun, 19 Dec 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Live Expressions&lt;/em&gt; allow you to observe values in Browser DevTools.
You can enter a JavaScript expression and it will automatically show the latest value.
This can be useful to see how a value changes over time or to monitor the focused element (&lt;code&gt;document.activeElement&lt;/code&gt;) to see if focus handling is working properly.&lt;/p&gt;
&lt;p&gt;Open the DevTools, navigate to the “Console” Tab and click the eye icon to add a new Live Expression.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Add live expression in DevTools&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1938px) 1938px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1938&quot; height=&quot;557&quot; src=&quot;https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_ZrQY0m.webp&quot; srcset=&quot;https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_1IUVmo.webp 640w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_ZBcyBK.webp 750w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_1h6Vre.webp 828w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_Z11iI1X.webp 1080w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_bcRnq.webp 1280w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_ZMaw2I.webp 1668w, https://tinytip.co/_astro/devtools-live-expression.DRgvlDWj_ZrQY0m.webp 1938w&quot;&gt;&lt;/p&gt;
</content:encoded><category>devtools</category></item><item><title>Move VS Code Side Bar to the right</title><link>https://tinytip.co/tips/vscode-sidebar-position/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-sidebar-position/</guid><pubDate>Wed, 17 Nov 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Visual Studio Code shows the side bar on the left side by default.
However, you can move it to the right if you want. Just right-click on the side bar and choose “Move Side Bar Right”.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Change the side bar position via context action&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 845px) 845px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;845&quot; height=&quot;762&quot; src=&quot;https://tinytip.co/_astro/vscode-sidebar-position.QxuJDv1E_DsB11.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-sidebar-position.QxuJDv1E_1UQaff.webp 640w, https://tinytip.co/_astro/vscode-sidebar-position.QxuJDv1E_11fh16.webp 750w, https://tinytip.co/_astro/vscode-sidebar-position.QxuJDv1E_x4gQj.webp 828w, https://tinytip.co/_astro/vscode-sidebar-position.QxuJDv1E_DsB11.webp 845w&quot;&gt;&lt;/p&gt;
&lt;p&gt;When collapsing / expanding the side bar your code does not jump anymore when the side bar is on the right side.
This helps a lot if you toggle the side bar very often.&lt;/p&gt;
</content:encoded><category>vscode</category></item><item><title>Map an RxJS stream to a static value with the mapTo operator</title><link>https://tinytip.co/tips/rxjs-mapto/</link><guid isPermaLink="true">https://tinytip.co/tips/rxjs-mapto/</guid><pubDate>Wed, 17 Nov 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The RxJS operator &lt;code&gt;map&lt;/code&gt; can be used to map the stream value to a new value.
However, if you want to map to a static value that does not depend on the stream value,
you can use the &lt;code&gt;mapTo&lt;/code&gt; operator. This operator accepts the value directly and you don’t need to create an additional function.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Use `map` for dynamic values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;stream$.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;pipe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; user.isAdmin));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Use `mapTo` for static values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;stream$.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;pipe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;mapTo&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the &lt;code&gt;mapTo&lt;/code&gt; operator has been deprecated in RxJS 7 and will be removed in RxJS 8. It’s better to use &lt;code&gt;map&lt;/code&gt; with a function that returns the static value.&lt;/p&gt;
</content:encoded><category>rxjs</category></item><item><title>Angular HttpClient accepts query params as object</title><link>https://tinytip.co/tips/angular-http-params/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-http-params/</guid><pubDate>Wed, 17 Nov 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When making an HTTP request with query params in Angular using the &lt;code&gt;HttpClient&lt;/code&gt; you don’t need to compose the URL by yourself. Instead, you can pass the params as an object or an &lt;code&gt;HttpParams&lt;/code&gt; instance.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Instead of passing query params as part of the URL...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; fetchSomeData&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.httpClient.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&apos;/my/endpoint?id=2&apos;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... you can pass them as object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; fetchSomeData&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; params&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.httpClient.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&apos;/my/endpoint&apos;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { params });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... or HttpParams&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; fetchSomeData&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; params&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; HttpParams&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;().&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&apos;id&apos;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; this&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;.httpClient.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&apos;/my/endpoint&apos;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, { params });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category></item><item><title>How to use Array.map() with objects</title><link>https://tinytip.co/tips/js-object-from-entries/</link><guid isPermaLink="true">https://tinytip.co/tips/js-object-from-entries/</guid><pubDate>Sat, 09 Oct 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;Array.map()&lt;/code&gt; function allows to to map each value of an array to a new value.
If you want to map an object - its keys, values or both - you can use &lt;code&gt;Object.entries()&lt;/code&gt; and &lt;code&gt;Object.fromEntries()&lt;/code&gt; to convert the object to an array and back to an object.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Object.entries()&lt;/code&gt; function expects an object and returns an array with key-value pairs in the form of an array &lt;code&gt;[key, value]&lt;/code&gt;. Then you can use &lt;code&gt;Array.map()&lt;/code&gt; to map the keys and/or values.&lt;/p&gt;
&lt;p&gt;The transformed array can be converted back to an object by using &lt;code&gt;Object.fromEntries()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// 1. Create an object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; obj&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; { one: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, two: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, three: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// 2. Convert the object to an array of key-value pairs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; entries&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Object.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;entries&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(obj);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// [ [&quot;one&quot;, 1], [&quot;two&quot;, 2], [&quot;three&quot;, 3] ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// 3. Map the array to new keys or values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; transformed&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; entries.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(([&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // Change the value to a string and add leading zeros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [key, value.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;().&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;padStart&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;0&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// 4. Convert the transformed array back to an object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; finalResult&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Object.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;fromEntries&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(transformed);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// { one: &quot;001&quot;, two: &quot;002&quot;, three: &quot;003&quot; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Style Angular Components based on their context</title><link>https://tinytip.co/tips/angular-host-context/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-host-context/</guid><pubDate>Sat, 09 Oct 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The Angular &lt;code&gt;:host-context()&lt;/code&gt; selector allows you to style your component based on some conditions outside the component - for example based on a class set on the body element - without the need to set view encapsulation to &lt;code&gt;none&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The selector will look for a matching element in any ancestor of your component up to the document root.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:host-context(&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.dark-theme&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.my-component&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Styles are applied when there is a &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;     &quot;dark-theme&quot; class on any ancestor */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is not limited to CSS class selectors but works with any valid CSS selector.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:host-context([&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;theme&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;dark&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.my-component&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Styles are applied when there is an ancestor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;     that has an attribute theme=&quot;dark&quot; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category><category>css</category></item><item><title>The CSS list-style property affects screen readers</title><link>https://tinytip.co/tips/a11y-html-list-role/</link><guid isPermaLink="true">https://tinytip.co/tips/a11y-html-list-role/</guid><pubDate>Sat, 09 Oct 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you have a &lt;code&gt;ul&lt;/code&gt; element in your HTML and you set &lt;code&gt;list-style: none&lt;/code&gt; via CSS (via inline styles, a style tag or an external stylesheet),
your list will &lt;strong&gt;not&lt;/strong&gt; be announced as a list anymore with VoiceOver + Safari on macOS.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- VoiceOver + Safari will not announce this as a list --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; style&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;list-style:none&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Add the &lt;code&gt;role&lt;/code&gt; attribute to the &lt;code&gt;ul&lt;/code&gt; element to fix this behavior.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- VoiceOver + Safari will now announce the list --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; role&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;list&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; style&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;list-style:none&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;...&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>html</category><category>a11y</category></item><item><title>Alpine.js accepts a custom prefix for directives</title><link>https://tinytip.co/tips/alpine-prefix/</link><guid isPermaLink="true">https://tinytip.co/tips/alpine-prefix/</guid><pubDate>Tue, 21 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Alpine.js uses the &lt;code&gt;x-&lt;/code&gt; prefix for directives by default (e.g. &lt;code&gt;x-if&lt;/code&gt;).
This prefix can be customized using &lt;code&gt;Alpine.prefix()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;Alpine.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;xyz-&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Define your custom prefix&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;Alpine.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Use your custom prefix for all directives --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; xyz-if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; xyz-bind:href&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;user.profileUrl&quot;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; xyz-text&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;user.name&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This can be useful to prevent clashes when integrating Alpine into existing apps / markup or to get valid HTML markup that passes the &lt;a href=&quot;https://validator.w3.org/&quot;&gt;W3C validator&lt;/a&gt; by using &lt;code&gt;data-x-&lt;/code&gt; as prefix.&lt;/p&gt;
</content:encoded><category>javascript</category></item><item><title>CSS has a turn unit to rotate elements</title><link>https://tinytip.co/tips/css-rotate-turn/</link><guid isPermaLink="true">https://tinytip.co/tips/css-rotate-turn/</guid><pubDate>Sat, 18 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;rotate&lt;/code&gt; function of the CSS &lt;code&gt;transform&lt;/code&gt; property supports the &lt;code&gt;turn&lt;/code&gt; unit.
This can be used as an alternative to &lt;code&gt;deg&lt;/code&gt;. 360 degrees correspond to 1 turn.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.element&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* Instead of degrees ... */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  transform&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;rotate&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;deg&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* ... you can use turn */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  transform&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;rotate&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;0.25&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;turn&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Let’s see it in action:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Demo of rotated elements in CSS&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1490px) 1490px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1490&quot; height=&quot;340&quot; src=&quot;https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_dxbNy.webp&quot; srcset=&quot;https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_Zrsjx7.webp 640w, https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_1D1IjS.webp 750w, https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_Z1btgu.webp 828w, https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_IApHc.webp 1080w, https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_17xBSz.webp 1280w, https://tinytip.co/_astro/css-rotate-turn.DVEhktm-_dxbNy.webp 1490w&quot;&gt;&lt;/p&gt;
</content:encoded><category>css</category></item><item><title>Create an array with the map function of Array.from</title><link>https://tinytip.co/tips/js-array-init-with-fn/</link><guid isPermaLink="true">https://tinytip.co/tips/js-array-init-with-fn/</guid><pubDate>Sat, 04 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;Array.from&lt;/code&gt; function has a second parameter that lets you map each item to a new value.&lt;/p&gt;
&lt;p&gt;The first argument of the map function is the current value or &lt;code&gt;undefined&lt;/code&gt; if you don’t have an existing list (as in the example below). The second argument is the index.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; items&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Array.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ length: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }, (&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;idx&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; idx &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(items); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// [1, 2, 3, 4, 5]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Configure default branch name in Git</title><link>https://tinytip.co/tips/git-branch-default-name/</link><guid isPermaLink="true">https://tinytip.co/tips/git-branch-default-name/</guid><pubDate>Sat, 04 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A newly created Git repo (&lt;code&gt;git init&lt;/code&gt;) has a default branch with the name &lt;code&gt;master&lt;/code&gt;.
You can configure that name for all new repositories with the following command:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; config&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; --global&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; init.defaultBranch&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; main&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now every new Git repository will automatically create a branch &lt;code&gt;main&lt;/code&gt; instead of &lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;
</content:encoded><category>git</category></item><item><title>setTimeout accepts arguments for the function</title><link>https://tinytip.co/tips/js-timeout-args/</link><guid isPermaLink="true">https://tinytip.co/tips/js-timeout-args/</guid><pubDate>Sun, 15 Aug 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;setTimeout&lt;/code&gt; function accepts optional arguments that are passed to the provided function. This way you can pass arguments without wrapping the actual function in another function.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Instead of this...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;setTimeout&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; search&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// ... you can do this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;setTimeout&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(search, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;world&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Function parameters can have default values based on other parameters</title><link>https://tinytip.co/tips/js-params-default-values/</link><guid isPermaLink="true">https://tinytip.co/tips/js-params-default-values/</guid><pubDate>Sun, 15 Aug 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A function with parameters can have default values that are used when the caller
does not provide a value for that parameter (by omitting the parameter or providing &lt;code&gt;undefined&lt;/code&gt;). The default value does not have to be a static value. You can run JavaScript and use previous parameters of that function.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// &quot;timestamp&quot; has a dynamic default value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; logMessage&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;timestamp&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Date.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;now&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;()) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; someFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  max&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E36209&quot;&gt;  suffix&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; value.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; max &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;...&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// max = 5, suffix = &quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// max = 2, suffix = &quot;...&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;undefined&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;.....&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// max = 5, suffix = &quot;.....&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Create a string type in a specific format in TypeScript</title><link>https://tinytip.co/tips/typescript-template-string-types/</link><guid isPermaLink="true">https://tinytip.co/tips/typescript-template-string-types/</guid><pubDate>Thu, 29 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;TypeScript supports template string types that lets you create string types in a specific format. Here are a few examples:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Locale&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `${&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;}-${&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; locale&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Locale&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;en-US&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Url&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `https://${&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; url&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Url&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;https://tinytip.co&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; CssCustomProp&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `var(--${&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;})`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; cssCustomProp&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; CssCustomProp&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;var(--color-primary)&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; CurrencySymbol&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;€&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;$&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;£&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;¥&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; AmountWithCurrency&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `${&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;CurrencySymbol&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;} ${&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; bankBalance&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; AmountWithCurrency&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; `$ 42`&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Check if a string is a valid enum value in TypeScript</title><link>https://tinytip.co/tips/typescript-enum-validation/</link><guid isPermaLink="true">https://tinytip.co/tips/typescript-enum-validation/</guid><pubDate>Thu, 29 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Let’s say you have an enum &lt;code&gt;Animal&lt;/code&gt; and a string value and you want to check if the value is an animal.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Animal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  Cat&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;cat&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  Dog&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;dog&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; someInputValue&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;cat&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// TS compiler will show an error,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// because &quot;cat&quot; is not assignable to Animal.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// We need to check if `someInputValue` is an animal.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;someFunctionThatExpectsAnAnimal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(someInputValue);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;TypeScript supports type guards and type predicates that lets you do this. The function &lt;code&gt;isAnimal&lt;/code&gt; accepts a string value and returns a boolean whether the value is a valid animal or not.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; isAnimal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; is&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Animal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; Object.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;(Animal).&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;includes&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If the function returns &lt;code&gt;true&lt;/code&gt;, TypeScript knows that the value is an &lt;code&gt;Animal&lt;/code&gt; and infers that type inside the &lt;code&gt;if&lt;/code&gt; statement. You don’t need to write &lt;code&gt;as Animal&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;isAnimal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(someInputValue)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  // TypeScript knows that `someInputValue` is of type `Animal`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;  someFunctionThatExpectsAnAnimal&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(someInputValue);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Enable smooth scrolling with scroll-behavior in CSS</title><link>https://tinytip.co/tips/css-smooth-scrolling/</link><guid isPermaLink="true">https://tinytip.co/tips/css-smooth-scrolling/</guid><pubDate>Wed, 28 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can change the scroll behavior of your page (or an element) with the
&lt;code&gt;scroll-behavior&lt;/code&gt; property. Using &lt;code&gt;smooth&lt;/code&gt; will enable animated scrolling when
the user clicks on an anchor link on your page. Normal scrolling by the user is not affected by this property.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#22863A&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  scroll-behavior&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;smooth&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>css</category></item><item><title>Enable Screencast Mode in VS Code</title><link>https://tinytip.co/tips/vscode-screencast-mode/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-screencast-mode/</guid><pubDate>Sat, 03 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Visual Studio Code has an integrated Screencast Mode. This can be useful when sharing your screen
or making videos. Press &lt;code&gt;Ctrl+Shift+P&lt;/code&gt; (or &lt;code&gt;Cmd+ShiftP&lt;/code&gt; on macOS) to open the command palette, search for “Screencast” and select the &lt;code&gt;Developer: Toggle Screencast Mode&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Toggle Screencast Mode in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1974px) 1974px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1974&quot; height=&quot;1322&quot; src=&quot;https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_Cc5dw.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_9Pr7e.webp 640w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_2tcfCM.webp 750w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_Z1d29MR.webp 828w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_ZBWRlH.webp 1080w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_qgXcb.webp 1280w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_tRn4l.webp 1668w, https://tinytip.co/_astro/vscode-screencast-mode-toggle.kZvhMX6r_Cc5dw.webp 1974w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Screencast Mode shows whenever you click with the mouse (a red circle appears) or press a key.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Toggle Screencast Mode in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1974px) 1974px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1974&quot; height=&quot;1322&quot; src=&quot;https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_Z1AAQq5.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_VqKNC.webp 640w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_ZOiekO.webp 750w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_1m2IV0.webp 828w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_gDUKD.webp 1080w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_Zua4eG.webp 1280w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_qqFlE.webp 1668w, https://tinytip.co/_astro/vscode-screencast-mode-demo.CH2oVxep_Z1AAQq5.webp 1974w&quot;&gt;&lt;/p&gt;
&lt;p&gt;The appearance of these elements can be customized in the settings.
If you want to show only keyboard shortcuts and not all keys, you can configure the following property:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  &quot;screencastMode.onlyKeyboardShortcuts&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>vscode</category></item><item><title>Unsubscribe multiple RxJS subscriptions with Subscription.add()</title><link>https://tinytip.co/tips/rxjs-subscription-add/</link><guid isPermaLink="true">https://tinytip.co/tips/rxjs-subscription-add/</guid><pubDate>Sat, 03 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;code&gt;Subscription&lt;/code&gt; class in &lt;a href=&quot;https://rxjs.dev/&quot;&gt;RxJS&lt;/a&gt; has an &lt;code&gt;add()&lt;/code&gt; method that let’s you add subscriptions. All added subscriptions will be unsubscribed when you call &lt;code&gt;unsubscribe()&lt;/code&gt; on the root subscription.&lt;/p&gt;
&lt;p&gt;This lets you clean up multiple subscriptions with one command.&lt;/p&gt;
&lt;!-- prettier-ignore --&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Create a new subscription&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; subscription&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Subscription&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Subscribe to some observables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// and add them to the subscription&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;subscription.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(one$.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;subscription.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(two$.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;subscription.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(three$.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; }));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// During clean up&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// This unsubscribes the subscription of one$, two$ and three$&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;subscription.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;unsubscribe&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>rxjs</category></item><item><title>Edit any website in design mode</title><link>https://tinytip.co/tips/js-designmode/</link><guid isPermaLink="true">https://tinytip.co/tips/js-designmode/</guid><pubDate>Sat, 03 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The &lt;em&gt;design mode&lt;/em&gt; lets you edit the content of any website directly inline in a WYSIWYG-like fashion. The modifications are locally only but still useful if you
want to test something. Keyboard shortcuts like &lt;code&gt;Ctrl+B&lt;/code&gt; for bold are supported.&lt;/p&gt;
&lt;p&gt;The design mode can be enabled with one line of JavaScript:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Enable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document.designMode &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;on&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Disable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document.designMode &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;off&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Toggle&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document.designMode &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.designMode &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;on&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; ?&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;off&quot;&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;on&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category><category>html</category></item><item><title>Reuse the last git commit message in VS Code</title><link>https://tinytip.co/tips/vscode-source-control-last-commit-msg/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-source-control-last-commit-msg/</guid><pubDate>Sun, 27 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you add a new git commit in VS Code you can press &lt;code&gt;Arrow Up&lt;/code&gt; in the commit message input to get the previous commit message. Press it several times to get older commit messages.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Demo of how to get the previous commit message in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 640px) 640px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;640&quot; height=&quot;455&quot; src=&quot;https://tinytip.co/_astro/vscode-source-control-last-commit-msg.Cm8bt99V_Gpljf.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-source-control-last-commit-msg.Cm8bt99V_Gpljf.webp 640w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Note: this only works for changes committed with the source control panel in VS Code. It will not show commits from external tools like SourceTree or the terminal.&lt;/p&gt;
</content:encoded><category>vscode</category><category>git</category></item><item><title>TypeScript supports arrays with the rest syntax at the beginning</title><link>https://tinytip.co/tips/ts-rest-array/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-rest-array/</guid><pubDate>Sun, 20 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A rest parameter in a JavaScript function must be the last parameter of the list:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Does not work&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;arg&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Works&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, you can use the rest syntax for an array type in TypeScript at any position.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Expect a list of strings and one number as last parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[], &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;]) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// It can also be in the middle of an array&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Example&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[], &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Define an array with a min length in TypeScript</title><link>https://tinytip.co/tips/ts-array-min-length/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-array-min-length/</guid><pubDate>Sun, 20 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can create an array type with a min length in TypeScript by using the rest syntax.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Type requires at least one element&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; NonEmptyArray&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[]];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Type requires at least three elements&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; ThreeOreMoreArray&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;[]];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can now use the type and TypeScript ensures that the array meets the minimum length:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; NonEmptyArray&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Error: Source has 0 element(s) but target requires 1.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;([]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Works&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;example&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;one&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;two&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;three&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Style console log outputs in JavaScript</title><link>https://tinytip.co/tips/js-console-styles/</link><guid isPermaLink="true">https://tinytip.co/tips/js-console-styles/</guid><pubDate>Sun, 20 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Console Log statements can be styled with a limited set of CSS features.
Insert &lt;code&gt;%c&lt;/code&gt; in your log message add an additional parameter with the style.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Logs &quot;hello world&quot; in red letters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;%chello world&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;color:red&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Use multiple &quot;%c&quot; and multiple style arguments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Logs &quot;hello world&quot; and &quot;hello&quot; is red&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;%chello %cworld&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;color:red&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// &quot;hello&quot; is italic and &quot;world&quot; has a red border and red text color&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;  &quot;%chello %cworld&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;  &quot;font-style:italic&quot;&lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt; /* styles for &quot;hello&quot; */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#032F62&quot;&gt;  &quot;border:1px solid red;color:red&quot;&lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt; /* styles for &quot;world&quot; */&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here is how it looks like on your browser console:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Styled color logs in the browser console&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1740px) 1740px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1740&quot; height=&quot;634&quot; src=&quot;https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_ZQ3tHB.webp&quot; srcset=&quot;https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_Z2vfi50.webp 640w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_2pwmMs.webp 750w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_Z4h5lh.webp 828w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_ZeGnVa.webp 1080w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_ZEBRue.webp 1280w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_1zNOWF.webp 1668w, https://tinytip.co/_astro/js-console-styles.Cw7YjwLn_ZQ3tHB.webp 1740w&quot;&gt;&lt;/p&gt;
</content:encoded><category>javascript</category></item><item><title>Amend the previous commit and keep the commit message</title><link>https://tinytip.co/tips/git-amend-commit/</link><guid isPermaLink="true">https://tinytip.co/tips/git-amend-commit/</guid><pubDate>Sun, 20 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Did you just commit some changes and forget to delete that &lt;code&gt;console.log(&apos;test&apos;)&lt;/code&gt; statement?
Use &lt;code&gt;git commit&lt;/code&gt; with &lt;code&gt;--amend&lt;/code&gt; to edit the previous commit and &lt;code&gt;--no-edit&lt;/code&gt; to keep the previous commit message.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# 1. Delete the console.log&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# 2. Stage the changes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; add&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; my-file.js&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# 3. Commit by updating the previous commit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;git&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; commit&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; --amend&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; --no-edit&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Do this for local commits only. Don’t amend commits that you already pushed.&lt;/p&gt;
</content:encoded><category>git</category></item><item><title>Generate strings with brace expansion</title><link>https://tinytip.co/tips/bash-brace-expansion/</link><guid isPermaLink="true">https://tinytip.co/tips/bash-brace-expansion/</guid><pubDate>Sun, 20 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Brace expansion lets you generate arbitrary strings in your terminal.
Place a comma-separated list of items in curly braces &lt;code&gt;{}&lt;/code&gt; and add prefix and/or suffix.
It will repeat the prefix / suffix for every item in the list.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Deletes image-01.png, image-17.png and image-42.png&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; rm&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; image-{01,17,42}.png&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# &quot;Hello &quot; must be in quotes because it ends with a white space&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Without quotes it would generate &quot;Hello World everyone&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; echo&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;Hello &quot;{World,everyone}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;Hello&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; World&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; Hello&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; Everyone&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Installs @radix-ui/react-accordion, @radix-ui/react-checkbox&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# and @radix-ui/react-switch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;npm&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; @radix-ui/{react-accordion,react-checkbox,react-switch}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>terminal</category></item><item><title>Generate code with Emmet in VS Code</title><link>https://tinytip.co/tips/vscode-emmet-abbreviations/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-emmet-abbreviations/</guid><pubDate>Sat, 19 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Emmet let’s you generate code by writing CSS-like expressions.
Write a small expression, press tab and it will generate the output for you.
VS Code supports Emmet out of the box.&lt;/p&gt;
&lt;p&gt;Here is an example that generates a submit button with id &lt;code&gt;submit&lt;/code&gt;, class &lt;code&gt;primary&lt;/code&gt; and the content “Submit” as shown in the preview tooltip.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Example of using Emmet in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1884px) 1884px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1884&quot; height=&quot;1272&quot; src=&quot;https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_15dFQq.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_Z1d7PoE.webp 640w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_Z27o57L.webp 750w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_Z1VzqBC.webp 828w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_1C6gno.webp 1080w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_Z18uuhs.webp 1280w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_7FkBB.webp 1668w, https://tinytip.co/_astro/vscode-emmet-abbreviations.DhEM_4bY_15dFQq.webp 1884w&quot;&gt;&lt;/p&gt;
&lt;p&gt;Here is another example:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Expression --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;ul.list&amp;gt;li.item*5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Output --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;list&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;item&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;See the official &lt;a href=&quot;https://docs.emmet.io/cheat-sheet/&quot;&gt;cheat sheet&lt;/a&gt; for more information.&lt;/p&gt;
</content:encoded><category>vscode</category></item><item><title>Assert that all possible cases in a switch statement are handled</title><link>https://tinytip.co/tips/ts-switch-assert-unreachable/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-switch-assert-unreachable/</guid><pubDate>Sat, 19 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Let’s say you have a &lt;code&gt;switch&lt;/code&gt; statement that handles all values of an enum (or some other type with a limited number of possible values). When you extend that enum sometime in the future you may forget to add a new case to the statement.&lt;/p&gt;
&lt;p&gt;With TypeScript you can use an &lt;code&gt;assertUnreachable()&lt;/code&gt; function to ensure that all possible cases are handled:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; myFunction&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; SomeEnum&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  switch&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; (value) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    case&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; SomeEnum.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;ONE&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;      break&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    case&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; SomeEnum.&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;TWO&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;      break&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;    default&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;      // Ensures that all cases are handled&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line highlighted&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;      assertUnreachable&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;assertUnreachable()&lt;/code&gt; function works by defining an argument of type &lt;code&gt;never&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; assertUnreachable&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E36209&quot;&gt;_value&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; never&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; never&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;  throw&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; new&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; Error&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;Statement should be unreachable&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When you now extend the enum TypeScript will show an error:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;TypeScript Error for unhandled cases&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1622px) 1622px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1622&quot; height=&quot;756&quot; src=&quot;https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_1V8LUh.webp&quot; srcset=&quot;https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_1BUJx2.webp 640w, https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_14mU4C.webp 750w, https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_Z23HmlX.webp 828w, https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_Z154COG.webp 1080w, https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_ZUe9Oa.webp 1280w, https://tinytip.co/_astro/ts-switch-assert-unreachable.D4z_0FB8_1V8LUh.webp 1622w&quot;&gt;&lt;/p&gt;
</content:encoded><category>typescript</category></item><item><title>Separate large numbers in TypeScript with underscore</title><link>https://tinytip.co/tips/ts-number-underscore-separator/</link><guid isPermaLink="true">https://tinytip.co/tips/ts-number-underscore-separator/</guid><pubDate>Sat, 19 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In TypeScript numbers can be separated using underscore.
This improves the readability of large numbers.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Bad, hard to read. How many zeros are there?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; MAGIC_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 1000000&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Good&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; MAGIC_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; 100_000&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>typescript</category></item><item><title>Insert multiple HTML elements at once with DocumentFragment</title><link>https://tinytip.co/tips/js-document-fragment/</link><guid isPermaLink="true">https://tinytip.co/tips/js-document-fragment/</guid><pubDate>Sat, 19 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you need to create multiple HTML elements and insert them into the DOM, you can use a document fragment. A document fragment allows you to assemble all elements and insert them all at once.
That is more efficient than adding them one by one.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;javascript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Create a new fragment&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; fragment&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;createDocumentFragment&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; item1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;div&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;item1.innerText &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;item 1&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;fragment.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;appendChild&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(item1); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Append a child&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; item2&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;div&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;item2.innerText &lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt; &quot;item 2&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;fragment.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;appendChild&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(item2); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Append another child&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Append all child to the document&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// The document fragment will not be part of the DOM&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;document.body.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;appendChild&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(fragment);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// The document fragment is now empty&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(fragment.childElementCount); &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// logs 0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>javascript</category></item><item><title>Open GitHub repositories in VS Code directly in your browser</title><link>https://tinytip.co/tips/github-repo-in-code/</link><guid isPermaLink="true">https://tinytip.co/tips/github-repo-in-code/</guid><pubDate>Thu, 17 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can view any public GitHub repository in VS Code directly in your browser.
Just open the repository on GitHub in your browser and change the domain to &lt;code&gt;github1s.com&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This will open a readonly VS Code instance directly in your browser.&lt;/p&gt;
&lt;p&gt;Example: &lt;a href=&quot;https://github1s.com/facebook/react/&quot;&gt;github1s.com/facebook/react/&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>git</category><category>vscode</category></item><item><title>Find files by name on GitHub</title><link>https://tinytip.co/tips/github-file-finder/</link><guid isPermaLink="true">https://tinytip.co/tips/github-file-finder/</guid><pubDate>Thu, 17 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Open a repository on GitHub and press &lt;code&gt;t&lt;/code&gt; to open the File Finder.
This let’s you find files by name (or name of the directory) in the current repo.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;File Finder on GitHub&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1904px) 1904px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1904&quot; height=&quot;730&quot; src=&quot;https://tinytip.co/_astro/github-file-finder.DU0k-uE__lG0r8.webp&quot; srcset=&quot;https://tinytip.co/_astro/github-file-finder.DU0k-uE__Z1HqP9T.webp 640w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__1Y4cDs.webp 750w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__Z2bX249.webp 828w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__Z17IEsM.webp 1080w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__Z15Btt4.webp 1280w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__10688I.webp 1668w, https://tinytip.co/_astro/github-file-finder.DU0k-uE__lG0r8.webp 1904w&quot;&gt;&lt;/p&gt;
</content:encoded><category>git</category></item><item><title>Emulate a focused page in DevTools to debug overlay elements</title><link>https://tinytip.co/tips/devtools-focused-page/</link><guid isPermaLink="true">https://tinytip.co/tips/devtools-focused-page/</guid><pubDate>Thu, 17 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Some overlay elements like dropdowns or flyout menus automatically hide/remove themselves when
the focus is lost. Whenever you switch to the DevTools the page is not focused anymore and the
element gets hidden.&lt;/p&gt;
&lt;p&gt;The Chrome DevTools have a feature to emulate page focus. Open the DevTools, press &lt;code&gt;Ctrl+Shift+P&lt;/code&gt; (or
&lt;code&gt;Cmd+Shift+P&lt;/code&gt; on macOS) and search for “Emulate a focused page”.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Emulate a focused page in DevTools&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2054px) 2054px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2054&quot; height=&quot;424&quot; src=&quot;https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_BRgMP.webp&quot; srcset=&quot;https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_KQ2KY.webp 640w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_wb3JI.webp 750w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_Z2vjN15.webp 828w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_Z1CR4ag.webp 1080w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_ZGrYks.webp 1280w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_ZTyzVx.webp 1668w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_Z2wr4Gy.webp 2048w, https://tinytip.co/_astro/devtools-focused-page.BwyGAYfE_BRgMP.webp 2054w&quot;&gt;&lt;/p&gt;
</content:encoded><category>devtools</category></item><item><title>Navigate easier in large files via symbols in VS Code</title><link>https://tinytip.co/tips/vscode-symbol-navigation/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-symbol-navigation/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you open a file in VS Code and you look for a specific function, class, … you can navigate by symbols. Press &lt;code&gt;Ctrl+Shift+O&lt;/code&gt; (or &lt;code&gt;Cmd+Shift+O&lt;/code&gt; on macOS) to see all symbols of the current file. You can filter the list and navigate through the results with arrow down / arrow up. VS Code will automatically scroll to the focused element. Press &lt;code&gt;esc&lt;/code&gt; to close the list (and navigate back to the original scroll position) or &lt;code&gt;enter&lt;/code&gt; to focus that symbol.&lt;/p&gt;
&lt;p&gt;This works for many different languages like JavaScript, TypeScript and even headings in Markdown.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Symbol Search in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 2168px) 2168px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;2168&quot; height=&quot;1524&quot; src=&quot;https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_17vskY.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_Z1RXTSH.webp 640w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_PA3SG.webp 750w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_ZNE3Le.webp 828w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_2wxBea.webp 1080w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_Z1daWSI.webp 1280w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_ZqfXSv.webp 1668w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_Z1lDjgd.webp 2048w, https://tinytip.co/_astro/vscode-symbol-navigation.BhBrJ-3f_17vskY.webp 2168w&quot;&gt;&lt;/p&gt;
</content:encoded><category>vscode</category></item><item><title>Restart TypeScript server in VS Code with a command</title><link>https://tinytip.co/tips/vscode-restart-ts/</link><guid isPermaLink="true">https://tinytip.co/tips/vscode-restart-ts/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Sometimes the TypeScript server in Visual Studio Code crashes
which results in broken auto completion. You can restart the server with a single command.&lt;/p&gt;
&lt;p&gt;Make sure that you have a TypeScript file open, press &lt;code&gt;Ctrl+Shift+P&lt;/code&gt; (or &lt;code&gt;Cmd+Shift+P&lt;/code&gt; on macOS) to open the Command Palette and type &lt;code&gt;restart&lt;/code&gt;, then select the command “TypeScript: Restart TS server”.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;Restart TS server command in VS Code&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 1776px) 1776px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;1776&quot; height=&quot;1194&quot; src=&quot;https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_sh0Mt.webp&quot; srcset=&quot;https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_27zMn6.webp 640w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_Z2tfYiv.webp 750w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_Z29vG8p.webp 828w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_Z1UG3tB.webp 1080w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_Z2bLRLm.webp 1280w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_1DLK4z.webp 1668w, https://tinytip.co/_astro/vscode-restart-ts.DDjbnsmc_sh0Mt.webp 1776w&quot;&gt;&lt;/p&gt;
&lt;p&gt;The status bar at the bottom of the window will show the status of the server.&lt;/p&gt;
</content:encoded><category>vscode</category></item><item><title>Copy text in the browser console with the copy() function</title><link>https://tinytip.co/tips/devtools-copy-text/</link><guid isPermaLink="true">https://tinytip.co/tips/devtools-copy-text/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The DevTools provide a global &lt;code&gt;copy()&lt;/code&gt; function.
Use that function in the Console tab to copy any content into your clipboard.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Copy some static text into the clipboard&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;copy&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;hello world&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Copy the page title&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;copy&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(document.title);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Copy some content from localStorage&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;copy&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(localStorage.&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;getItem&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;));&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>devtools</category></item><item><title>Find elements in the browser console with $$</title><link>https://tinytip.co/tips/devtools-console-query-selector/</link><guid isPermaLink="true">https://tinytip.co/tips/devtools-console-query-selector/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Use &lt;code&gt;$$(...)&lt;/code&gt; in the Console tab of the DevTools to query elements.
It’s a quick way for using &lt;code&gt;querySelectorAll&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Find all &quot;a&quot; elements&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$$&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Find all div elements with &quot;container&quot; in the class attribute&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;$$&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;div[class*=&apos;container&apos;]&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>devtools</category></item><item><title>Use $0 in the browser console to get the current element</title><link>https://tinytip.co/tips/devtools-console-current-element/</link><guid isPermaLink="true">https://tinytip.co/tips/devtools-console-current-element/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When you select an element in the Elements tab of the Browser DevTools you
can use &lt;code&gt;$0&lt;/code&gt; in the Console tab to refer to that element.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Logs the selected element of the Elements tab&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;$0;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;// Access any property or method on that element&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;$0.href;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>devtools</category></item><item><title>Get the current text color with currentColor in CSS</title><link>https://tinytip.co/tips/css-current-color/</link><guid isPermaLink="true">https://tinytip.co/tips/css-current-color/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In CSS the special variable &lt;code&gt;currentColor&lt;/code&gt; gives you access to
the current text color of the element. You can use this value
in other properties like &lt;code&gt;border-color&lt;/code&gt; to automatically adjust the border
to match the text color.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.button&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  border&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D73A49&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; solid&lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt; currentColor&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;/* border color is blue */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;blue&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt;.button:hover&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;  /* border color automatically changes to darkblue */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;  color&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#005CC5&quot;&gt;darkblue&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>css</category></item><item><title>Listen for specific keys in Angular Templates</title><link>https://tinytip.co/tips/angular-event-key-modifiers/</link><guid isPermaLink="true">https://tinytip.co/tips/angular-event-key-modifiers/</guid><pubDate>Mon, 14 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Angular allows you to listen for specific keys of a keyboard event similar to &lt;a href=&quot;https://v3.vuejs.org/guide/events.html#key-modifiers&quot;&gt;Vue’s Key Modifiers&lt;/a&gt;. When listing for a keyboard event like &lt;code&gt;keydown&lt;/code&gt; or &lt;code&gt;keyup&lt;/code&gt; you can add a key or key combination that you want to listen for.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;astro-code github-light&quot; style=&quot;background-color:#fff;color:#24292e; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;html&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Listen for all keys --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; (keydown)&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;onKeyDown()&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Listen for enter --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; (keydown.enter)&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;onEnter()&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Listen for arrow down --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; (keydown.arrowdown)&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;onArrowDown()&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;&amp;lt;!-- Listen for shift + f --&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#24292E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#22863A&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#6F42C1&quot;&gt; (keydown.shift.f)&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#032F62&quot;&gt;&quot;onShiftF()&quot;&lt;/span&gt;&lt;span style=&quot;color:#24292E&quot;&gt; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content:encoded><category>angular</category></item></channel></rss>