From 8ecb88497b76285f819afbd2a7f144b02d068d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Holl=C3=B3?= Date: Sat, 30 Dec 2017 15:46:01 +0100 Subject: [PATCH 01/77] Create size.md --- snippets/size.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 snippets/size.md diff --git a/snippets/size.md b/snippets/size.md new file mode 100644 index 000000000..42b3cfd9d --- /dev/null +++ b/snippets/size.md @@ -0,0 +1,15 @@ +### size + +Get size of arrays, objects or strings. + +Get type of value – array, object and string. Use `length` property for arrays. Return `length` or `size` value if available or number of object keys. 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' ? value.split('').length : 0; +``` + +```js +size([ 1, 2, 3, 4, 5 ]); // 5 +size('size'); // 4 +size({ one: 1, two: 2, three: 3 }); // 3 +``` From f8b2499bfcd8e61161817ea94106f41dbc62dc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Holl=C3=B3?= Date: Sat, 30 Dec 2017 17:27:37 +0100 Subject: [PATCH 02/77] Add line breaks between conditions --- snippets/size.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snippets/size.md b/snippets/size.md index 42b3cfd9d..61c50e19e 100644 --- a/snippets/size.md +++ b/snippets/size.md @@ -5,7 +5,14 @@ Get size of arrays, objects or strings. Get type of value – array, object and string. Use `length` property for arrays. Return `length` or `size` value if available or number of object keys. 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' ? value.split('').length : 0; +const size = value => + Array.isArray(value) + ? value.length + : value && typeof value === 'object' + ? value.size || value.length || Object.keys(value).length + : typeof value === 'string' + ? value.split('').length + : 0; ``` ```js From 4f86278d216ca514587f6595d23cebd93b4358d4 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 30 Dec 2017 18:35:54 +0200 Subject: [PATCH 03/77] Add yesNo snippet --- snippets/yesNo.md | 18 ++++++++++++++++++ tag_database | 1 + 2 files changed, 19 insertions(+) create mode 100644 snippets/yesNo.md diff --git a/snippets/yesNo.md b/snippets/yesNo.md new file mode 100644 index 000000000..3783e6fde --- /dev/null +++ b/snippets/yesNo.md @@ -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 +``` diff --git a/tag_database b/tag_database index d897e319c..0e1a31a69 100644 --- a/tag_database +++ b/tag_database @@ -148,5 +148,6 @@ UUIDGeneratorNode:node validateNumber:utility without:array words:string +yesNo:utility zip:array zipObject:array From 05aeadf916e8d6ca0768ab736947ea5068ce7edd Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 03:40:22 +1100 Subject: [PATCH 04/77] Test readme gen --- README.md | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e036b03bd..d2303ccd5 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,8 @@ -## Adapter +--- + ## Adapter ### call @@ -424,7 +425,8 @@ arrayMax([1, 2, 4]); // 4
[⬆ Back to top](#table-of-contents) -## Array +--- + ## Array ### chunk @@ -1437,7 +1439,8 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
[⬆ Back to top](#table-of-contents) -## Browser +--- + ## Browser ### arrayToHtmlList @@ -1888,7 +1891,8 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
[⬆ Back to top](#table-of-contents) -## Date +--- + ## Date ### getDaysDiffBetweenDates @@ -1988,7 +1992,8 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
[⬆ Back to top](#table-of-contents) -## Function +--- + ## Function ### chainAsync @@ -2151,7 +2156,8 @@ async function sleepyWork() {
[⬆ Back to top](#table-of-contents) -## Logic +--- + ## Logic ### negate @@ -2175,7 +2181,8 @@ negate(isOdd)(1); // false
[⬆ Back to top](#table-of-contents) -## Math +--- + ## Math ### average @@ -2880,7 +2887,8 @@ sum([1, 2, 3, 4]); // 10
[⬆ Back to top](#table-of-contents) -## Media +--- + ## Media ### speechSynthesis @@ -2910,7 +2918,8 @@ speechSynthesis('Hello, World'); // // plays the message
[⬆ Back to top](#table-of-contents) -## Node +--- + ## Node ### JSONToFile @@ -2999,7 +3008,8 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
[⬆ Back to top](#table-of-contents) -## Object +--- + ## Object ### cleanObj @@ -3214,7 +3224,8 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
[⬆ Back to top](#table-of-contents) -## String +--- + ## String ### anagrams @@ -3738,7 +3749,8 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
[⬆ Back to top](#table-of-contents) -## Utility +--- + ## Utility ### coalesce From 4a142715056959d8c448a72307df42ace27ac40a Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 03:55:27 +1100 Subject: [PATCH 05/77] Add emojis --- README.md | 48 +++++++++---------- scripts/build.js | 122 ++++++++++++++++++++++++++++------------------- 2 files changed, 98 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index d2303ccd5..16e26af95 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## Table of Contents -### Adapter +### 🔌 Adapter
View contents @@ -28,7 +28,7 @@
-### Array +### 📚 Array
View contents @@ -76,7 +76,7 @@
-### Browser +### 🖥️ Browser
View contents @@ -102,7 +102,7 @@
-### Date +### ⏱️ Date
View contents @@ -114,7 +114,7 @@
-### Function +### 🎛️ Function
View contents @@ -128,7 +128,7 @@
-### Logic +### 🔮 Logic
View contents @@ -137,7 +137,7 @@
-### Math +### ➗ Math
View contents @@ -173,7 +173,7 @@
-### Media +### 📺 Media
View contents @@ -182,7 +182,7 @@
-### Node +### 📦 Node
View contents @@ -193,7 +193,7 @@
-### Object +### 🗃️ Object
View contents @@ -209,7 +209,7 @@
-### String +### 📜 String
View contents @@ -236,7 +236,7 @@
-### Utility +### 💎 Utility
View contents @@ -263,7 +263,7 @@
--- - ## Adapter + ## 🔌 Adapter ### call @@ -426,7 +426,7 @@ arrayMax([1, 2, 4]); // 4
[⬆ Back to top](#table-of-contents) --- - ## Array + ## 📚 Array ### chunk @@ -1440,7 +1440,7 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
[⬆ Back to top](#table-of-contents) --- - ## Browser + ## 🖥️ Browser ### arrayToHtmlList @@ -1892,7 +1892,7 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
[⬆ Back to top](#table-of-contents) --- - ## Date + ## ⏱️ Date ### getDaysDiffBetweenDates @@ -1993,7 +1993,7 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
[⬆ Back to top](#table-of-contents) --- - ## Function + ## 🎛️ Function ### chainAsync @@ -2157,7 +2157,7 @@ async function sleepyWork() {
[⬆ Back to top](#table-of-contents) --- - ## Logic + ## 🔮 Logic ### negate @@ -2182,7 +2182,7 @@ negate(isOdd)(1); // false
[⬆ Back to top](#table-of-contents) --- - ## Math + ## ➗ Math ### average @@ -2888,7 +2888,7 @@ sum([1, 2, 3, 4]); // 10
[⬆ Back to top](#table-of-contents) --- - ## Media + ## 📺 Media ### speechSynthesis @@ -2919,7 +2919,7 @@ speechSynthesis('Hello, World'); // // plays the message
[⬆ Back to top](#table-of-contents) --- - ## Node + ## 📦 Node ### JSONToFile @@ -3009,7 +3009,7 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
[⬆ Back to top](#table-of-contents) --- - ## Object + ## 🗃️ Object ### cleanObj @@ -3225,7 +3225,7 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
[⬆ Back to top](#table-of-contents) --- - ## String + ## 📜 String ### anagrams @@ -3750,7 +3750,7 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
[⬆ Back to top](#table-of-contents) --- - ## Utility + ## 💎 Utility ### coalesce diff --git a/scripts/build.js b/scripts/build.js index a6e6d607d..1f400a04e 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -3,51 +3,64 @@ Run using `npm run builder`. */ // Load modules -const fs = require('fs-extra'), - path = require('path'), - chalk = require('chalk'); -// Set variables for paths -const snippetsPath = './snippets', - staticPartsPath = './static-parts'; -// Set variables for script -let snippets = {}, - startPart = '', +const fs = require('fs-extra'); +const path = require('path'); +const chalk = require('chalk'); + +const SNIPPETS_PATH = './snippets'; +const STATIC_PARTS_PATH = './static-parts'; + +const snippets = {}; +const emojis = { + adapter: '🔌', + array: '📚', + browser: '🖥️', + date: '⏱️', + function: '🎛️', + logic: '🔮', + math: '➗', + media: '📺', + node: '📦', + object: '🗃️', + string: '📜', + utility: '💎' +}; + +let startPart = '', endPart = '', output = '', tagDbData = {}; + // 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 capitalize = (str, lowerRest = false) => str.slice(0, 1).toUpperCase() + (lowerRest ? str.slice(1).toLowerCase() : str.slice(1)); -// Start the timer of the script + console.time('Builder'); + // Synchronously read all snippets and sort them as necessary (case-insensitive) try { - let snippetFilenames = fs.readdirSync(snippetsPath); - snippetFilenames.sort((a, b) => { - a = a.toLowerCase(); - b = b.toLowerCase(); - if (a < b) return -1; - if (a > b) return 1; - return 0; - }); + const snippetFilenames = fs + .readdirSync(SNIPPETS_PATH) + .sort((a, b) => a.toLowerCase() - b.toLowerCase()); // Store the data read from each snippet in the appropriate object - for (let snippet of snippetFilenames) - snippets[snippet] = fs.readFileSync(path.join(snippetsPath, snippet), 'utf8'); + for (const name of snippetFilenames) { + snippets[name] = fs.readFileSync(path.join(SNIPPETS_PATH, name), 'utf8'); + } } catch (err) { - // Handle errors (hopefully not!) console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`); process.exit(1); } + // Load static parts for the README file try { - startPart = fs.readFileSync(path.join(staticPartsPath, 'README-start.md'), 'utf8'); - endPart = fs.readFileSync(path.join(staticPartsPath, 'README-end.md'), 'utf8'); + startPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-start.md'), 'utf8'); + endPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-end.md'), 'utf8'); } catch (err) { - // Handle errors (hopefully not!) console.log(`${chalk.red('ERROR!')} During static part loading: ${err}`); process.exit(1); } + // Load tag data from the database try { tagDbData = objectFromPairs( @@ -58,48 +71,62 @@ try { .map(v => v.split(':').slice(0, 2)) ); } catch (err) { - // Handle errors (hopefully not!) console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`); process.exit(1); } + // Create the output for the README file 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 output += `${startPart + '\n'}`; - // Loop over tags and snippets to create the table of contents let uncategorizedOutput = ''; - for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))] - .filter(v => v) - .sort((a, b) => a.localeCompare(b))) { - if (capitalize(tag, true) == 'Uncategorized') { - uncategorizedOutput += `### _${capitalize( - tag, - true - )}_\n\n
\nView contents\n\n`; - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) + + // Loop over tags and snippets to create the table of contents + for (const tag of tags) { + const capitalizedTag = capitalize(tag, true); + + if (capitalizedTag === 'Uncategorized') { + uncategorizedOutput += `### _${capitalizedTag}_\n\n
\nView contents\n\n`; + for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { uncategorizedOutput += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`; + } uncategorizedOutput += '\n
\n\n'; } else { - output += `### ${capitalize(tag, true)}\n\n
\nView contents\n\n`; - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) + output += `### ${ + emojis[tag] + } ${capitalizedTag}\n\n
\nView contents\n\n`; + for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { output += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`; + } output += '\n
\n\n'; } } + output += uncategorizedOutput; uncategorizedOutput = ''; + // Loop over tags and snippets to create the list of snippets - for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1]))] - .filter(v => v) - .sort((a, b) => a.localeCompare(b))) { - if (capitalize(tag, true) == 'Uncategorized') { - uncategorizedOutput += `## _${capitalize(tag, true)}_\n`; - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) + for (const tag of tags) { + const capitalizedTag = capitalize(tag, true); + + if (capitalizedTag == 'Uncategorized') { + uncategorizedOutput += `---\n ## _${capitalizedTag}_\n`; + for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { uncategorizedOutput += `\n${snippets[taggedSnippet[0] + '.md'] + '\n
[⬆ back to top](#table-of-contents)\n\n'}`; + } } else { - output += `## ${capitalize(tag, true)}\n`; - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { + output += `---\n ## ${emojis[tag]} ${capitalizedTag}\n`; + for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { let data = snippets[taggedSnippet[0] + '.md']; data = data.slice(0, data.lastIndexOf('```js')) + @@ -111,17 +138,16 @@ try { } } } + output += uncategorizedOutput; // Add the ending static part output += `\n${endPart + '\n'}`; // Write to the README file fs.writeFileSync('README.md', output); } catch (err) { - // Handle errors (hopefully not!) console.log(`${chalk.red('ERROR!')} During README generation: ${err}`); process.exit(1); } -// Log a success message + console.log(`${chalk.green('SUCCESS!')} README file generated!`); -// Log the time taken console.timeEnd('Builder'); From 418406563b38f715a06292254315ae319234c3f7 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 03:57:00 +1100 Subject: [PATCH 06/77] revert README back --- README.md | 139 +++++++++++++++++++++++++----------------------------- 1 file changed, 63 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 16e26af95..d3467da01 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ ## Table of Contents -### 🔌 Adapter +### Adapter
View contents @@ -28,7 +28,7 @@
-### 📚 Array +### Array
View contents @@ -76,7 +76,7 @@
-### 🖥️ Browser +### Browser
View contents @@ -102,7 +102,7 @@
-### ⏱️ Date +### Date
View contents @@ -114,7 +114,7 @@
-### 🎛️ Function +### Function
View contents @@ -128,7 +128,7 @@
-### 🔮 Logic +### Logic
View contents @@ -137,7 +137,7 @@
-### ➗ Math +### Math
View contents @@ -173,7 +173,7 @@
-### 📺 Media +### Media
View contents @@ -182,7 +182,7 @@
-### 📦 Node +### Node
View contents @@ -193,7 +193,7 @@
-### 🗃️ Object +### Object
View contents @@ -209,7 +209,7 @@
-### 📜 String +### String
View contents @@ -236,7 +236,7 @@
-### 💎 Utility +### Utility
View contents @@ -262,19 +262,18 @@
---- - ## 🔌 Adapter +## Adapter + +### call + +Given a key and a set of arguments, call them when given a context. Primarily useful in composition. + +Use a closure to call a stored key with stored arguments. -### call - -Given a key and a set of arguments, call them when given a context. Primarily useful in composition. - -Use a closure to call a stored key with stored arguments. - ```js const call = (key, ...args) => context => context[key](...args); -``` - +``` +
Examples @@ -286,23 +285,23 @@ const map = call.bind(null, 'map'); Promise.resolve([1, 2, 3]) .then(map(x => 2 * x)) .then(console.log); //[ 2, 4, 6 ] -``` +```

[⬆ Back to top](#table-of-contents) -### collectInto - -Changes a function that accepts an array into a variadic function. - -Given a function, return a closure that collects all inputs into an array-accepting function. - +### collectInto + +Changes a function that accepts an array into a variadic function. + +Given a function, return a closure that collects all inputs into an array-accepting function. + ```js const collectInto = fn => (...args) => fn(args); -``` - +``` +
Examples @@ -312,23 +311,23 @@ let p1 = Promise.resolve(1); let p2 = Promise.resolve(2); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); Pall(p1, p2, p3).then(console.log); -``` +```

[⬆ Back to top](#table-of-contents) -### flip - -Flip takes a function as an argument, then makes the first argument the last - -Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. - +### flip + +Flip takes a function as an argument, then makes the first argument the last + +Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. + ```js const flip = fn => (...args) => fn(args.pop(), ...args); -``` - +``` +
Examples @@ -340,7 +339,7 @@ let mergePerson = mergeFrom.bind(null, a); mergePerson(b); // == b b = {}; Object.assign(b, a); // == b -``` +```
@@ -402,16 +401,16 @@ delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s
[⬆ Back to top](#table-of-contents) -### spreadOver - -Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. - -Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. - +### spreadOver + +Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. + +Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. + ```js const spreadOver = fn => argsArr => fn(...argsArr); -``` - +``` +
Examples @@ -419,14 +418,13 @@ const spreadOver = fn => argsArr => fn(...argsArr); const arrayMax = spreadOver(Math.max); arrayMax([1, 2, 3]); // 3 arrayMax([1, 2, 4]); // 4 -``` +```

[⬆ Back to top](#table-of-contents) ---- - ## 📚 Array +## Array ### chunk @@ -1112,8 +1110,8 @@ console.log(pulled); // [ 'b', 'd' ] QuickSort an Array (ascending sort by default). -Use recursion. -Use `Array.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. +Use recursion. +Use `Array.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. If the parameter `desc` is truthy, return array sorts in descending order. ```js @@ -1439,8 +1437,7 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
[⬆ Back to top](#table-of-contents) ---- - ## 🖥️ Browser +## Browser ### arrayToHtmlList @@ -1713,7 +1710,7 @@ const httpsRedirect = () => { Run the callback whenever the user input type changes (`mouse` or `touch`). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops). -Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document. +Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document. On `touchstart`, add a `mousemove` event listener to listen for two consecutive `mousemove` events firing within 20ms, using `performance.now()`. Run the callback with the input type as an argument in either of these situations. @@ -1891,8 +1888,7 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
[⬆ Back to top](#table-of-contents) ---- - ## ⏱️ Date +## Date ### getDaysDiffBetweenDates @@ -1992,8 +1988,7 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
[⬆ Back to top](#table-of-contents) ---- - ## 🎛️ Function +## Function ### chainAsync @@ -2156,8 +2151,7 @@ async function sleepyWork() {
[⬆ Back to top](#table-of-contents) ---- - ## 🔮 Logic +## Logic ### negate @@ -2181,8 +2175,7 @@ negate(isOdd)(1); // false
[⬆ Back to top](#table-of-contents) ---- - ## ➗ Math +## Math ### average @@ -2887,8 +2880,7 @@ sum([1, 2, 3, 4]); // 10
[⬆ Back to top](#table-of-contents) ---- - ## 📺 Media +## Media ### speechSynthesis @@ -2918,8 +2910,7 @@ speechSynthesis('Hello, World'); // // plays the message
[⬆ Back to top](#table-of-contents) ---- - ## 📦 Node +## Node ### JSONToFile @@ -3008,8 +2999,7 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
[⬆ Back to top](#table-of-contents) ---- - ## 🗃️ Object +## Object ### cleanObj @@ -3224,8 +3214,7 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
[⬆ Back to top](#table-of-contents) ---- - ## 📜 String +## String ### anagrams @@ -3749,8 +3738,7 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
[⬆ Back to top](#table-of-contents) ---- - ## 💎 Utility +## Utility ### coalesce @@ -4215,4 +4203,3 @@ validateNumber('10'); // true ## 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/).* - From 1502d75d1379e892cf243d003fd607c0d10f45ee Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 04:02:28 +1100 Subject: [PATCH 07/77] handle new categories --- scripts/build.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 1f400a04e..b1e49a0a5 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -102,7 +102,7 @@ try { uncategorizedOutput += '\n
\n\n'; } else { output += `### ${ - emojis[tag] + emojis[tag] || '' } ${capitalizedTag}\n\n
\nView contents\n\n`; for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { output += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`; @@ -125,7 +125,7 @@ try { '\n
[⬆ back to top](#table-of-contents)\n\n'}`; } } else { - output += `---\n ## ${emojis[tag]} ${capitalizedTag}\n`; + output += `---\n ## ${emojis[tag] || ''} ${capitalizedTag}\n`; for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) { let data = snippets[taggedSnippet[0] + '.md']; data = From 55ba61476facc096414f32b8d3ac3a314b9b25e3 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 30 Dec 2017 19:07:10 +0200 Subject: [PATCH 08/77] Update tag_database --- tag_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tag_database b/tag_database index d897e319c..bada09166 100644 --- a/tag_database +++ b/tag_database @@ -121,7 +121,7 @@ shuffle:array similarity:array sleep:function sortCharactersInString:string -speechSynthesis:media +speechSynthesis:browser splitLines:string spreadOver:adapter standardDeviation:math From f1f3ca4a8f7f383f54aeb43d9f350cd6edc95c96 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 30 Dec 2017 17:08:11 +0000 Subject: [PATCH 09/77] Travis build: 672 [ci skip] --- README.md | 69 +++++++++++++++++++++---------------------------- docs/index.html | 14 +++++----- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index e036b03bd..329416bde 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ * [`scrollToTop`](#scrolltotop) * [`setStyle`](#setstyle) * [`show`](#show) +* [`speechSynthesis`](#speechsynthesis) * [`toggleClass`](#toggleclass) * [`UUIDGeneratorBrowser`](#uuidgeneratorbrowser) @@ -173,15 +174,6 @@
-### Media - -
-View contents - -* [`speechSynthesis`](#speechsynthesis) - -
- ### Node
@@ -1842,6 +1834,35 @@ show(document.querySelectorAll('img')); // Shows all elements on the page
[⬆ 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); +}; +``` + +
+Examples + +```js +speechSynthesis('Hello, World'); // // plays the message +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### toggleClass Toggle a class for an element. @@ -2880,36 +2901,6 @@ sum([1, 2, 3, 4]); // 10
[⬆ Back to top](#table-of-contents) -## Media - -### 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); -}; -``` - -
-Examples - -```js -speechSynthesis('Hello, World'); // // plays the message -``` - -
- -
[⬆ Back to top](#table-of-contents) - ## Node ### JSONToFile diff --git a/docs/index.html b/docs/index.html index 356e7004a..1459847d1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,7 @@ wrapper.appendChild(box); box.appendChild(el); }); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+    }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -357,6 +357,12 @@ elementIsVisibleInViewport(el, true); // true // (partially visible)
 
setStyle(document.querySelector('p'), 'font-size', '20px'); // The first <p> element on the page will have a font-size of 20px
 

show

Shows all the elements specified.

Use the spread operator (...) and Array.forEach() to clear the display property for each element specified.

const show = (...el) => [...el].forEach(e => (e.style.display = ''));
 
show(document.querySelectorAll('img')); // Shows all <img> elements on the page
+

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.

const speechSynthesis = message => {
+  const msg = new SpeechSynthesisUtterance(message);
+  msg.voice = window.speechSynthesis.getVoices()[0];
+  window.speechSynthesis.speak(msg);
+};
+
speechSynthesis('Hello, World'); // // plays the message
 

toggleClass

Toggle a class for an element.

Use element.classList.toggle() to toggle the specified class for the element.

const toggleClass = (el, className) => el.classList.toggle(className);
 
toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore
 

UUIDGeneratorBrowser

Generates a UUID in a browser.

Use crypto API to generate a UUID, compliant with RFC4122 version 4.

const UUIDGeneratorBrowser = () =>
@@ -549,12 +555,6 @@ median([0, 10, -2, 7]); // 3.5
 standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (population)
 

sum

Returns the sum of an of two or more numbers/arrays.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0.

const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0);
 
sum([1, 2, 3, 4]); // 10
-

Media

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.

const speechSynthesis = message => {
-  const msg = new SpeechSynthesisUtterance(message);
-  msg.voice = window.speechSynthesis.getVoices()[0];
-  window.speechSynthesis.speak(msg);
-};
-
speechSynthesis('Hello, World'); // // plays the message
 

Node

JSONToFile

Writes a JSON object to a file.

Use fs.writeFile(), template literals and JSON.stringify() to write a json object to a .json file.

const fs = require('fs');
 const JSONToFile = (obj, filename) =>
   fs.writeFile(`${filename}.json`, JSON.stringify(obj, null, 2));

From 8be8ad706c20e2468b2b778c018e518bf90ddabd Mon Sep 17 00:00:00 2001
From: Travis CI 
Date: Sat, 30 Dec 2017 17:11:10 +0000
Subject: [PATCH 10/77] Travis build: 673 [ci skip]

---
 README.md | 134 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 73 insertions(+), 61 deletions(-)

diff --git a/README.md b/README.md
index 2940b3e8d..9c0256cd2 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
 
 ## Table of Contents
 
-### Adapter
+### 🔌 Adapter
 
 
View contents @@ -28,7 +28,7 @@
-### Array +### 📚 Array
View contents @@ -76,7 +76,7 @@
-### Browser +### 🖥️ Browser
View contents @@ -103,7 +103,7 @@
-### Date +### ⏱️ Date
View contents @@ -115,7 +115,7 @@
-### Function +### 🎛️ Function
View contents @@ -129,7 +129,7 @@
-### Logic +### 🔮 Logic
View contents @@ -138,7 +138,7 @@
-### Math +### ➗ Math
View contents @@ -174,7 +174,7 @@
-### Node +### 📦 Node
View contents @@ -185,7 +185,7 @@
-### Object +### 🗃️ Object
View contents @@ -201,7 +201,7 @@
-### String +### 📜 String
View contents @@ -228,7 +228,7 @@
-### Utility +### 💎 Utility
View contents @@ -254,18 +254,19 @@
-## Adapter - -### call - -Given a key and a set of arguments, call them when given a context. Primarily useful in composition. - -Use a closure to call a stored key with stored arguments. +--- + ## 🔌 Adapter +### call + +Given a key and a set of arguments, call them when given a context. Primarily useful in composition. + +Use a closure to call a stored key with stored arguments. + ```js const call = (key, ...args) => context => context[key](...args); -``` - +``` +
Examples @@ -277,23 +278,23 @@ const map = call.bind(null, 'map'); Promise.resolve([1, 2, 3]) .then(map(x => 2 * x)) .then(console.log); //[ 2, 4, 6 ] -``` +```

[⬆ Back to top](#table-of-contents) -### collectInto - -Changes a function that accepts an array into a variadic function. - -Given a function, return a closure that collects all inputs into an array-accepting function. - +### collectInto + +Changes a function that accepts an array into a variadic function. + +Given a function, return a closure that collects all inputs into an array-accepting function. + ```js const collectInto = fn => (...args) => fn(args); -``` - +``` +
Examples @@ -303,23 +304,23 @@ let p1 = Promise.resolve(1); let p2 = Promise.resolve(2); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); Pall(p1, p2, p3).then(console.log); -``` +```

[⬆ Back to top](#table-of-contents) -### flip - -Flip takes a function as an argument, then makes the first argument the last - -Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. - +### flip + +Flip takes a function as an argument, then makes the first argument the last + +Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest. + ```js const flip = fn => (...args) => fn(args.pop(), ...args); -``` - +``` +
Examples @@ -331,7 +332,7 @@ let mergePerson = mergeFrom.bind(null, a); mergePerson(b); // == b b = {}; Object.assign(b, a); // == b -``` +```
@@ -393,16 +394,16 @@ delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s
[⬆ Back to top](#table-of-contents) -### spreadOver - -Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. - -Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. - +### spreadOver + +Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. + +Use closures and the spread operator (`...`) to map the array of arguments to the inputs of the function. + ```js const spreadOver = fn => argsArr => fn(...argsArr); -``` - +``` +
Examples @@ -410,13 +411,14 @@ const spreadOver = fn => argsArr => fn(...argsArr); const arrayMax = spreadOver(Math.max); arrayMax([1, 2, 3]); // 3 arrayMax([1, 2, 4]); // 4 -``` +```

[⬆ Back to top](#table-of-contents) -## Array +--- + ## 📚 Array ### chunk @@ -1102,8 +1104,8 @@ console.log(pulled); // [ 'b', 'd' ] QuickSort an Array (ascending sort by default). -Use recursion. -Use `Array.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. +Use recursion. +Use `Array.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. If the parameter `desc` is truthy, return array sorts in descending order. ```js @@ -1429,7 +1431,8 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
[⬆ Back to top](#table-of-contents) -## Browser +--- + ## 🖥️ Browser ### arrayToHtmlList @@ -1702,7 +1705,7 @@ const httpsRedirect = () => { Run the callback whenever the user input type changes (`mouse` or `touch`). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops). -Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document. +Use two event listeners. Assume `mouse` input initially and bind a `touchstart` event listener to the document. On `touchstart`, add a `mousemove` event listener to listen for two consecutive `mousemove` events firing within 20ms, using `performance.now()`. Run the callback with the input type as an argument in either of these situations. @@ -1909,7 +1912,8 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
[⬆ Back to top](#table-of-contents) -## Date +--- + ## ⏱️ Date ### getDaysDiffBetweenDates @@ -2009,7 +2013,8 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
[⬆ Back to top](#table-of-contents) -## Function +--- + ## 🎛️ Function ### chainAsync @@ -2172,7 +2177,8 @@ async function sleepyWork() {
[⬆ Back to top](#table-of-contents) -## Logic +--- + ## 🔮 Logic ### negate @@ -2196,7 +2202,8 @@ negate(isOdd)(1); // false
[⬆ Back to top](#table-of-contents) -## Math +--- + ## ➗ Math ### average @@ -2901,7 +2908,8 @@ sum([1, 2, 3, 4]); // 10
[⬆ Back to top](#table-of-contents) -## Node +--- + ## 📦 Node ### JSONToFile @@ -2990,7 +2998,8 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
[⬆ Back to top](#table-of-contents) -## Object +--- + ## 🗃️ Object ### cleanObj @@ -3205,7 +3214,8 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
[⬆ Back to top](#table-of-contents) -## String +--- + ## 📜 String ### anagrams @@ -3729,7 +3739,8 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
[⬆ Back to top](#table-of-contents) -## Utility +--- + ## 💎 Utility ### coalesce @@ -4194,3 +4205,4 @@ validateNumber('10'); // true ## 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/).* + From 447b0bd1be1e8e79b9ef2820f36b0b75857fcb4b Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 30 Dec 2017 17:26:00 +0000 Subject: [PATCH 11/77] Travis build: 674 [ci skip] --- README.md | 28 ++++++++++++++++++++++++++++ docs/index.html | 8 +++++++- snippets/yesNo.md | 8 ++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c0256cd2..1ab0c8c3c 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,7 @@ * [`toDecimalMark`](#todecimalmark) * [`toOrdinalSuffix`](#toordinalsuffix) * [`validateNumber`](#validatenumber) +* [`yesNo`](#yesno)
@@ -4202,6 +4203,33 @@ validateNumber('10'); // true
[⬆ 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; +``` + +
+Examples + +```js +yesNo('Y'); // true +yesNo('yes'); // true +yesNo('No'); // false +yesNo('Foo', true); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ## 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/).* diff --git a/docs/index.html b/docs/index.html index 1459847d1..e4346b4ec 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,7 @@ wrapper.appendChild(box); box.appendChild(el); }); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+    }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -862,4 +862,10 @@ console.log(sdbm('age')); // 808122783
 
toOrdinalSuffix('123'); // "123rd"
 

validateNumber

Returns true if the given value is a number, false otherwise.

Use !isNaN in combination with parseFloat() to check if the argument is a number. Use isFinite() to check if the number is finite. Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 
validateNumber('10'); // true
+

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.

const yesNo = (val, def = false) =>
+  /^(y|yes)$/i.test(val) ? true : /^(n|no)$/i.test(val) ? false : def;
+
yesNo('Y'); // true
+yesNo('yes'); // true
+yesNo('No'); // false
+yesNo('Foo', true); // true
 

\ No newline at end of file diff --git a/snippets/yesNo.md b/snippets/yesNo.md index 3783e6fde..5d191cb94 100644 --- a/snippets/yesNo.md +++ b/snippets/yesNo.md @@ -11,8 +11,8 @@ const yesNo = (val, def = false) => ``` ```js -yesNo('Y') // true -yesNo('yes') // true -yesNo('No') // false -yesNo('Foo', true) // true +yesNo('Y'); // true +yesNo('yes'); // true +yesNo('No'); // false +yesNo('Foo', true); // true ``` From 949d59edd1851094706c40fce9d98db3e0690a85 Mon Sep 17 00:00:00 2001 From: atomiks Date: Sun, 31 Dec 2017 05:16:35 +1100 Subject: [PATCH 12/77] Fix implicit return --- snippets/toSnakeCase.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snippets/toSnakeCase.md b/snippets/toSnakeCase.md index e277fdcf1..47c82348a 100644 --- a/snippets/toSnakeCase.md +++ b/snippets/toSnakeCase.md @@ -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). ```js -const toSnakeCase = str => { +const toSnakeCase = 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) - .map(x => x.toLowerCase()) - .join('_'); -}; + str + .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()) + .join('_'); ``` ```js From ed780e2a5d43b3e8e2d0fc17d44cc46414f92a70 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 30 Dec 2017 18:19:26 +0000 Subject: [PATCH 13/77] Travis build: 677 [ci skip] --- README.md | 11 +++++------ docs/index.html | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1ab0c8c3c..c8317e4a3 100644 --- a/README.md +++ b/README.md @@ -3635,13 +3635,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). ```js -const toSnakeCase = str => { +const toSnakeCase = 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) - .map(x => x.toLowerCase()) - .join('_'); -}; + str + .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()) + .join('_'); ```
diff --git a/docs/index.html b/docs/index.html index e4346b4ec..22500c832 100644 --- a/docs/index.html +++ b/docs/index.html @@ -731,13 +731,12 @@ toKebabCase('some text'); // 'some-text' toKebabCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some-mixed-string-with-spaces-underscores-and-hyphens' toKebabCase('AllThe-small Things'); // "all-the-small-things" toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html" -

toSnakeCase

Converts a string to snake case.

Break the string into words and combine them using _ as a separator. For more detailed explanation of this Regex, visit this Site.

const toSnakeCase = str => {
+

toSnakeCase

Converts a string to snake case.

Break the string into words and combine them using _ as a separator. For more detailed explanation of this Regex, visit this Site.

const toSnakeCase = 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)
-      .map(x => x.toLowerCase())
-      .join('_');
-};
+  str
+    .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())
+    .join('_');
 
toSnakeCase('camelCase'); // 'camel_case'
 toSnakeCase('some text'); // 'some_text'
 toSnakeCase('some-javascript-property'); // 'some_javascript_property'

From f964c1a80750b96a566b4ebedef699d231499e59 Mon Sep 17 00:00:00 2001
From: Rob-Rychs 
Date: Sat, 30 Dec 2017 23:29:54 -0800
Subject: [PATCH 14/77] add link to README for files to import snippets into
 text editors

---
 static-parts/README-start.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/static-parts/README-start.md b/static-parts/README-start.md
index c49c6dd87..f6a95a986 100644
--- a/static-parts/README-start.md
+++ b/static-parts/README-start.md
@@ -9,6 +9,7 @@
 - Use Ctrl + F or command + F to search for a snippet.
 - 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.
+- 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 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.
 

From 0a701c0e63e8ffb5a1fbe1649958785380aec636 Mon Sep 17 00:00:00 2001
From: Travis CI 
Date: Sun, 31 Dec 2017 09:30:09 +0000
Subject: [PATCH 15/77] Travis build: 684 [ci skip]

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index c8317e4a3..092a124a0 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
 - Use Ctrl + F or command + F to search for a snippet.
 - 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.
+- 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 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.
 

From ea531aae037bbe0f1f448812217e4ee1622ad03b Mon Sep 17 00:00:00 2001
From: Angelos Chalaris 
Date: Sun, 31 Dec 2017 11:40:33 +0200
Subject: [PATCH 16/77] Add copyToClipboard

---
 snippets/copyToClipboard.md | 23 +++++++++++++++++++++++
 tag_database                |  1 +
 2 files changed, 24 insertions(+)
 create mode 100644 snippets/copyToClipboard.md

diff --git a/snippets/copyToClipboard.md b/snippets/copyToClipboard.md
new file mode 100644
index 000000000..50b986962
--- /dev/null
+++ b/snippets/copyToClipboard.md
@@ -0,0 +1,23 @@
+### copyToClipboard
+
+Copy a string to the clipboard.
+
+Create a new `