@jeniex/utils 1.0.13 → 1.0.15

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/node/index.cjs CHANGED
@@ -92,6 +92,28 @@ async function listFolders({ folderPath, getFullPath }) {
92
92
  return folders;
93
93
  }
94
94
 
95
+ /**
96
+ * Get a list of folders that are present in the provided folder path.
97
+ * If the provided folder path does not exists, an error will be thrown.
98
+ */
99
+ function listFoldersSync({ folderPath, getFullPath }) {
100
+ if (fs.existsSync(folderPath) === false) {
101
+ throw new Error('The provided folder path does not exist!');
102
+ }
103
+ const entries = fs.readdirSync(folderPath, {
104
+ withFileTypes: true,
105
+ });
106
+ const folders = entries
107
+ .filter((entry) => entry.isDirectory() === true)
108
+ .map((folderEntry) => {
109
+ if (getFullPath === true) {
110
+ return path.join(folderPath, folderEntry.name);
111
+ }
112
+ return folderEntry.name;
113
+ });
114
+ return folders;
115
+ }
116
+
95
117
  async function removeFiles({ folderPath, filter }) {
96
118
  const nestedFilePathPattern = `${path.resolve('./')}\\`;
97
119
  if (!folderPath.startsWith(nestedFilePathPattern)) {
@@ -112,6 +134,7 @@ exports.isString = isString;
112
134
  exports.isTruthy = isTruthy;
113
135
  exports.listFiles = listFiles;
114
136
  exports.listFolders = listFolders;
137
+ exports.listFoldersSync = listFoldersSync;
115
138
  exports.noop = noop;
116
139
  exports.removeFiles = removeFiles;
117
140
  exports.sleep = sleep;
package/node/index.d.ts CHANGED
@@ -46,6 +46,12 @@ declare function listFiles({ folderPath, getFullPath, filter }: ListFilesOpt): P
46
46
  */
47
47
  declare function listFolders({ folderPath, getFullPath }: ListFoldersOpt): Promise<string[]>;
48
48
 
49
+ /**
50
+ * Get a list of folders that are present in the provided folder path.
51
+ * If the provided folder path does not exists, an error will be thrown.
52
+ */
53
+ declare function listFoldersSync({ folderPath, getFullPath }: ListFoldersOpt): string[];
54
+
49
55
  declare function removeFiles({ folderPath, filter }: RemoveFilesOpt): Promise<void>;
50
56
 
51
- export { Fn, Nullable, asserted, ensureJoin, isFalsy, isNotNullish, isNullish, isString, isTruthy, listFiles, listFolders, noop, removeFiles, sleep };
57
+ export { Fn, Nullable, asserted, ensureJoin, isFalsy, isNotNullish, isNullish, isString, isTruthy, listFiles, listFolders, listFoldersSync, noop, removeFiles, sleep };
package/node/index.js CHANGED
@@ -90,6 +90,28 @@ async function listFolders({ folderPath, getFullPath }) {
90
90
  return folders;
91
91
  }
92
92
 
93
+ /**
94
+ * Get a list of folders that are present in the provided folder path.
95
+ * If the provided folder path does not exists, an error will be thrown.
96
+ */
97
+ function listFoldersSync({ folderPath, getFullPath }) {
98
+ if (fs.existsSync(folderPath) === false) {
99
+ throw new Error('The provided folder path does not exist!');
100
+ }
101
+ const entries = fs.readdirSync(folderPath, {
102
+ withFileTypes: true,
103
+ });
104
+ const folders = entries
105
+ .filter((entry) => entry.isDirectory() === true)
106
+ .map((folderEntry) => {
107
+ if (getFullPath === true) {
108
+ return path.join(folderPath, folderEntry.name);
109
+ }
110
+ return folderEntry.name;
111
+ });
112
+ return folders;
113
+ }
114
+
93
115
  async function removeFiles({ folderPath, filter }) {
94
116
  const nestedFilePathPattern = `${path.resolve('./')}\\`;
95
117
  if (!folderPath.startsWith(nestedFilePathPattern)) {
@@ -101,4 +123,4 @@ async function removeFiles({ folderPath, filter }) {
101
123
  }
102
124
  }
103
125
 
104
- export { asserted, ensureJoin, isFalsy, isNotNullish, isNullish, isString, isTruthy, listFiles, listFolders, noop, removeFiles, sleep };
126
+ export { asserted, ensureJoin, isFalsy, isNotNullish, isNullish, isString, isTruthy, listFiles, listFolders, listFoldersSync, noop, removeFiles, sleep };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",