Skip to content

Commit 307061b

Browse files
committed
improvements
1 parent 8d2fd90 commit 307061b

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

lib/formats/csv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const os = require('os');
33
const path = require('path');
44

55
const J = require('JSUS').JSUS;
6-
const { addWD, addIfNotThere } = require('../util.js');
6+
const { addWD, addIfNotThere, findLineBreak } = require('../util.js');
77

88
module.exports = function(opts = {}) {
99

lib/loadDir.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44

55
const fs = require('fs');
6+
const path = require('path');
67

78
const NDDB = require('NDDB');
89

@@ -11,27 +12,44 @@
1112
/**
1213
* ### NDDB.loadDirSync
1314
*
14-
* Load all files matching the criteria into db synchronously
15+
* Synchronously load all files matching the criteria from a folder
1516
*
1617
* @param {string} dir The directory to search recursively
18+
* @param {object} opts The options to search and load files
19+
*
20+
* @returns {NDDB} The NDDB instance for chaining
1721
*
1822
* @see NDDB.loadSync
1923
*/
2024
NDDB.prototype.loadDirSync = function(dir, opts) {
2125

2226
decorateLoadDirOpts(opts);
2327

24-
getFilesSync(dir, opts).forEach(file => this.loadSync(file, opts));
25-
28+
getFilesSync(dir, opts).forEach(file => {
29+
try {
30+
this.loadSync(file, opts);
31+
}
32+
catch(e) {
33+
console.log(`\n (!) NDDB.loadDirSync: An error occurred ` +
34+
`in file: ${file}\n`);
35+
throw e;
36+
}
37+
});
2638
return this;
2739
};
2840

2941
/**
30-
* ### NDDB.loadDir
42+
* ### NDDB.loadDirSync
3143
*
32-
* Load in the specified format and loads them into db synchronously
44+
* Asynchronously load all files matching the criteria from a folder
3345
*
34-
* @see NDDB.loadSync
46+
* @param {string} dir The directory to search recursively
47+
* @param {object} opts The options to search and load files
48+
* @param {function} cb A callback executed when all files are loaded
49+
*
50+
* @returns {NDDB} The NDDB instance for chaining
51+
*
52+
* @see NDDB.load
3553
*/
3654
NDDB.prototype.loadDir = function(dir, opts, cb) {
3755

@@ -41,10 +59,20 @@
4159
let files = getFilesSync(dir, opts);
4260
let filesLeft = files.length;
4361

44-
files.forEach(file => this.load(file, (err) => {
45-
if (err) this.throwErr('Error', 'load', err);
46-
if (--filesLeft <= 0 && cb) cb(this);
47-
)});
62+
files.forEach(file => {
63+
try {
64+
this.load(file, (err) => {
65+
if (err) this.throwErr('Error', 'load', err);
66+
if (--filesLeft <= 0 && cb) cb(this);
67+
});
68+
}
69+
catch(e) {
70+
console.log(`\n (!) NDDB.loadDir: An error occurred in file: ` +
71+
`${file}\n`);
72+
console.log(e.message);
73+
throw e;
74+
}
75+
});
4876

4977
return this;
5078
};

0 commit comments

Comments
 (0)