@jeniex/utils 1.0.16 → 1.0.18

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/browser/index.cjs CHANGED
@@ -36,7 +36,7 @@ function join(object, separator = ',') {
36
36
 
37
37
  /**
38
38
  * Removes an item from an array by mutating it.
39
- * @throws An error if the object to be removed does not exist inside the array.
39
+ * @throws an error if the object to be removed does not exist inside the array.
40
40
  *
41
41
  * @category Array
42
42
  */
@@ -7,7 +7,7 @@ declare function join(object: string[] | string, separator?: string): string;
7
7
 
8
8
  /**
9
9
  * Removes an item from an array by mutating it.
10
- * @throws An error if the object to be removed does not exist inside the array.
10
+ * @throws an error if the object to be removed does not exist inside the array.
11
11
  *
12
12
  * @category Array
13
13
  */
package/browser/index.js CHANGED
@@ -34,7 +34,7 @@ function join(object, separator = ',') {
34
34
 
35
35
  /**
36
36
  * Removes an item from an array by mutating it.
37
- * @throws An error if the object to be removed does not exist inside the array.
37
+ * @throws an error if the object to be removed does not exist inside the array.
38
38
  *
39
39
  * @category Array
40
40
  */
package/node/index.cjs CHANGED
@@ -40,7 +40,7 @@ function join(object, separator = ',') {
40
40
 
41
41
  /**
42
42
  * Removes an item from an array by mutating it.
43
- * @throws An error if the object to be removed does not exist inside the array.
43
+ * @throws an error if the object to be removed does not exist inside the array.
44
44
  *
45
45
  * @category Array
46
46
  */
@@ -83,12 +83,14 @@ async function sleep(milliSeconds) {
83
83
  }
84
84
 
85
85
  /**
86
- * Get a list of files that are present in the provided folder path.
87
- * If the provided folder path does not exists, it will return an empty array.
86
+ * Lists the files that are present in the provided folder path.
87
+ * @throws an error if the provided folder path does not exist.
88
+ *
89
+ * @category File-System
88
90
  */
89
91
  async function listFiles({ folderPath, getFullPath, filter }) {
90
92
  if (fs.existsSync(folderPath) === false) {
91
- return [];
93
+ throw new Error('The provided folder path does not exist!');
92
94
  }
93
95
  const entries = await fsp.readdir(folderPath, {
94
96
  withFileTypes: true,
@@ -111,8 +113,10 @@ async function listFiles({ folderPath, getFullPath, filter }) {
111
113
  }
112
114
 
113
115
  /**
114
- * Get a list of folders that are present in the provided folder path.
115
- * If the provided folder path does not exists, an error will be thrown.
116
+ * Lists the folders that are present in the provided folder path.
117
+ * @throws an error if the provided folder path does not exist.
118
+ *
119
+ * @category File-System
116
120
  */
117
121
  async function listFolders({ folderPath, getFullPath }) {
118
122
  if (fs.existsSync(folderPath) === false) {
@@ -133,8 +137,10 @@ async function listFolders({ folderPath, getFullPath }) {
133
137
  }
134
138
 
135
139
  /**
136
- * Get a list of folders that are present in the provided folder path.
137
- * If the provided folder path does not exists, an error will be thrown.
140
+ * Lists the folders that are present in the provided folder path.
141
+ * @throws an error if the provided folder path does not exist.
142
+ *
143
+ * @category File-System
138
144
  */
139
145
  function listFoldersSync({ folderPath, getFullPath }) {
140
146
  if (fs.existsSync(folderPath) === false) {
@@ -154,6 +160,13 @@ function listFoldersSync({ folderPath, getFullPath }) {
154
160
  return folders;
155
161
  }
156
162
 
163
+ /**
164
+ * Removes the files that are present in the provided folder path.
165
+ * @throws an error if the provided folder path does not exist.
166
+ * @throws an error if the files are outside or at the root of the project folder.
167
+ *
168
+ * @category File-System
169
+ */
157
170
  async function removeFiles({ folderPath, filter }) {
158
171
  const nestedFilePathPattern = `${path.resolve('./')}\\`;
159
172
  if (!folderPath.startsWith(nestedFilePathPattern)) {
package/node/index.d.ts CHANGED
@@ -7,7 +7,7 @@ declare function join(object: string[] | string, separator?: string): string;
7
7
 
8
8
  /**
9
9
  * Removes an item from an array by mutating it.
10
- * @throws An error if the object to be removed does not exist inside the array.
10
+ * @throws an error if the object to be removed does not exist inside the array.
11
11
  *
12
12
  * @category Array
13
13
  */
@@ -58,23 +58,36 @@ interface RemoveFilesOpt extends Omit<ListFilesOpt, 'getFullPath'> {
58
58
  }
59
59
 
60
60
  /**
61
- * Get a list of files that are present in the provided folder path.
62
- * If the provided folder path does not exists, it will return an empty array.
61
+ * Lists the files that are present in the provided folder path.
62
+ * @throws an error if the provided folder path does not exist.
63
+ *
64
+ * @category File-System
63
65
  */
64
66
  declare function listFiles({ folderPath, getFullPath, filter }: ListFilesOpt): Promise<string[]>;
65
67
 
66
68
  /**
67
- * Get a list of folders that are present in the provided folder path.
68
- * If the provided folder path does not exists, an error will be thrown.
69
+ * Lists the folders that are present in the provided folder path.
70
+ * @throws an error if the provided folder path does not exist.
71
+ *
72
+ * @category File-System
69
73
  */
70
74
  declare function listFolders({ folderPath, getFullPath }: ListFoldersOpt): Promise<string[]>;
71
75
 
72
76
  /**
73
- * Get a list of folders that are present in the provided folder path.
74
- * If the provided folder path does not exists, an error will be thrown.
77
+ * Lists the folders that are present in the provided folder path.
78
+ * @throws an error if the provided folder path does not exist.
79
+ *
80
+ * @category File-System
75
81
  */
76
82
  declare function listFoldersSync({ folderPath, getFullPath }: ListFoldersOpt): string[];
77
83
 
84
+ /**
85
+ * Removes the files that are present in the provided folder path.
86
+ * @throws an error if the provided folder path does not exist.
87
+ * @throws an error if the files are outside or at the root of the project folder.
88
+ *
89
+ * @category File-System
90
+ */
78
91
  declare function removeFiles({ folderPath, filter }: RemoveFilesOpt): Promise<void>;
79
92
 
80
93
  declare function readJSON<T = object>(filePath: string, withComments?: boolean): Promise<T>;
package/node/index.js CHANGED
@@ -38,7 +38,7 @@ function join(object, separator = ',') {
38
38
 
39
39
  /**
40
40
  * Removes an item from an array by mutating it.
41
- * @throws An error if the object to be removed does not exist inside the array.
41
+ * @throws an error if the object to be removed does not exist inside the array.
42
42
  *
43
43
  * @category Array
44
44
  */
@@ -81,12 +81,14 @@ async function sleep(milliSeconds) {
81
81
  }
82
82
 
83
83
  /**
84
- * Get a list of files that are present in the provided folder path.
85
- * If the provided folder path does not exists, it will return an empty array.
84
+ * Lists the files that are present in the provided folder path.
85
+ * @throws an error if the provided folder path does not exist.
86
+ *
87
+ * @category File-System
86
88
  */
87
89
  async function listFiles({ folderPath, getFullPath, filter }) {
88
90
  if (fs.existsSync(folderPath) === false) {
89
- return [];
91
+ throw new Error('The provided folder path does not exist!');
90
92
  }
91
93
  const entries = await fsp.readdir(folderPath, {
92
94
  withFileTypes: true,
@@ -109,8 +111,10 @@ async function listFiles({ folderPath, getFullPath, filter }) {
109
111
  }
110
112
 
111
113
  /**
112
- * Get a list of folders that are present in the provided folder path.
113
- * If the provided folder path does not exists, an error will be thrown.
114
+ * Lists the folders that are present in the provided folder path.
115
+ * @throws an error if the provided folder path does not exist.
116
+ *
117
+ * @category File-System
114
118
  */
115
119
  async function listFolders({ folderPath, getFullPath }) {
116
120
  if (fs.existsSync(folderPath) === false) {
@@ -131,8 +135,10 @@ async function listFolders({ folderPath, getFullPath }) {
131
135
  }
132
136
 
133
137
  /**
134
- * Get a list of folders that are present in the provided folder path.
135
- * If the provided folder path does not exists, an error will be thrown.
138
+ * Lists the folders that are present in the provided folder path.
139
+ * @throws an error if the provided folder path does not exist.
140
+ *
141
+ * @category File-System
136
142
  */
137
143
  function listFoldersSync({ folderPath, getFullPath }) {
138
144
  if (fs.existsSync(folderPath) === false) {
@@ -152,6 +158,13 @@ function listFoldersSync({ folderPath, getFullPath }) {
152
158
  return folders;
153
159
  }
154
160
 
161
+ /**
162
+ * Removes the files that are present in the provided folder path.
163
+ * @throws an error if the provided folder path does not exist.
164
+ * @throws an error if the files are outside or at the root of the project folder.
165
+ *
166
+ * @category File-System
167
+ */
155
168
  async function removeFiles({ folderPath, filter }) {
156
169
  const nestedFilePathPattern = `${path.resolve('./')}\\`;
157
170
  if (!folderPath.startsWith(nestedFilePathPattern)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@commitlint/cli": "^17.7.1",
36
36
  "@commitlint/config-conventional": "^17.7.0",
37
- "@jeniex/eslint-config": "^0.0.3",
37
+ "@jeniex/eslint-config": "^1.0.2",
38
38
  "@rollup/plugin-typescript": "^11.1.3",
39
39
  "@types/inquirer": "^9.0.3",
40
40
  "@types/node": "^20.5.7",