Add emojis
This commit is contained in:
48
README.md
48
README.md
@ -14,7 +14,7 @@
|
||||
|
||||
## Table of Contents
|
||||
|
||||
### Adapter
|
||||
### 🔌 Adapter
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Array
|
||||
### 📚 Array
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -76,7 +76,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Browser
|
||||
### 🖥️ Browser
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -102,7 +102,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Date
|
||||
### ⏱️ Date
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -114,7 +114,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Function
|
||||
### 🎛️ Function
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -128,7 +128,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Logic
|
||||
### 🔮 Logic
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -137,7 +137,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Math
|
||||
### ➗ Math
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -173,7 +173,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Media
|
||||
### 📺 Media
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -182,7 +182,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Node
|
||||
### 📦 Node
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -193,7 +193,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Object
|
||||
### 🗃️ Object
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -209,7 +209,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### String
|
||||
### 📜 String
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -236,7 +236,7 @@
|
||||
|
||||
</details>
|
||||
|
||||
### Utility
|
||||
### 💎 Utility
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
@ -263,7 +263,7 @@
|
||||
</details>
|
||||
|
||||
---
|
||||
## Adapter
|
||||
## 🔌 Adapter
|
||||
|
||||
### call
|
||||
|
||||
@ -426,7 +426,7 @@ arrayMax([1, 2, 4]); // 4
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Array
|
||||
## 📚 Array
|
||||
|
||||
### chunk
|
||||
|
||||
@ -1440,7 +1440,7 @@ zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2}
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Browser
|
||||
## 🖥️ Browser
|
||||
|
||||
### arrayToHtmlList
|
||||
|
||||
@ -1892,7 +1892,7 @@ UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Date
|
||||
## ⏱️ Date
|
||||
|
||||
### getDaysDiffBetweenDates
|
||||
|
||||
@ -1993,7 +1993,7 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Function
|
||||
## 🎛️ Function
|
||||
|
||||
### chainAsync
|
||||
|
||||
@ -2157,7 +2157,7 @@ async function sleepyWork() {
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Logic
|
||||
## 🔮 Logic
|
||||
|
||||
### negate
|
||||
|
||||
@ -2182,7 +2182,7 @@ negate(isOdd)(1); // false
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Math
|
||||
## ➗ Math
|
||||
|
||||
### average
|
||||
|
||||
@ -2888,7 +2888,7 @@ sum([1, 2, 3, 4]); // 10
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Media
|
||||
## 📺 Media
|
||||
|
||||
### speechSynthesis
|
||||
|
||||
@ -2919,7 +2919,7 @@ speechSynthesis('Hello, World'); // // plays the message
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Node
|
||||
## 📦 Node
|
||||
|
||||
### JSONToFile
|
||||
|
||||
@ -3009,7 +3009,7 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Object
|
||||
## 🗃️ Object
|
||||
|
||||
### cleanObj
|
||||
|
||||
@ -3225,7 +3225,7 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## String
|
||||
## 📜 String
|
||||
|
||||
### anagrams
|
||||
|
||||
@ -3750,7 +3750,7 @@ words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"]
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
---
|
||||
## Utility
|
||||
## 💎 Utility
|
||||
|
||||
### coalesce
|
||||
|
||||
|
||||
122
scripts/build.js
122
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<details>\n<summary>View contents</summary>\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<details>\n<summary>View contents</summary>\n\n`;
|
||||
for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag)) {
|
||||
uncategorizedOutput += `* [\`${taggedSnippet[0]}\`](#${taggedSnippet[0].toLowerCase()})\n`;
|
||||
}
|
||||
uncategorizedOutput += '\n</details>\n\n';
|
||||
} else {
|
||||
output += `### ${capitalize(tag, true)}\n\n<details>\n<summary>View contents</summary>\n\n`;
|
||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1] === tag))
|
||||
output += `### ${
|
||||
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 += '\n</details>\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<br>[⬆ 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');
|
||||
|
||||
Reference in New Issue
Block a user