Skip to content

Commit 2c73fe7

Browse files
committed
initial commit
1 parent 1215fae commit 2c73fe7

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
# loopie
1+
# node-loopie
2+
23
Converts your nodejs files in a folder to an object.
4+
5+
- **Declarative:** Reduce your code with node-loopie. Routes declaration, models, and etc... node-loopie will shorten it for you.
6+
7+
## Installation
8+
9+
```jsx
10+
npm install node-loopie
11+
```

index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
module.exports = (location = null, cb, basename = [], ext = '.js') => {
5+
if (!basename) basename = [];
6+
7+
if (location === null) throw new Error('Path is not');
8+
9+
fs.readdirSync(location)
10+
.filter((file) => {
11+
const file_split = file.split('.');
12+
const file_ext = '.' + file_split[file_split.length - 1];
13+
14+
return (
15+
file.indexOf('.') !== 0 &&
16+
basename.concat([`index${ext}`]).every((name) => name !== file) &&
17+
file_ext === ext
18+
);
19+
})
20+
.forEach((file) => {
21+
const r_file = fs.readFileSync(path.join(location, file), 'utf8');
22+
23+
cb(file, file.split('.')[0], r_file);
24+
});
25+
};

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "node-loopie",
3+
"version": "1.0.2",
4+
"description": "Converts your files in a folder to an object.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/techuila/loopie.git"
12+
},
13+
"keywords": [
14+
"object",
15+
"loop",
16+
"looper",
17+
"loopie",
18+
"loopfiles",
19+
"file",
20+
"files",
21+
"node",
22+
"node-loopie",
23+
"nodeloopie"
24+
],
25+
"author": "techuila",
26+
"license": "ISC",
27+
"bugs": {
28+
"url": "https://github.com/techuila/loopie/issues"
29+
},
30+
"homepage": "https://github.com/techuila/loopie#readme"
31+
}

0 commit comments

Comments
 (0)