Merge branch 'master' into isPrimitive
This commit is contained in:
495
README.md
495
README.md
@ -9,12 +9,13 @@
|
|||||||
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
||||||
- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
|
- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
|
||||||
- Snippets are written in ES6, use the [Babel transpiler](https://babeljs.io/) to ensure backwards-compatibility.
|
- Snippets are written in ES6, use the [Babel transpiler](https://babeljs.io/) to ensure backwards-compatibility.
|
||||||
|
- You can import these snippets into your text editor of choice (VSCode, Atom, Sublime) using the files found in [this repo](https://github.com/Rob-Rychs/30-seconds-of-code-texteditorsnippets).
|
||||||
- You can import these snippets into Alfred 3, using [this file](https://github.com/lslvxy/30-seconds-of-code-alfredsnippets).
|
- You can import these snippets into Alfred 3, using [this file](https://github.com/lslvxy/30-seconds-of-code-alfredsnippets).
|
||||||
- You can find a package with all the snippets on [npm](https://www.npmjs.com/package/tsoc). Bear in mind that most of these snippets are not production-ready.
|
- You can find a package with all the snippets on [npm](https://www.npmjs.com/package/tsoc). Bear in mind that most of these snippets are not production-ready.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
### Adapter
|
### 🔌 Adapter
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -28,7 +29,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Array
|
### 📚 Array
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -63,6 +64,7 @@
|
|||||||
* [`quickSort`](#quicksort)
|
* [`quickSort`](#quicksort)
|
||||||
* [`remove`](#remove)
|
* [`remove`](#remove)
|
||||||
* [`sample`](#sample)
|
* [`sample`](#sample)
|
||||||
|
* [`sampleSize`](#samplesize)
|
||||||
* [`shuffle`](#shuffle)
|
* [`shuffle`](#shuffle)
|
||||||
* [`similarity`](#similarity)
|
* [`similarity`](#similarity)
|
||||||
* [`symmetricDifference`](#symmetricdifference)
|
* [`symmetricDifference`](#symmetricdifference)
|
||||||
@ -76,13 +78,14 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Browser
|
### 🌐 Browser
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
* [`arrayToHtmlList`](#arraytohtmllist)
|
* [`arrayToHtmlList`](#arraytohtmllist)
|
||||||
* [`bottomVisible`](#bottomvisible)
|
* [`bottomVisible`](#bottomvisible)
|
||||||
|
* [`copyToClipboard`](#copytoclipboard)
|
||||||
* [`currentURL`](#currenturl)
|
* [`currentURL`](#currenturl)
|
||||||
* [`detectDeviceType`](#detectdevicetype)
|
* [`detectDeviceType`](#detectdevicetype)
|
||||||
* [`elementIsVisibleInViewport`](#elementisvisibleinviewport)
|
* [`elementIsVisibleInViewport`](#elementisvisibleinviewport)
|
||||||
@ -97,12 +100,13 @@
|
|||||||
* [`scrollToTop`](#scrolltotop)
|
* [`scrollToTop`](#scrolltotop)
|
||||||
* [`setStyle`](#setstyle)
|
* [`setStyle`](#setstyle)
|
||||||
* [`show`](#show)
|
* [`show`](#show)
|
||||||
|
* [`speechSynthesis`](#speechsynthesis)
|
||||||
* [`toggleClass`](#toggleclass)
|
* [`toggleClass`](#toggleclass)
|
||||||
* [`UUIDGeneratorBrowser`](#uuidgeneratorbrowser)
|
* [`UUIDGeneratorBrowser`](#uuidgeneratorbrowser)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Date
|
### ⏱️ Date
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -114,7 +118,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Function
|
### 🎛️ Function
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -123,12 +127,13 @@
|
|||||||
* [`compose`](#compose)
|
* [`compose`](#compose)
|
||||||
* [`curry`](#curry)
|
* [`curry`](#curry)
|
||||||
* [`functionName`](#functionname)
|
* [`functionName`](#functionname)
|
||||||
|
* [`memoize`](#memoize)
|
||||||
* [`runPromisesInSeries`](#runpromisesinseries)
|
* [`runPromisesInSeries`](#runpromisesinseries)
|
||||||
* [`sleep`](#sleep)
|
* [`sleep`](#sleep)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Logic
|
### 🔮 Logic
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -137,7 +142,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Math
|
### ➗ Math
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -173,16 +178,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Media
|
### 📦 Node
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>View contents</summary>
|
|
||||||
|
|
||||||
* [`speechSynthesis`](#speechsynthesis)
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Node
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -193,7 +189,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Object
|
### 🗃️ Object
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -205,11 +201,12 @@
|
|||||||
* [`orderBy`](#orderby)
|
* [`orderBy`](#orderby)
|
||||||
* [`select`](#select)
|
* [`select`](#select)
|
||||||
* [`shallowClone`](#shallowclone)
|
* [`shallowClone`](#shallowclone)
|
||||||
|
* [`size`](#size)
|
||||||
* [`truthCheckCollection`](#truthcheckcollection)
|
* [`truthCheckCollection`](#truthcheckcollection)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### String
|
### 📜 String
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -222,6 +219,7 @@
|
|||||||
* [`escapeHTML`](#escapehtml)
|
* [`escapeHTML`](#escapehtml)
|
||||||
* [`escapeRegExp`](#escaperegexp)
|
* [`escapeRegExp`](#escaperegexp)
|
||||||
* [`fromCamelCase`](#fromcamelcase)
|
* [`fromCamelCase`](#fromcamelcase)
|
||||||
|
* [`isAbsoluteURL`](#isabsoluteurl)
|
||||||
* [`palindrome`](#palindrome)
|
* [`palindrome`](#palindrome)
|
||||||
* [`repeatString`](#repeatstring)
|
* [`repeatString`](#repeatstring)
|
||||||
* [`reverseString`](#reversestring)
|
* [`reverseString`](#reversestring)
|
||||||
@ -236,7 +234,7 @@
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Utility
|
### 💎 Utility
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
@ -247,11 +245,15 @@
|
|||||||
* [`getType`](#gettype)
|
* [`getType`](#gettype)
|
||||||
* [`hexToRGB`](#hextorgb)
|
* [`hexToRGB`](#hextorgb)
|
||||||
* [`isArray`](#isarray)
|
* [`isArray`](#isarray)
|
||||||
|
* [`isArrayLike`](#isarraylike)
|
||||||
* [`isBoolean`](#isboolean)
|
* [`isBoolean`](#isboolean)
|
||||||
* [`isFunction`](#isfunction)
|
* [`isFunction`](#isfunction)
|
||||||
|
* [`isNull`](#isnull)
|
||||||
* [`isNumber`](#isnumber)
|
* [`isNumber`](#isnumber)
|
||||||
|
* [`isPromiseLike`](#ispromiselike)
|
||||||
* [`isString`](#isstring)
|
* [`isString`](#isstring)
|
||||||
* [`isSymbol`](#issymbol)
|
* [`isSymbol`](#issymbol)
|
||||||
|
* [`isValidJSON`](#isvalidjson)
|
||||||
* [`randomHexColorCode`](#randomhexcolorcode)
|
* [`randomHexColorCode`](#randomhexcolorcode)
|
||||||
* [`RGBToHex`](#rgbtohex)
|
* [`RGBToHex`](#rgbtohex)
|
||||||
* [`sdbm`](#sdbm)
|
* [`sdbm`](#sdbm)
|
||||||
@ -259,10 +261,21 @@
|
|||||||
* [`toDecimalMark`](#todecimalmark)
|
* [`toDecimalMark`](#todecimalmark)
|
||||||
* [`toOrdinalSuffix`](#toordinalsuffix)
|
* [`toOrdinalSuffix`](#toordinalsuffix)
|
||||||
* [`validateNumber`](#validatenumber)
|
* [`validateNumber`](#validatenumber)
|
||||||
|
* [`yesNo`](#yesno)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Adapter
|
### _Uncategorized_
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`sortedIndex`](#sortedindex)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
---
|
||||||
|
## 🔌 Adapter
|
||||||
|
|
||||||
### call
|
### call
|
||||||
|
|
||||||
@ -424,7 +437,8 @@ arrayMax([1, 2, 4]); // 4
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Array
|
---
|
||||||
|
## 📚 Array
|
||||||
|
|
||||||
### chunk
|
### chunk
|
||||||
|
|
||||||
@ -1190,6 +1204,38 @@ sample([3, 7, 9, 11]); // 9
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### sampleSize
|
||||||
|
|
||||||
|
Gets `n` random elements at unique keys from `array` up to the size of `array`.
|
||||||
|
|
||||||
|
Shuffle the array using the [Fisher-Yates algorithm](https://github.com/chalarangelo/30-seconds-of-code#shuffle).
|
||||||
|
Use `Array.slice()` to get the first `n` elements.
|
||||||
|
Omit the second argument, `n` to get only one element at random from the array.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const sampleSize = ([...arr], n = 1) => {
|
||||||
|
let m = arr.length;
|
||||||
|
while (m) {
|
||||||
|
const i = Math.floor(Math.random() * m--);
|
||||||
|
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||||
|
}
|
||||||
|
return arr.slice(0, n);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
sampleSize([1, 2, 3], 2); // [3,1]
|
||||||
|
sampleSize([1, 2, 3], 4); // [2,3,1]
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### shuffle
|
### shuffle
|
||||||
|
|
||||||
Randomizes the order of the values of an array, returning a new array.
|
Randomizes the order of the values of an array, returning a new array.
|
||||||
@ -1437,7 +1483,8 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Browser
|
---
|
||||||
|
## 🌐 Browser
|
||||||
|
|
||||||
### arrayToHtmlList
|
### arrayToHtmlList
|
||||||
|
|
||||||
@ -1486,6 +1533,48 @@ bottomVisible(); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### copyToClipboard
|
||||||
|
|
||||||
|
Copy a string to the clipboard. Only works as a result of user action (i.e. inside a `click` event listener).
|
||||||
|
|
||||||
|
Create a new `<textarea>` element, fill it with the supplied data and add it to the HTML document.
|
||||||
|
Use `Selection.getRangeAt()`to store the selected range (if any).
|
||||||
|
Use `document.execCommand('copy')` to copy to the clipboard.
|
||||||
|
Remove the `<textarea>` element from the HTML document.
|
||||||
|
Finally, use `Selection().addRange()` to recover the original selected range (if any).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const copyToClipboard = str => {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
const selected =
|
||||||
|
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### currentURL
|
### currentURL
|
||||||
|
|
||||||
Returns the current URL.
|
Returns the current URL.
|
||||||
@ -1842,6 +1931,35 @@ show(document.querySelectorAll('img')); // Shows all <img> elements on the page
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### speechSynthesis
|
||||||
|
|
||||||
|
Performs speech synthesis (experimental).
|
||||||
|
|
||||||
|
Use `SpeechSynthesisUtterance.voice` and `window.speechSynthesis.getVoices()` to convert a message to speech.
|
||||||
|
Use `window.speechSynthesis.speak()` to play the message.
|
||||||
|
|
||||||
|
Learn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const speechSynthesis = message => {
|
||||||
|
const msg = new SpeechSynthesisUtterance(message);
|
||||||
|
msg.voice = window.speechSynthesis.getVoices()[0];
|
||||||
|
window.speechSynthesis.speak(msg);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
speechSynthesis('Hello, World'); // // plays the message
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### toggleClass
|
### toggleClass
|
||||||
|
|
||||||
Toggle a class for an element.
|
Toggle a class for an element.
|
||||||
@ -1888,7 +2006,8 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Date
|
---
|
||||||
|
## ⏱️ Date
|
||||||
|
|
||||||
### getDaysDiffBetweenDates
|
### getDaysDiffBetweenDates
|
||||||
|
|
||||||
@ -1988,7 +2107,8 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Function
|
---
|
||||||
|
## 🎛️ Function
|
||||||
|
|
||||||
### chainAsync
|
### chainAsync
|
||||||
|
|
||||||
@ -2103,6 +2223,35 @@ functionName(Math.max); // max (logged in debug channel of console)
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### memoize
|
||||||
|
|
||||||
|
Returns the memoized (cached) function.
|
||||||
|
|
||||||
|
Use `Object.create(null)` to create an empty object without `Object.prototype` (so that those properties are not resolved if the input value is something like `'hasOwnProperty'`).
|
||||||
|
Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const memoize = fn => {
|
||||||
|
const cache = Object.create(null);
|
||||||
|
return value => cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
// See the `anagrams` snippet.
|
||||||
|
const anagramsCached = memoize(anagrams);
|
||||||
|
anagramsCached('javascript'); // takes a long time
|
||||||
|
anagramsCached('javascript'); // returns virtually instantly since it's now cached
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### runPromisesInSeries
|
### runPromisesInSeries
|
||||||
|
|
||||||
Runs an array of promises in series.
|
Runs an array of promises in series.
|
||||||
@ -2151,7 +2300,8 @@ async function sleepyWork() {
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Logic
|
---
|
||||||
|
## 🔮 Logic
|
||||||
|
|
||||||
### negate
|
### negate
|
||||||
|
|
||||||
@ -2175,7 +2325,8 @@ negate(isOdd)(1); // false
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Math
|
---
|
||||||
|
## ➗ Math
|
||||||
|
|
||||||
### average
|
### average
|
||||||
|
|
||||||
@ -2398,7 +2549,7 @@ const fibonacciUntilNum = num => {
|
|||||||
<summary>Examples</summary>
|
<summary>Examples</summary>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fibonacciCountUntilNum(10); // 7
|
fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@ -2568,7 +2719,7 @@ Return `false` if any of them divides the given number, else return `true`, unle
|
|||||||
```js
|
```js
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i == 0) return false;
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -2880,37 +3031,8 @@ sum([1, 2, 3, 4]); // 10
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Media
|
---
|
||||||
|
## 📦 Node
|
||||||
### speechSynthesis
|
|
||||||
|
|
||||||
Performs speech synthesis (experimental).
|
|
||||||
|
|
||||||
Use `SpeechSynthesisUtterance.voice` and `window.speechSynthesis.getVoices()` to convert a message to speech.
|
|
||||||
Use `window.speechSynthesis.speak()` to play the message.
|
|
||||||
|
|
||||||
Learn more about the [SpeechSynthesisUtterance interface of the Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance).
|
|
||||||
|
|
||||||
```js
|
|
||||||
const speechSynthesis = message => {
|
|
||||||
const msg = new SpeechSynthesisUtterance(message);
|
|
||||||
msg.voice = window.speechSynthesis.getVoices()[0];
|
|
||||||
window.speechSynthesis.speak(msg);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>Examples</summary>
|
|
||||||
|
|
||||||
```js
|
|
||||||
speechSynthesis('Hello, World'); // // plays the message
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
|
||||||
|
|
||||||
## Node
|
|
||||||
|
|
||||||
### JSONToFile
|
### JSONToFile
|
||||||
|
|
||||||
@ -2999,7 +3121,8 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Object
|
---
|
||||||
|
## 🗃️ Object
|
||||||
|
|
||||||
### cleanObj
|
### cleanObj
|
||||||
|
|
||||||
@ -3193,6 +3316,40 @@ a === b; // false
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### size
|
||||||
|
|
||||||
|
Get size of arrays, objects or strings.
|
||||||
|
|
||||||
|
Get type of `value` (`array`, `object` or `string`).
|
||||||
|
Use `length` property for arrays.
|
||||||
|
Use `length` or `size` value if available or number of keys for objects.
|
||||||
|
Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `value` for strings.
|
||||||
|
|
||||||
|
Split strings into array of characters with `split('')` and return its length.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const size = value =>
|
||||||
|
Array.isArray(value)
|
||||||
|
? value.length
|
||||||
|
: value && typeof value === 'object'
|
||||||
|
? value.size || value.length || Object.keys(value).length
|
||||||
|
: typeof value === 'string' ? new Blob([value]).size : 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
size([1, 2, 3, 4, 5]); // 5
|
||||||
|
size('size'); // 4
|
||||||
|
size({ one: 1, two: 2, three: 3 }); // 3
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### truthCheckCollection
|
### truthCheckCollection
|
||||||
|
|
||||||
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
||||||
@ -3214,7 +3371,8 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## String
|
---
|
||||||
|
## 📜 String
|
||||||
|
|
||||||
### anagrams
|
### anagrams
|
||||||
|
|
||||||
@ -3273,7 +3431,7 @@ byteSize('Hello World'); // 11
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### Capitalize
|
### capitalize
|
||||||
|
|
||||||
Capitalizes the first letter of a string.
|
Capitalizes the first letter of a string.
|
||||||
|
|
||||||
@ -3427,6 +3585,30 @@ fromCamelCase('someJavascriptProperty', '_'); // 'some_javascript_property'
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isAbsoluteURL
|
||||||
|
|
||||||
|
Returns `true` if the given string is an absolute URL, `false` otherwise.
|
||||||
|
|
||||||
|
Use a regular expression to test if the string is an absolute URL.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isAbsoluteURL('https://google.com'); // true
|
||||||
|
isAbsoluteURL('ftp://www.myserver.net'); // true
|
||||||
|
isAbsoluteURL('/foo/bar'); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### palindrome
|
### palindrome
|
||||||
|
|
||||||
Returns `true` if the given string is a palindrome, `false` otherwise.
|
Returns `true` if the given string is a palindrome, `false` otherwise.
|
||||||
@ -3633,13 +3815,12 @@ Break the string into words and combine them using `_` as a separator.
|
|||||||
For more detailed explanation of this Regex, [visit this Site](https://regex101.com/r/bMCgAB/1).
|
For more detailed explanation of this Regex, [visit this Site](https://regex101.com/r/bMCgAB/1).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const toSnakeCase = str => {
|
const toSnakeCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('_');
|
.join('_');
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -3738,7 +3919,8 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
## Utility
|
---
|
||||||
|
## 💎 Utility
|
||||||
|
|
||||||
### coalesce
|
### coalesce
|
||||||
|
|
||||||
@ -3902,6 +4084,35 @@ isArray([1]); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isArrayLike
|
||||||
|
|
||||||
|
Checks if the provided argument is array-like (i.e. is iterable).
|
||||||
|
|
||||||
|
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isArrayLike = val =>
|
||||||
|
val != null &&
|
||||||
|
typeof val != 'function' &&
|
||||||
|
val.length > -1 &&
|
||||||
|
val.length % 1 == 0 &&
|
||||||
|
val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isArrayLike(document.querySelectorAll('.className')); // true
|
||||||
|
isArrayLike('abc'); // true
|
||||||
|
isArrayLike(null); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### isBoolean
|
### isBoolean
|
||||||
|
|
||||||
Checks if the given argument is a native boolean element.
|
Checks if the given argument is a native boolean element.
|
||||||
@ -3948,6 +4159,29 @@ isFunction(x => x); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isNull
|
||||||
|
|
||||||
|
Returns `true` if the specified value is `null`, `false` otherwise.
|
||||||
|
|
||||||
|
Use the strict equality operator to check if the value and of `val` are equal to `null`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isNull = val => val === null;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isNull(null); // true
|
||||||
|
isNull('null'); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### isNumber
|
### isNumber
|
||||||
|
|
||||||
Checks if the given argument is a number.
|
Checks if the given argument is a number.
|
||||||
@ -3970,6 +4204,37 @@ isNumber(1); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isPromiseLike
|
||||||
|
|
||||||
|
Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise.
|
||||||
|
|
||||||
|
Check if the object is not `null`, its `typeof` matches either `object` or `function` and if it has a `.then` property, which is also a `function`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isPromiseLike = obj =>
|
||||||
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isPromiseLike({
|
||||||
|
then: function() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}); // true
|
||||||
|
isPromiseLike(null); // false
|
||||||
|
isPromiseLike({}); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### isString
|
### isString
|
||||||
|
|
||||||
Checks if the given argument is a string.
|
Checks if the given argument is a string.
|
||||||
@ -4016,6 +4281,37 @@ isSymbol(Symbol('x')); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### isValidJSON
|
||||||
|
|
||||||
|
Checks if the provided argument is a valid JSON.
|
||||||
|
|
||||||
|
Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isValidJSON = obj => {
|
||||||
|
try {
|
||||||
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
isValidJSON('{"name":"Adam","age":20}'); // true
|
||||||
|
isValidJSON('{"name":"Adam",age:"20"}'); // false
|
||||||
|
isValidJSON(null); // true
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### randomHexColorCode
|
### randomHexColorCode
|
||||||
|
|
||||||
Generates a random hexadecimal color code.
|
Generates a random hexadecimal color code.
|
||||||
@ -4200,6 +4496,65 @@ validateNumber('10'); // true
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### yesNo
|
||||||
|
|
||||||
|
Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`.
|
||||||
|
|
||||||
|
Use `RegExp.test()` to check if the string evaluates to `y/yes` or `n/no`.
|
||||||
|
Omit the second argument, `def` to set the default answer as `no`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const yesNo = (val, def = false) =>
|
||||||
|
/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
yesNo('Y'); // true
|
||||||
|
yesNo('yes'); // true
|
||||||
|
yesNo('No'); // false
|
||||||
|
yesNo('Foo', true); // true
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
---
|
||||||
|
## _Uncategorized_
|
||||||
|
|
||||||
|
### sortedIndex
|
||||||
|
|
||||||
|
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
||||||
|
|
||||||
|
Check if the array is sorted in descending order (loosely).
|
||||||
|
Use `Array.findIndex()` to find the appropriate index where the element should be inserted.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const sortedIndex = (arr, n) => {
|
||||||
|
const isDescending = arr[0] > arr[arr.length - 1];
|
||||||
|
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||||
|
return index === -1 ? arr.length : index;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
sortedIndex([5, 3, 2, 1], 4); // 1
|
||||||
|
sortedIndex([30, 50], 40); // 1
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>[⬆ back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
## Collaborators
|
||||||
|
|
||||||
|
| [<img src="https://github.com/Chalarangelo.png" width="100px;"/>](https://github.com/Chalarangelo)<br/> [<sub>Angelos Chalaris</sub>](https://github.com/Chalarangelo) | [<img src="https://github.com/Pl4gue.png" width="100px;"/>](https://github.com/Pl4gue)<br/> [<sub>David Wu</sub>](https://github.com/Pl4gue) | [<img src="https://github.com/fejes713.png" width="100px;"/>](https://github.com/fejes713)<br/> [<sub>Stefan Feješ</sub>](https://github.com/fejes713) | [<img src="https://github.com/kingdavidmartins.png" width="100px;"/>](https://github.com/kingdavidmartins)<br/> [<sub>King David Martins</sub>](https://github.com/iamsoorena) | [<img src="https://github.com/iamsoorena.png" width="100px;"/>](https://github.com/iamsoorena)<br/> [<sub>Soorena Soleimani</sub>](https://github.com/iamsoorena) |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| [<img src="https://github.com/elderhsouza.png" width="100px;"/>](https://github.com/elderhsouza)<br/> [<sub>Elder Henrique Souza</sub>](https://github.com/elderhsouza) | [<img src="https://github.com/skatcat31.png" width="100px;"/>](https://github.com/skatcat31)<br/> [<sub>Robert Mennell</sub>](https://github.com/skatcat31) | [<img src="https://github.com/atomiks.png" width="100px;"/>](https://github.com/atomiks)<br/> [<sub>atomiks</sub>](https://github.com/atomiks) |
|
||||||
|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*
|
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*
|
||||||
|
|||||||
127
docs/index.html
127
docs/index.html
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -121,7 +121,7 @@ code {
|
|||||||
transform: scale(1); /* Deals with the issue described in #243 */
|
transform: scale(1); /* Deals with the issue described in #243 */
|
||||||
}
|
}
|
||||||
pre { font-size: 1rem; border: 0.0625rem solid var(--secondary-border-color); border-radius: var(--universal-border-radius);}
|
pre { font-size: 1rem; border: 0.0625rem solid var(--secondary-border-color); border-radius: var(--universal-border-radius);}
|
||||||
.group{position:relative;margin-top:2em;margin-bottom:-1em}
|
.group{position:relative;margin-top:2em;margin-bottom:1em}
|
||||||
.search{font-size:14px;margin-top:-.1em;display:block;width:100%;border:none;border-bottom:1px solid var(--nav-link-color)}
|
.search{font-size:14px;margin-top:-.1em;display:block;width:100%;border:none;border-bottom:1px solid var(--nav-link-color)}
|
||||||
.search:focus{outline:none}
|
.search:focus{outline:none}
|
||||||
label#search-label{color:var(--nav-link-color);font-size:18px;font-weight:400;position:absolute;left:5px;top:10px}
|
label#search-label{color:var(--nav-link-color);font-size:18px;font-weight:400;position:absolute;left:5px;top:10px}
|
||||||
|
|||||||
122
scripts/build.js
122
scripts/build.js
@ -3,51 +3,64 @@
|
|||||||
Run using `npm run builder`.
|
Run using `npm run builder`.
|
||||||
*/
|
*/
|
||||||
// Load modules
|
// Load modules
|
||||||
const fs = require('fs-extra'),
|
const fs = require('fs-extra');
|
||||||
path = require('path'),
|
const path = require('path');
|
||||||
chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
// Set variables for paths
|
|
||||||
const snippetsPath = './snippets',
|
const SNIPPETS_PATH = './snippets';
|
||||||
staticPartsPath = './static-parts';
|
const STATIC_PARTS_PATH = './static-parts';
|
||||||
// Set variables for script
|
|
||||||
let snippets = {},
|
const snippets = {};
|
||||||
startPart = '',
|
const EMOJIS = {
|
||||||
|
adapter: '🔌',
|
||||||
|
array: '📚',
|
||||||
|
browser: '🌐',
|
||||||
|
date: '⏱️',
|
||||||
|
function: '🎛️',
|
||||||
|
logic: '🔮',
|
||||||
|
math: '➗',
|
||||||
|
media: '📺',
|
||||||
|
node: '📦',
|
||||||
|
object: '🗃️',
|
||||||
|
string: '📜',
|
||||||
|
utility: '💎'
|
||||||
|
};
|
||||||
|
|
||||||
|
let startPart = '',
|
||||||
endPart = '',
|
endPart = '',
|
||||||
output = '',
|
output = '',
|
||||||
tagDbData = {};
|
tagDbData = {};
|
||||||
|
|
||||||
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
// Load helper functions (these are from existing snippets in 30 seconds of code!)
|
||||||
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
||||||
const capitalize = (str, lowerRest = false) =>
|
const capitalize = (str, lowerRest = false) =>
|
||||||
str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1));
|
str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1));
|
||||||
// Start the timer of the script
|
|
||||||
console.time('Builder');
|
console.time('Builder');
|
||||||
|
|
||||||
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
||||||
try {
|
try {
|
||||||
let snippetFilenames = fs.readdirSync(snippetsPath);
|
const snippetFilenames = fs
|
||||||
snippetFilenames.sort((a, b) => {
|
.readdirSync(SNIPPETS_PATH)
|
||||||
a = a.toLowerCase();
|
.sort((a, b) => a.toLowerCase() - b.toLowerCase());
|
||||||
b = b.toLowerCase();
|
|
||||||
if (a < b) return -1;
|
|
||||||
if (a > b) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
// Store the data read from each snippet in the appropriate object
|
// Store the data read from each snippet in the appropriate object
|
||||||
for (let snippet of snippetFilenames)
|
for (const name of snippetFilenames) {
|
||||||
snippets[snippet] = fs.readFileSync(path.join(snippetsPath, snippet), 'utf8');
|
snippets[name] = fs.readFileSync(path.join(SNIPPETS_PATH, name), 'utf8');
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
|
console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load static parts for the README file
|
// Load static parts for the README file
|
||||||
try {
|
try {
|
||||||
startPart = fs.readFileSync(path.join(staticPartsPath, 'README-start.md'), 'utf8');
|
startPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-start.md'), 'utf8');
|
||||||
endPart = fs.readFileSync(path.join(staticPartsPath, 'README-end.md'), 'utf8');
|
endPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-end.md'), 'utf8');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During static part loading: ${err}`);
|
console.log(`${chalk.red('ERROR!')} During static part loading: ${err}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load tag data from the database
|
// Load tag data from the database
|
||||||
try {
|
try {
|
||||||
tagDbData = objectFromPairs(
|
tagDbData = objectFromPairs(
|
||||||
@ -58,48 +71,62 @@ try {
|
|||||||
.map(v => v.split(':').slice(0, 2))
|
.map(v => v.split(':').slice(0, 2))
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the output for the README file
|
// Create the output for the README file
|
||||||
try {
|
try {
|
||||||
|
const tags = [
|
||||||
|
...new Set(
|
||||||
|
Object.entries(tagDbData)
|
||||||
|
.map(t => t[1])
|
||||||
|
.filter(v => v)
|
||||||
|
.sort((a, b) => a.localeCompare(b))
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
// Add the start static part
|
// Add the start static part
|
||||||
output += `${startPart + '\n'}`;
|
output += `${startPart + '\n'}`;
|
||||||
// Loop over tags and snippets to create the table of contents
|
|
||||||
let uncategorizedOutput = '';
|
let uncategorizedOutput = '';
|
||||||
for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))]
|
|
||||||
.filter(v => v)
|
// Loop over tags and snippets to create the table of contents
|
||||||
.sort((a, b) => a.localeCompare(b))) {
|
for (const tag of tags) {
|
||||||
if (capitalize(tag, true) == 'Uncategorized') {
|
const capitalizedTag = capitalize(tag, true);
|
||||||
uncategorizedOutput += `### _${capitalize(
|
|
||||||
tag,
|
if (capitalizedTag === 'Uncategorized') {
|
||||||
true
|
uncategorizedOutput += `### _${capitalizedTag}_\n\n<details>\n<summary>View contents</summary>\n\n`;
|
||||||
)}_\n\n<details>\n<summary>View contents</summary>\n\n`;
|
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
||||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag))
|
|
||||||
uncategorizedOutput += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`;
|
uncategorizedOutput += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`;
|
||||||
|
}
|
||||||
uncategorizedOutput += '\n</details>\n\n';
|
uncategorizedOutput += '\n</details>\n\n';
|
||||||
} else {
|
} else {
|
||||||
output += `### ${capitalize(tag, true)}\n\n<details>\n<summary>View contents</summary>\n\n`;
|
output += `### ${
|
||||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag))
|
EMOJIS[tag] || ''
|
||||||
|
} ${capitalizedTag}\n\n<details>\n<summary>View contents</summary>\n\n`;
|
||||||
|
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
||||||
output += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`;
|
output += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`;
|
||||||
|
}
|
||||||
output += '\n</details>\n\n';
|
output += '\n</details>\n\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output += uncategorizedOutput;
|
output += uncategorizedOutput;
|
||||||
uncategorizedOutput = '';
|
uncategorizedOutput = '';
|
||||||
|
|
||||||
// Loop over tags and snippets to create the list of snippets
|
// Loop over tags and snippets to create the list of snippets
|
||||||
for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))]
|
for (const tag of tags) {
|
||||||
.filter(v => v)
|
const capitalizedTag = capitalize(tag, true);
|
||||||
.sort((a, b) => a.localeCompare(b))) {
|
|
||||||
if (capitalize(tag, true) == 'Uncategorized') {
|
if (capitalizedTag == 'Uncategorized') {
|
||||||
uncategorizedOutput += `## _${capitalize(tag, true)}_\n`;
|
uncategorizedOutput += `---\n ## _${capitalizedTag}_\n`;
|
||||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag))
|
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
||||||
uncategorizedOutput += `\n${snippets[taggedSnippet[0] + '.md'] +
|
uncategorizedOutput += `\n${snippets[taggedSnippet[0] + '.md'] +
|
||||||
'\n<br>[⬆ back to top](#table-of-contents)\n\n'}`;
|
'\n<br>[⬆ back to top](#table-of-contents)\n\n'}`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
output += `## ${capitalize(tag, true)}\n`;
|
output += `---\n ## ${EMOJIS[tag] || ''} ${capitalizedTag}\n`;
|
||||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
||||||
let data = snippets[taggedSnippet[0] + '.md'];
|
let data = snippets[taggedSnippet[0] + '.md'];
|
||||||
data =
|
data =
|
||||||
data.slice(0, data.lastIndexOf('```js')) +
|
data.slice(0, data.lastIndexOf('```js')) +
|
||||||
@ -111,17 +138,16 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output += uncategorizedOutput;
|
output += uncategorizedOutput;
|
||||||
// Add the ending static part
|
// Add the ending static part
|
||||||
output += `\n${endPart + '\n'}`;
|
output += `\n${endPart + '\n'}`;
|
||||||
// Write to the README file
|
// Write to the README file
|
||||||
fs.writeFileSync('README.md', output);
|
fs.writeFileSync('README.md', output);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During README generation: ${err}`);
|
console.log(`${chalk.red('ERROR!')} During README generation: ${err}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
// Log a success message
|
|
||||||
console.log(`${chalk.green('SUCCESS!')} README file generated!`);
|
console.log(`${chalk.green('SUCCESS!')} README file generated!`);
|
||||||
// Log the time taken
|
|
||||||
console.timeEnd('Builder');
|
console.timeEnd('Builder');
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
### Capitalize
|
### capitalize
|
||||||
|
|
||||||
Capitalizes the first letter of a string.
|
Capitalizes the first letter of a string.
|
||||||
|
|
||||||
|
|||||||
33
snippets/copyToClipboard.md
Normal file
33
snippets/copyToClipboard.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
### copyToClipboard
|
||||||
|
|
||||||
|
Copy a string to the clipboard. Only works as a result of user action (i.e. inside a `click` event listener).
|
||||||
|
|
||||||
|
Create a new `<textarea>` element, fill it with the supplied data and add it to the HTML document.
|
||||||
|
Use `Selection.getRangeAt()`to store the selected range (if any).
|
||||||
|
Use `document.execCommand('copy')` to copy to the clipboard.
|
||||||
|
Remove the `<textarea>` element from the HTML document.
|
||||||
|
Finally, use `Selection().addRange()` to recover the original selected range (if any).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const copyToClipboard = str => {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = str;
|
||||||
|
el.setAttribute('readonly', '');
|
||||||
|
el.style.position = 'absolute';
|
||||||
|
el.style.left = '-9999px';
|
||||||
|
document.body.appendChild(el);
|
||||||
|
const selected =
|
||||||
|
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
if (selected) {
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
document.getSelection().addRange(selected);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
|
||||||
|
```
|
||||||
@ -17,5 +17,5 @@ const fibonacciUntilNum = num => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fibonacciCountUntilNum(10); // 7
|
fibonacciUntilNum(10); // [ 0, 1, 1, 2, 3, 5, 8 ]
|
||||||
```
|
```
|
||||||
|
|||||||
15
snippets/isAbsoluteURL.md
Normal file
15
snippets/isAbsoluteURL.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
### isAbsoluteURL
|
||||||
|
|
||||||
|
Returns `true` if the given string is an absolute URL, `false` otherwise.
|
||||||
|
|
||||||
|
Use a regular expression to test if the string is an absolute URL.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isAbsoluteURL('https://google.com'); // true
|
||||||
|
isAbsoluteURL('ftp://www.myserver.net'); // true
|
||||||
|
isAbsoluteURL('/foo/bar'); // false
|
||||||
|
```
|
||||||
20
snippets/isArrayLike.md
Normal file
20
snippets/isArrayLike.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
### isArrayLike
|
||||||
|
|
||||||
|
Checks if the provided argument is array-like (i.e. is iterable).
|
||||||
|
|
||||||
|
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isArrayLike = val =>
|
||||||
|
val != null &&
|
||||||
|
typeof val != 'function' &&
|
||||||
|
val.length > -1 &&
|
||||||
|
val.length % 1 == 0 &&
|
||||||
|
val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isArrayLike(document.querySelectorAll('.className')); // true
|
||||||
|
isArrayLike('abc'); // true
|
||||||
|
isArrayLike(null); // false
|
||||||
|
```
|
||||||
14
snippets/isNull.md
Normal file
14
snippets/isNull.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
### isNull
|
||||||
|
|
||||||
|
Returns `true` if the specified value is `null`, `false` otherwise.
|
||||||
|
|
||||||
|
Use the strict equality operator to check if the value and of `val` are equal to `null`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isNull = val => val === null;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isNull(null); // true
|
||||||
|
isNull('null'); // false
|
||||||
|
```
|
||||||
@ -8,7 +8,7 @@ Return `false` if any of them divides the given number, else return `true`, unle
|
|||||||
```js
|
```js
|
||||||
const isPrime = num => {
|
const isPrime = num => {
|
||||||
const boundary = Math.floor(Math.sqrt(num));
|
const boundary = Math.floor(Math.sqrt(num));
|
||||||
for (var i = 2; i * i <= boundary; i++) if (num % i == 0) return false;
|
for (var i = 2; i <= boundary; i++) if (num % i == 0) return false;
|
||||||
return num >= 2;
|
return num >= 2;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
22
snippets/isPromiseLike.md
Normal file
22
snippets/isPromiseLike.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
### isPromiseLike
|
||||||
|
|
||||||
|
Returns `true` if an object looks like a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), `false` otherwise.
|
||||||
|
|
||||||
|
Check if the object is not `null`, its `typeof` matches either `object` or `function` and if it has a `.then` property, which is also a `function`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isPromiseLike = obj =>
|
||||||
|
obj !== null &&
|
||||||
|
(typeof obj === 'object' || typeof obj === 'function') &&
|
||||||
|
typeof obj.then === 'function';
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isPromiseLike({
|
||||||
|
then: function() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}); // true
|
||||||
|
isPromiseLike(null); // false
|
||||||
|
isPromiseLike({}); // false
|
||||||
|
```
|
||||||
22
snippets/isValidJSON.md
Normal file
22
snippets/isValidJSON.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
### isValidJSON
|
||||||
|
|
||||||
|
Checks if the provided argument is a valid JSON.
|
||||||
|
|
||||||
|
Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const isValidJSON = obj => {
|
||||||
|
try {
|
||||||
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isValidJSON('{"name":"Adam","age":20}'); // true
|
||||||
|
isValidJSON('{"name":"Adam",age:"20"}'); // false
|
||||||
|
isValidJSON(null); // true
|
||||||
|
```
|
||||||
20
snippets/memoize.md
Normal file
20
snippets/memoize.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
### memoize
|
||||||
|
|
||||||
|
Returns the memoized (cached) function.
|
||||||
|
|
||||||
|
Use `Object.create(null)` to create an empty object without `Object.prototype` (so that those properties are not resolved if the input value is something like `'hasOwnProperty'`).
|
||||||
|
Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const memoize = fn => {
|
||||||
|
const cache = Object.create(null);
|
||||||
|
return value => cache[value] || (cache[value] = fn(value));
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
// See the `anagrams` snippet.
|
||||||
|
const anagramsCached = memoize(anagrams);
|
||||||
|
anagramsCached('javascript'); // takes a long time
|
||||||
|
anagramsCached('javascript'); // returns virtually instantly since it's now cached
|
||||||
|
```
|
||||||
23
snippets/sampleSize.md
Normal file
23
snippets/sampleSize.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
### sampleSize
|
||||||
|
|
||||||
|
Gets `n` random elements at unique keys from `array` up to the size of `array`.
|
||||||
|
|
||||||
|
Shuffle the array using the [Fisher-Yates algorithm](https://github.com/chalarangelo/30-seconds-of-code#shuffle).
|
||||||
|
Use `Array.slice()` to get the first `n` elements.
|
||||||
|
Omit the second argument, `n` to get only one element at random from the array.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const sampleSize = ([...arr], n = 1) => {
|
||||||
|
let m = arr.length;
|
||||||
|
while (m) {
|
||||||
|
const i = Math.floor(Math.random() * m--);
|
||||||
|
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||||
|
}
|
||||||
|
return arr.slice(0, n);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
sampleSize([1, 2, 3], 2); // [3,1]
|
||||||
|
sampleSize([1, 2, 3], 4); // [2,3,1]
|
||||||
|
```
|
||||||
25
snippets/size.md
Normal file
25
snippets/size.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
### size
|
||||||
|
|
||||||
|
Get size of arrays, objects or strings.
|
||||||
|
|
||||||
|
Get type of `value` (`array`, `object` or `string`).
|
||||||
|
Use `length` property for arrays.
|
||||||
|
Use `length` or `size` value if available or number of keys for objects.
|
||||||
|
Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `value` for strings.
|
||||||
|
|
||||||
|
Split strings into array of characters with `split('')` and return its length.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const size = value =>
|
||||||
|
Array.isArray(value)
|
||||||
|
? value.length
|
||||||
|
: value && typeof value === 'object'
|
||||||
|
? value.size || value.length || Object.keys(value).length
|
||||||
|
: typeof value === 'string' ? new Blob([value]).size : 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
size([1, 2, 3, 4, 5]); // 5
|
||||||
|
size('size'); // 4
|
||||||
|
size({ one: 1, two: 2, three: 3 }); // 3
|
||||||
|
```
|
||||||
19
snippets/sortedIndex.md
Normal file
19
snippets/sortedIndex.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
### sortedIndex
|
||||||
|
|
||||||
|
Returns the lowest index at which value should be inserted into array in order to maintain its sort order.
|
||||||
|
|
||||||
|
Check if the array is sorted in descending order (loosely).
|
||||||
|
Use `Array.findIndex()` to find the appropriate index where the element should be inserted.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const sortedIndex = (arr, n) => {
|
||||||
|
const isDescending = arr[0] > arr[arr.length - 1];
|
||||||
|
const index = arr.findIndex(el => (isDescending ? n >= el : n <= el));
|
||||||
|
return index === -1 ? arr.length : index;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
sortedIndex([5, 3, 2, 1], 4); // 1
|
||||||
|
sortedIndex([30, 50], 40); // 1
|
||||||
|
```
|
||||||
@ -6,13 +6,12 @@ Break the string into words and combine them using `_` as a separator.
|
|||||||
For more detailed explanation of this Regex, [visit this Site](https://regex101.com/r/bMCgAB/1).
|
For more detailed explanation of this Regex, [visit this Site](https://regex101.com/r/bMCgAB/1).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const toSnakeCase = str => {
|
const toSnakeCase = str =>
|
||||||
str &&
|
str &&
|
||||||
str
|
str
|
||||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||||
.map(x => x.toLowerCase())
|
.map(x => x.toLowerCase())
|
||||||
.join('_');
|
.join('_');
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
18
snippets/yesNo.md
Normal file
18
snippets/yesNo.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
### yesNo
|
||||||
|
|
||||||
|
Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`.
|
||||||
|
|
||||||
|
Use `RegExp.test()` to check if the string evaluates to `y/yes` or `n/no`.
|
||||||
|
Omit the second argument, `def` to set the default answer as `no`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const yesNo = (val, def = false) =>
|
||||||
|
/^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
yesNo('Y'); // true
|
||||||
|
yesNo('yes'); // true
|
||||||
|
yesNo('No'); // false
|
||||||
|
yesNo('Foo', true); // true
|
||||||
|
```
|
||||||
@ -1,3 +1,10 @@
|
|||||||
|
## Collaborators
|
||||||
|
|
||||||
|
| [<img src="https://github.com/Chalarangelo.png" width="100px;"/>](https://github.com/Chalarangelo)<br/> [<sub>Angelos Chalaris</sub>](https://github.com/Chalarangelo) | [<img src="https://github.com/Pl4gue.png" width="100px;"/>](https://github.com/Pl4gue)<br/> [<sub>David Wu</sub>](https://github.com/Pl4gue) | [<img src="https://github.com/fejes713.png" width="100px;"/>](https://github.com/fejes713)<br/> [<sub>Stefan Feješ</sub>](https://github.com/fejes713) | [<img src="https://github.com/kingdavidmartins.png" width="100px;"/>](https://github.com/kingdavidmartins)<br/> [<sub>King David Martins</sub>](https://github.com/iamsoorena) | [<img src="https://github.com/iamsoorena.png" width="100px;"/>](https://github.com/iamsoorena)<br/> [<sub>Soorena Soleimani</sub>](https://github.com/iamsoorena) |
|
||||||
|
| --- | --- | --- | --- | --- |
|
||||||
|
| [<img src="https://github.com/elderhsouza.png" width="100px;"/>](https://github.com/elderhsouza)<br/> [<sub>Elder Henrique Souza</sub>](https://github.com/elderhsouza) | [<img src="https://github.com/skatcat31.png" width="100px;"/>](https://github.com/skatcat31)<br/> [<sub>Robert Mennell</sub>](https://github.com/skatcat31) | [<img src="https://github.com/atomiks.png" width="100px;"/>](https://github.com/atomiks)<br/> [<sub>atomiks</sub>](https://github.com/atomiks) |
|
||||||
|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*
|
*Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/).*
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
||||||
- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
|
- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
|
||||||
- Snippets are written in ES6, use the [Babel transpiler](https://babeljs.io/) to ensure backwards-compatibility.
|
- Snippets are written in ES6, use the [Babel transpiler](https://babeljs.io/) to ensure backwards-compatibility.
|
||||||
|
- You can import these snippets into your text editor of choice (VSCode, Atom, Sublime) using the files found in [this repo](https://github.com/Rob-Rychs/30-seconds-of-code-texteditorsnippets).
|
||||||
- You can import these snippets into Alfred 3, using [this file](https://github.com/lslvxy/30-seconds-of-code-alfredsnippets).
|
- You can import these snippets into Alfred 3, using [this file](https://github.com/lslvxy/30-seconds-of-code-alfredsnippets).
|
||||||
- You can find a package with all the snippets on [npm](https://www.npmjs.com/package/tsoc). Bear in mind that most of these snippets are not production-ready.
|
- You can find a package with all the snippets on [npm](https://www.npmjs.com/package/tsoc). Bear in mind that most of these snippets are not production-ready.
|
||||||
|
|
||||||
|
|||||||
@ -92,8 +92,6 @@
|
|||||||
<nav class="col-md-4 col-lg-3" style="border-top: 0">
|
<nav class="col-md-4 col-lg-3" style="border-top: 0">
|
||||||
<div class="group">
|
<div class="group">
|
||||||
<input class="search" type="text" id="searchInput" onkeyup="search(this)">
|
<input class="search" type="text" id="searchInput" onkeyup="search(this)">
|
||||||
<span class="highlight"></span>
|
|
||||||
<span class="bar"></span>
|
|
||||||
<label id="search-label">Search for snippet...</label>
|
<label id="search-label">Search for snippet...</label>
|
||||||
</div>
|
</div>
|
||||||
<label for="doc-drawer-checkbox" class="button drawer-close"></label>
|
<label for="doc-drawer-checkbox" class="button drawer-close"></label>
|
||||||
|
|||||||
13
tag_database
13
tag_database
@ -16,6 +16,7 @@ collatz:math
|
|||||||
collectInto:adapter
|
collectInto:adapter
|
||||||
compact:array
|
compact:array
|
||||||
compose:function
|
compose:function
|
||||||
|
copyToClipboard:browser
|
||||||
countOccurrences:array
|
countOccurrences:array
|
||||||
countVowels:string
|
countVowels:string
|
||||||
currentURL:browser
|
currentURL:browser
|
||||||
@ -63,17 +64,22 @@ initializeArrayWithRange:array
|
|||||||
initializeArrayWithValues:array
|
initializeArrayWithValues:array
|
||||||
inRange:math
|
inRange:math
|
||||||
intersection:array
|
intersection:array
|
||||||
|
isAbsoluteURL:string
|
||||||
isArmstrongNumber:math
|
isArmstrongNumber:math
|
||||||
isArray:utility
|
isArray:utility
|
||||||
|
isArrayLike:utility
|
||||||
isBoolean:utility
|
isBoolean:utility
|
||||||
isDivisible:math
|
isDivisible:math
|
||||||
isEven:math
|
isEven:math
|
||||||
isFunction:utility
|
isFunction:utility
|
||||||
|
isNull:utility
|
||||||
isNumber:utility
|
isNumber:utility
|
||||||
isPrime:math
|
isPrime:math
|
||||||
isPrimitive:utility
|
isPrimitive:utility
|
||||||
|
isPromiseLike:utility
|
||||||
isString:utility
|
isString:utility
|
||||||
isSymbol:utility
|
isSymbol:utility
|
||||||
|
isValidJSON:utility
|
||||||
JSONToDate:date
|
JSONToDate:date
|
||||||
JSONToFile:node
|
JSONToFile:node
|
||||||
last:array
|
last:array
|
||||||
@ -82,6 +88,7 @@ lowercaseKeys:object
|
|||||||
mapObject:array
|
mapObject:array
|
||||||
max:math
|
max:math
|
||||||
median:math
|
median:math
|
||||||
|
memoize:function
|
||||||
min:math
|
min:math
|
||||||
negate:logic
|
negate:logic
|
||||||
nthElement:array
|
nthElement:array
|
||||||
@ -112,6 +119,7 @@ RGBToHex:utility
|
|||||||
round:math
|
round:math
|
||||||
runPromisesInSeries:function
|
runPromisesInSeries:function
|
||||||
sample:array
|
sample:array
|
||||||
|
sampleSize:array
|
||||||
scrollToTop:browser
|
scrollToTop:browser
|
||||||
sdbm:utility
|
sdbm:utility
|
||||||
select:object
|
select:object
|
||||||
@ -120,9 +128,11 @@ shallowClone:object
|
|||||||
show:browser
|
show:browser
|
||||||
shuffle:array
|
shuffle:array
|
||||||
similarity:array
|
similarity:array
|
||||||
|
size:object
|
||||||
sleep:function
|
sleep:function
|
||||||
sortCharactersInString:string
|
sortCharactersInString:string
|
||||||
speechSynthesis:media
|
sortedIndex:uncategorized
|
||||||
|
speechSynthesis:browser
|
||||||
splitLines:string
|
splitLines:string
|
||||||
spreadOver:adapter
|
spreadOver:adapter
|
||||||
standardDeviation:math
|
standardDeviation:math
|
||||||
@ -149,5 +159,6 @@ UUIDGeneratorNode:node
|
|||||||
validateNumber:utility
|
validateNumber:utility
|
||||||
without:array
|
without:array
|
||||||
words:string
|
words:string
|
||||||
|
yesNo:utility
|
||||||
zip:array
|
zip:array
|
||||||
zipObject:array
|
zipObject:array
|
||||||
|
|||||||
Reference in New Issue
Block a user