First snippet, builder working
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules/
|
||||
23
README.md
23
README.md
@ -1,2 +1,21 @@
|
||||
# 30s of Code
|
||||
A collection of useful Javascript snippets.
|
||||

|
||||
|
||||
# 30 seconds of code
|
||||
> Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.
|
||||
|
||||
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
||||
- Contributions welcome, please read [contribution guide](contributing.md).
|
||||
|
||||
### Sort characters in string (alphabetical)
|
||||
|
||||
Split the string using `split('')`, `sort()` utilizing `localeCompare()`, recombine using `join('')`.
|
||||
|
||||
```js
|
||||
var sortCharactersInString = str =>
|
||||
str.split('').sort( (a,b) => a.localeCompare(b) ).join('');
|
||||
```
|
||||
|
||||
## 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/).*
|
||||
|
||||
|
||||
33
package.json
Normal file
33
package.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"concurrently": "^3.5.1",
|
||||
"fs-extra": "^4.0.2",
|
||||
"live-server": "^1.2.0",
|
||||
"markdown-it": "^8.4.0",
|
||||
"nodemon": "^1.12.1"
|
||||
},
|
||||
"name": "30-seconds-of-code",
|
||||
"description": "A collection of useful Javascript snippets.",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"build-list": "node ./scripts/builder.js",
|
||||
"start": "concurrently --kill-others \"nodemon -e js,md -i README.md -x \\\"npm run build-list\\\"\" \"live-server ./build\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Chalarangelo/30-seconds-of-code.git"
|
||||
},
|
||||
"keywords": [
|
||||
"javascript",
|
||||
"snippets",
|
||||
"list"
|
||||
],
|
||||
"author": "Chalarangelo (chalarangelo@gmail.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Chalarangelo/30-seconds-of-code/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Chalarangelo/30-seconds-of-code#readme"
|
||||
}
|
||||
38
scripts/builder.js
Normal file
38
scripts/builder.js
Normal file
@ -0,0 +1,38 @@
|
||||
var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
|
||||
var snippetsPath = './snippets';
|
||||
var staticPartsPath = './static-parts';
|
||||
|
||||
var snippets = {}, startPart = '', endPart = '', output = '';
|
||||
|
||||
try {
|
||||
for(var snippet of fs.readdirSync(snippetsPath)){
|
||||
snippets[snippet] = fs.readFileSync(path.join(snippetsPath,snippet),'utf8');
|
||||
}
|
||||
}
|
||||
catch (err){
|
||||
console.log('Error during snippet loading: '+err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
startPart = fs.readFileSync(path.join(staticPartsPath,'README-start.md'),'utf8');
|
||||
endPart = fs.readFileSync(path.join(staticPartsPath,'README-end.md'),'utf8');
|
||||
}
|
||||
catch (err){
|
||||
console.log('Error during static part loading: '+err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
output += `${startPart+'\n'}`;
|
||||
for(var snippet of Object.entries(snippets))
|
||||
output += `${snippet[1]+'\n'}`;
|
||||
output += `${endPart+'\n'}`;
|
||||
fs.writeFileSync('README.md', output);
|
||||
}
|
||||
catch (err){
|
||||
console.log('Error during README generation: '+err);
|
||||
process.exit(1);
|
||||
}
|
||||
8
snippets/sort-characters-in-string.md
Normal file
8
snippets/sort-characters-in-string.md
Normal file
@ -0,0 +1,8 @@
|
||||
### Sort characters in string (alphabetical)
|
||||
|
||||
Split the string using `split('')`, `sort()` utilizing `localeCompare()`, recombine using `join('')`.
|
||||
|
||||
```js
|
||||
var sortCharactersInString = str =>
|
||||
str.split('').sort( (a,b) => a.localeCompare(b) ).join('');
|
||||
```
|
||||
3
static-parts/README-end.md
Normal file
3
static-parts/README-end.md
Normal file
@ -0,0 +1,3 @@
|
||||
## 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/).*
|
||||
7
static-parts/README-start.md
Normal file
7
static-parts/README-start.md
Normal file
@ -0,0 +1,7 @@
|
||||

|
||||
|
||||
# 30 seconds of code
|
||||
> Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.
|
||||
|
||||
- Use <kbd>Ctrl</kbd> + <kbd>F</kbd> or <kbd>command</kbd> + <kbd>F</kbd> to search for a snippet.
|
||||
- Contributions welcome, please read [contribution guide](contributing.md).
|
||||
Reference in New Issue
Block a user