First snippet, builder working

This commit is contained in:
Angelos Chalaris
2017-11-30 17:40:06 +02:00
parent 2b16c211cb
commit a20766c478
9 changed files with 1946 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

View File

@ -1,2 +1,21 @@
# 30s of Code
A collection of useful Javascript snippets.
![Logo](/docs/logo.png)
# 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/).*

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

33
package.json Normal file
View 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
View 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);
}

View 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('');
```

View 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/).*

View File

@ -0,0 +1,7 @@
![Logo](/docs/logo.png)
# 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).

1835
yarn.lock Normal file

File diff suppressed because it is too large Load Diff