Travis build: 1833

This commit is contained in:
30secondsofcode
2018-03-19 17:29:22 +00:00
parent 5736b0329f
commit d7c4f837e5
2 changed files with 5 additions and 6 deletions

View File

@ -8260,12 +8260,11 @@ Logs: {
### isBrowser
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node)
without throwing errors.
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.
Use `Array.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a
browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`.
`typeof` allows globals to be checked for existence without throwing a ReferenceError. If both of them are not `undefined`, then the current environment is assumed to be a browser.
Use `Array.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`.
`typeof` allows globals to be checked for existence without throwing a `ReferenceError`.
If both of them are not `undefined`, then the current environment is assumed to be a browser.
```js
const isBrowser = () => ![typeof window, typeof document].includes('undefined');

View File

@ -1990,7 +1990,7 @@ Logs: {
"id": 101
}
*/</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="isbrowser" class="section double-padded">isBrowser</h3><div class="section double-padded"><p>Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.</p><p>Use <code>Array.includes()</code> on the <code>typeof</code> values of both <code>window</code> and <code>document</code> (globals usually only available in a browser environment unless they were explicitly defined), which will return <code>true</code> if one of them is <code>undefined</code>. <code>typeof</code> allows globals to be checked for existence without throwing a ReferenceError. If both of them are not <code>undefined</code>, then the current environment is assumed to be a browser.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">isBrowser</span> <span class="token operator">=</span> <span class="token punctuation">()</span> <span class="token operator">=> !</span><span class="token punctuation">[</span><span class="token keyword">typeof</span> window<span class="token punctuation">,</span> <span class="token keyword">typeof</span> document<span class="token punctuation">].</span><span class="token function">includes</span><span class="token punctuation">(</span><span class="token string">'undefined'</span><span class="token punctuation">);</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="isbrowser" class="section double-padded">isBrowser</h3><div class="section double-padded"><p>Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.</p><p>Use <code>Array.includes()</code> on the <code>typeof</code> values of both <code>window</code> and <code>document</code> (globals usually only available in a browser environment unless they were explicitly defined), which will return <code>true</code> if one of them is <code>undefined</code>. <code>typeof</code> allows globals to be checked for existence without throwing a <code>ReferenceError</code>. If both of them are not <code>undefined</code>, then the current environment is assumed to be a browser.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">isBrowser</span> <span class="token operator">=</span> <span class="token punctuation">()</span> <span class="token operator">=> !</span><span class="token punctuation">[</span><span class="token keyword">typeof</span> window<span class="token punctuation">,</span> <span class="token keyword">typeof</span> document<span class="token punctuation">].</span><span class="token function">includes</span><span class="token punctuation">(</span><span class="token string">'undefined'</span><span class="token punctuation">);</span>
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">isBrowser</span><span class="token punctuation">();</span> <span class="token comment">// true (browser)</span>
<span class="token function">isBrowser</span><span class="token punctuation">();</span> <span class="token comment">// false (Node)</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="mostperformant" class="section double-padded">mostPerformant</h3><div class="section double-padded"><p>Returns the index of the function in an array of functions which executed the fastest.</p><p>Use <code>Array.map()</code> to generate an array where each value is the total time taken to execute the function after <code>iterations</code> times. Use the difference in <code>performance.now()</code> values before and after to get the total time in milliseconds to a high degree of accuracy. Use <code>Math.min()</code> to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function. Omit the second argument, <code>iterations</code>, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">mostPerformant</span> <span class="token operator">=</span> <span class="token punctuation">(</span>fns<span class="token punctuation">,</span> iterations <span class="token operator">=</span> <span class="token number">10000</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>