@bemoje/fs 2.0.0 → 2.0.1

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 (3) hide show
  1. package/lib/index.cjs +11 -27
  2. package/lib/index.js +11 -27
  3. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -36,12 +36,8 @@ async function getFirstFileInDir(dirpath) {
36
36
  const dirents = await fs5__default.default.readdir(dirpath, {
37
37
  withFileTypes: true
38
38
  });
39
- const fileDirents = dirents.filter((file) => {
40
- return file.isFile();
41
- });
42
- const filenames = fileDirents.map((file) => {
43
- return file.name;
44
- });
39
+ const fileDirents = dirents.filter((file) => file.isFile());
40
+ const filenames = fileDirents.map((file) => file.name);
45
41
  const firstFileName = filenames[0];
46
42
  return firstFileName;
47
43
  }
@@ -124,29 +120,19 @@ function walkDirectory(dirpath, options) {
124
120
  return walkdir__default.default.sync(dirpath, {
125
121
  ...convertToWalkdirOptions(options),
126
122
  return_object: false
127
- }).map((fspath) => {
128
- return upath__default.default.normalizeSafe(fspath);
129
- });
123
+ }).map((fspath) => upath__default.default.normalizeSafe(fspath));
130
124
  }
131
125
  let entries = Object.entries(walkdir__default.default.sync(dirpath, convertToWalkdirOptions(options)));
132
126
  if (options.only === "files") {
133
- entries = entries.filter(([_, stats]) => {
134
- return stats.isFile();
135
- });
127
+ entries = entries.filter(([_, stats]) => stats.isFile());
136
128
  } else if (options.only === "directories") {
137
- entries = entries.filter(([_, stats]) => {
138
- return stats.isDirectory();
139
- });
129
+ entries = entries.filter(([_, stats]) => stats.isDirectory());
140
130
  }
141
- entries = entries.map(([fspath, stats]) => {
142
- return [
143
- upath__default.default.normalizeSafe(fspath),
144
- stats
145
- ];
146
- });
147
- return options.stats ? entries : entries.map(([fspath]) => {
148
- return fspath;
149
- });
131
+ entries = entries.map(([fspath, stats]) => [
132
+ upath__default.default.normalizeSafe(fspath),
133
+ stats
134
+ ]);
135
+ return options.stats ? entries : entries.map(([fspath]) => fspath);
150
136
  }
151
137
  __name(walkDirectory, "walkDirectory");
152
138
  function convertToWalkdirOptions(options) {
@@ -166,9 +152,7 @@ function convertToWalkdirOptions(options) {
166
152
  }
167
153
  if (options.filter) {
168
154
  const filter = options.filter;
169
- result.filter = (dirpath, files) => {
170
- return filter(upath__default.default.normalizeSafe(dirpath), upath__default.default.basename(dirpath)) ? files : [];
171
- };
155
+ result.filter = (dirpath, files) => filter(upath__default.default.normalizeSafe(dirpath), upath__default.default.basename(dirpath)) ? files : [];
172
156
  }
173
157
  return result;
174
158
  }
package/lib/index.js CHANGED
@@ -27,12 +27,8 @@ async function getFirstFileInDir(dirpath) {
27
27
  const dirents = await fs5.readdir(dirpath, {
28
28
  withFileTypes: true
29
29
  });
30
- const fileDirents = dirents.filter((file) => {
31
- return file.isFile();
32
- });
33
- const filenames = fileDirents.map((file) => {
34
- return file.name;
35
- });
30
+ const fileDirents = dirents.filter((file) => file.isFile());
31
+ const filenames = fileDirents.map((file) => file.name);
36
32
  const firstFileName = filenames[0];
37
33
  return firstFileName;
38
34
  }
@@ -115,29 +111,19 @@ function walkDirectory(dirpath, options) {
115
111
  return walkdir.sync(dirpath, {
116
112
  ...convertToWalkdirOptions(options),
117
113
  return_object: false
118
- }).map((fspath) => {
119
- return upath.normalizeSafe(fspath);
120
- });
114
+ }).map((fspath) => upath.normalizeSafe(fspath));
121
115
  }
122
116
  let entries = Object.entries(walkdir.sync(dirpath, convertToWalkdirOptions(options)));
123
117
  if (options.only === "files") {
124
- entries = entries.filter(([_, stats]) => {
125
- return stats.isFile();
126
- });
118
+ entries = entries.filter(([_, stats]) => stats.isFile());
127
119
  } else if (options.only === "directories") {
128
- entries = entries.filter(([_, stats]) => {
129
- return stats.isDirectory();
130
- });
120
+ entries = entries.filter(([_, stats]) => stats.isDirectory());
131
121
  }
132
- entries = entries.map(([fspath, stats]) => {
133
- return [
134
- upath.normalizeSafe(fspath),
135
- stats
136
- ];
137
- });
138
- return options.stats ? entries : entries.map(([fspath]) => {
139
- return fspath;
140
- });
122
+ entries = entries.map(([fspath, stats]) => [
123
+ upath.normalizeSafe(fspath),
124
+ stats
125
+ ]);
126
+ return options.stats ? entries : entries.map(([fspath]) => fspath);
141
127
  }
142
128
  __name(walkDirectory, "walkDirectory");
143
129
  function convertToWalkdirOptions(options) {
@@ -157,9 +143,7 @@ function convertToWalkdirOptions(options) {
157
143
  }
158
144
  if (options.filter) {
159
145
  const filter = options.filter;
160
- result.filter = (dirpath, files) => {
161
- return filter(upath.normalizeSafe(dirpath), upath.basename(dirpath)) ? files : [];
162
- };
146
+ result.filter = (dirpath, files) => filter(upath.normalizeSafe(dirpath), upath.basename(dirpath)) ? files : [];
163
147
  }
164
148
  return result;
165
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/fs",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "File system utilities for reading, updating, and managing files and directories.",
5
5
  "type": "module",
6
6
  "sideEffects": false,