@coderich/util 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +6 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -110,19 +110,19 @@ exports.map = (mixed, fn) => {
|
|
|
110
110
|
return isArray ? results : results[0];
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
exports.dirmap = (dir, fn
|
|
113
|
+
exports.dirmap = (dir, fn) => {
|
|
114
114
|
const data = {};
|
|
115
115
|
dir = Path.resolve(dir);
|
|
116
116
|
|
|
117
117
|
FS.readdirSync(dir).forEach((filename) => {
|
|
118
118
|
const { name } = Path.parse(filename);
|
|
119
119
|
const path = `${dir}/${filename}`;
|
|
120
|
-
const
|
|
120
|
+
const stats = FS.statSync(path);
|
|
121
121
|
|
|
122
|
-
if (
|
|
123
|
-
data[name] = exports.dirmap(path);
|
|
124
|
-
} else {
|
|
125
|
-
data[name] = fn(path);
|
|
122
|
+
if (stats?.isDirectory()) {
|
|
123
|
+
data[name] = { ...fn?.({ stats, path }), ...exports.dirmap(path, fn) };
|
|
124
|
+
} else if (fn) {
|
|
125
|
+
data[name] = fn({ stats, path });
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
|