Merge branch 'master' into new-snippets
This commit is contained in:
@ -3679,17 +3679,17 @@ hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then
|
||||
|
||||
Hides all the elements specified.
|
||||
|
||||
Use the spread operator (`...`) and `Array.forEach()` to apply `display: none` to each element specified.
|
||||
Use `NodeList.prototype.forEach()` to apply `display: none` to each element specified.
|
||||
|
||||
```js
|
||||
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||
const hide = els => els.forEach(e => (e.style.display = 'none'));
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
|
||||
hide(document.querySelectorAll('img')); // Hides all <img> elements on the page
|
||||
```
|
||||
|
||||
</details>
|
||||
@ -4301,7 +4301,7 @@ const formatDuration = ms => {
|
||||
};
|
||||
return Object.entries(time)
|
||||
.filter(val => val[1] !== 0)
|
||||
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
|
||||
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
|
||||
.join(', ');
|
||||
};
|
||||
```
|
||||
|
||||
@ -199,8 +199,8 @@ hub<span class="token punctuation">.</span><span class="token function">off</spa
|
||||
<span class="token keyword">return</span> hexes<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">);
|
||||
});</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">hashBrowser</span><span class="token punctuation">(</span><span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">({</span> a<span class="token punctuation">:</span> <span class="token string">'a'</span><span class="token punctuation">,</span> b<span class="token punctuation">: [</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">],</span> foo<span class="token punctuation">: {</span> c<span class="token punctuation">:</span> <span class="token string">'bar'</span> <span class="token punctuation">} })).</span><span class="token function">then</span><span class="token punctuation">(</span>console<span class="token punctuation">.</span>log<span class="token punctuation">);</span> <span class="token comment">// '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'</span>
|
||||
</pre><button class="primary clipboard-copy">📋 Copy to clipboard</button></div></div><div class="card fluid"><h3 id="hide" class="section double-padded">hide</h3><div class="section double-padded"><p>Hides all the elements specified.</p><p>Use the spread operator (<code>...</code>) and <code>Array.forEach()</code> to apply <code>display: none</code> to each element specified.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">hide</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">...</span>el<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token operator">...</span>el<span class="token punctuation">].</span><span class="token function">forEach</span><span class="token punctuation">(</span>e <span class="token operator">=></span> <span class="token punctuation">(</span>e<span class="token punctuation">.</span>style<span class="token punctuation">.</span>display <span class="token operator">=</span> <span class="token string">'none'</span><span class="token punctuation">));</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">hide</span><span class="token punctuation">(</span><span class="token operator">...</span>document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">'img'</span><span class="token punctuation">));</span> <span class="token comment">// Hides all <img> elements on the page</span>
|
||||
</pre><button class="primary clipboard-copy">📋 Copy to clipboard</button></div></div><div class="card fluid"><h3 id="hide" class="section double-padded">hide</h3><div class="section double-padded"><p>Hides all the elements specified.</p><p>Use <code>NodeList.prototype.forEach()</code> to apply <code>display: none</code> to each element specified.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">hide</span> <span class="token operator">=</span> els <span class="token operator">=></span> els<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span>e <span class="token operator">=></span> <span class="token punctuation">(</span>e<span class="token punctuation">.</span>style<span class="token punctuation">.</span>display <span class="token operator">=</span> <span class="token string">'none'</span><span class="token punctuation">));</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">hide</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">querySelectorAll</span><span class="token punctuation">(</span><span class="token string">'img'</span><span class="token punctuation">));</span> <span class="token comment">// Hides all <img> elements on the page</span>
|
||||
</pre><button class="primary clipboard-copy">📋 Copy to clipboard</button></div></div><div class="card fluid"><h3 id="httpsredirect" class="section double-padded">httpsRedirect</h3><div class="section double-padded"><p>Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.</p><p>Use <code>location.protocol</code> to get the protocol currently being used. If it's not HTTPS, use <code>location.replace()</code> to replace the existing page with the HTTPS version of the page. Use <code>location.href</code> to get the full address, split it with <code>String.split()</code> and remove the protocol part of the URL.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">httpsRedirect</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">if</span> <span class="token punctuation">(</span>location<span class="token punctuation">.</span>protocol <span class="token operator">!==</span> <span class="token string">'https:'</span><span class="token punctuation">)</span> location<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">'https://'</span> <span class="token operator">+</span> location<span class="token punctuation">.</span>href<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'//'</span><span class="token punctuation">)[</span><span class="token number">1</span><span class="token punctuation">]);
|
||||
};</span>
|
||||
|
||||
@ -90,7 +90,7 @@
|
||||
<span class="token punctuation">};</span>
|
||||
<span class="token keyword">return</span> Object<span class="token punctuation">.</span><span class="token function">entries</span><span class="token punctuation">(</span>time<span class="token punctuation">)
|
||||
.</span><span class="token function">filter</span><span class="token punctuation">(</span>val <span class="token operator">=></span> val<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">!==</span> <span class="token number">0</span><span class="token punctuation">)
|
||||
.</span><span class="token function">map</span><span class="token punctuation">(</span>val <span class="token operator">=></span> val<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token string">' '</span> <span class="token operator">+</span> <span class="token punctuation">(</span>val<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">!==</span> <span class="token number">1</span> <span class="token operator">?</span> val<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token string">'s'</span> <span class="token punctuation">:</span> val<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]))
|
||||
.</span><span class="token function">map</span><span class="token punctuation">(([</span>key<span class="token punctuation">,</span> val<span class="token punctuation">])</span> <span class="token operator">=></span> <span class="token template-string"><span class="token string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>val<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>key<span class="token interpolation-punctuation punctuation">}</span></span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>val <span class="token operator">!==</span> <span class="token number">1</span> <span class="token operator">?</span> <span class="token string">'s'</span> <span class="token punctuation">:</span> <span class="token string">''</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span><span class="token punctuation">)
|
||||
.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">', '</span><span class="token punctuation">);
|
||||
};</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">formatDuration</span><span class="token punctuation">(</span><span class="token number">1001</span><span class="token punctuation">);</span> <span class="token comment">// '1 second, 1 millisecond'</span>
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1692,7 +1692,7 @@
|
||||
"fileName": "formatDuration.md",
|
||||
"text": "Returns the human readable format of the given number of milliseconds.\n\nDivide `ms` with the appropriate values to obtain the appropriate values for `day`, `hour`, `minute`, `second` and `millisecond`.\nUse `Object.entries()` with `Array.filter()` to keep only non-zero values.\nUse `Array.map()` to create the string for each value, pluralizing appropriately.\nUse `String.join(', ')` to combine the values into a string.",
|
||||
"codeBlocks": [
|
||||
"const formatDuration = ms => {\n if (ms < 0) ms = -ms;\n const time = {\n day: Math.floor(ms / 86400000),\n hour: Math.floor(ms / 3600000) % 24,\n minute: Math.floor(ms / 60000) % 60,\n second: Math.floor(ms / 1000) % 60,\n millisecond: Math.floor(ms) % 1000\n };\n return Object.entries(time)\n .filter(val => val[1] !== 0)\n .map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))\n .join(', ');\n};",
|
||||
"const formatDuration = ms => {\n if (ms < 0) ms = -ms;\n const time = {\n day: Math.floor(ms / 86400000),\n hour: Math.floor(ms / 3600000) % 24,\n minute: Math.floor(ms / 60000) % 60,\n second: Math.floor(ms / 1000) % 60,\n millisecond: Math.floor(ms) % 1000\n };\n return Object.entries(time)\n .filter(val => val[1] !== 0)\n .map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)\n .join(', ');\n};",
|
||||
"formatDuration(1001); // '1 second, 1 millisecond'\nformatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'"
|
||||
],
|
||||
"tags": [
|
||||
@ -1704,7 +1704,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "79051bd95886abf6856585481e3c9cb0685e197bad764a56eb583bd3421f3449"
|
||||
"hash": "fcaccacf92e1a1e5f8610cf78b840a6b897fc5e6cadb54d7a32efadb71b99f80"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -2166,10 +2166,10 @@
|
||||
"type": "snippet",
|
||||
"attributes": {
|
||||
"fileName": "hide.md",
|
||||
"text": "Hides all the elements specified.\n\nUse the spread operator (`...`) and `Array.forEach()` to apply `display: none` to each element specified.",
|
||||
"text": "Hides all the elements specified.\n\nUse `NodeList.prototype.forEach()` to apply `display: none` to each element specified.",
|
||||
"codeBlocks": [
|
||||
"const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));",
|
||||
"hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page"
|
||||
"const hide = els => els.forEach(e => (e.style.display = 'none'));",
|
||||
"hide(document.querySelectorAll('img')); // Hides all <img> elements on the page"
|
||||
],
|
||||
"tags": [
|
||||
"browser",
|
||||
@ -2178,7 +2178,7 @@
|
||||
},
|
||||
"meta": {
|
||||
"archived": false,
|
||||
"hash": "936ca95ab4a3a012580a45574f77cb8f8c2b70d60e8506627bf4eb2ef8743fa2"
|
||||
"hash": "8b7b70809f93fd9392315a5c63aa4cbbf9b45eb1165a7d44db314186d407816b"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -19,7 +19,7 @@ const formatDuration = ms => {
|
||||
};
|
||||
return Object.entries(time)
|
||||
.filter(val => val[1] !== 0)
|
||||
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
|
||||
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
|
||||
.join(', ');
|
||||
};
|
||||
```
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
|
||||
Hides all the elements specified.
|
||||
|
||||
Use the spread operator (`...`) and `Array.forEach()` to apply `display: none` to each element specified.
|
||||
Use `NodeList.prototype.forEach()` to apply `display: none` to each element specified.
|
||||
|
||||
```js
|
||||
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||
const hide = els => els.forEach(e => (e.style.display = 'none'));
|
||||
```
|
||||
|
||||
```js
|
||||
hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
|
||||
hide(document.querySelectorAll('img')); // Hides all <img> elements on the page
|
||||
```
|
||||
|
||||
@ -168,7 +168,7 @@
|
||||
<span class="contribution-number">2</span>
|
||||
<div class="section">
|
||||
<h3>Tag</h3>
|
||||
<p style="text-align: justify">Run <code>npm run tagger</code> from your terminal, then open the tag_database file and tag your snippet appropriately. Multitagging is also supported, just make sure the first tag you specify is on of the major tags and the one that is most relevant to the implemneted function.</p>
|
||||
<p style="text-align: justify">Run <code>npm run tagger</code> from your terminal, then open the tag_database file and tag your snippet appropriately. Multitagging is also supported, just make sure the first tag you specify is on of the major tags and the one that is most relevant to the implemented function.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card fluid contribution-guideline">
|
||||
|
||||
@ -9,7 +9,7 @@ const formatDuration = ms => {
|
||||
};
|
||||
return Object.entries(time)
|
||||
.filter(val => val[1] !== 0)
|
||||
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0]))
|
||||
.map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
|
||||
.join(', ');
|
||||
};
|
||||
module.exports = formatDuration;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const hide = (...el) => [...el].forEach(e => (e.style.display = 'none'));
|
||||
const hide = els => els.forEach(e => (e.style.display = 'none'));
|
||||
module.exports = hide;
|
||||
|
||||
3124
test/testlog
3124
test/testlog
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user