@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +6 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/util",
3
3
  "main": "src/index.js",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
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 = v => v) => {
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 stat = FS.statSync(path);
120
+ const stats = FS.statSync(path);
121
121
 
122
- if (stat && stat.isDirectory()) {
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