tiny-essentials 1.12.1 → 1.12.2

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.
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import { toTitleCase } from './text.mjs';
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, lstatSync, rmSync, unlinkSync, copyFileSync, statSync, renameSync, } from 'fs';
2
+ import { join, dirname, basename, extname } from 'path';
3
+ import { toTitleCase } from '../basics/text.mjs';
4
4
  /*========================*
5
5
  * JSON Operations
6
6
  *========================*/
@@ -11,9 +11,9 @@ import { toTitleCase } from './text.mjs';
11
11
  * @returns {any}
12
12
  */
13
13
  export function readJsonFile(filePath) {
14
- if (!fs.existsSync(filePath))
14
+ if (!existsSync(filePath))
15
15
  throw new Error(`File not found: ${filePath}`);
16
- const content = fs.readFileSync(filePath, 'utf-8');
16
+ const content = readFileSync(filePath, 'utf-8');
17
17
  return JSON.parse(content);
18
18
  }
19
19
  /**
@@ -25,31 +25,7 @@ export function readJsonFile(filePath) {
25
25
  */
26
26
  export function writeJsonFile(filePath, data, spaces = 2) {
27
27
  const json = JSON.stringify(data, null, spaces);
28
- fs.writeFileSync(filePath, json, 'utf-8');
29
- }
30
- /**
31
- * Reads and parses a JSON file.
32
- * Throws an error if the file content is not valid JSON.
33
- * @param {string} filePath
34
- * @returns {Promise<any>}
35
- */
36
- export async function readJsonFileAsync(filePath) {
37
- if (!fs.existsSync(filePath))
38
- throw new Error(`File not found: ${filePath}`);
39
- const content = await fs.promises.readFile(filePath, 'utf-8');
40
- return JSON.parse(content);
41
- }
42
- /**
43
- * Saves an object as JSON to a file.
44
- * Automatically creates the directory if it does not exist.
45
- * @param {string} filePath
46
- * @param {any} data
47
- * @param {number} [spaces=2]
48
- * @returns {Promise<void>}
49
- */
50
- export function writeJsonFileAsync(filePath, data, spaces = 2) {
51
- const json = JSON.stringify(data, null, spaces);
52
- return fs.promises.writeFile(filePath, json, 'utf-8');
28
+ writeFileSync(filePath, json, 'utf-8');
53
29
  }
54
30
  /*========================*
55
31
  * Directory Management
@@ -59,8 +35,8 @@ export function writeJsonFileAsync(filePath, data, spaces = 2) {
59
35
  * @param {string} dirPath
60
36
  */
61
37
  export function ensureDirectory(dirPath) {
62
- if (!fs.existsSync(dirPath)) {
63
- fs.mkdirSync(dirPath, { recursive: true });
38
+ if (!existsSync(dirPath)) {
39
+ mkdirSync(dirPath, { recursive: true });
64
40
  }
65
41
  }
66
42
  /**
@@ -68,17 +44,17 @@ export function ensureDirectory(dirPath) {
68
44
  * @param {string} dirPath
69
45
  */
70
46
  export function clearDirectory(dirPath) {
71
- if (!fs.existsSync(dirPath))
47
+ if (!existsSync(dirPath))
72
48
  return;
73
- const files = fs.readdirSync(dirPath);
49
+ const files = readdirSync(dirPath);
74
50
  for (const file of files) {
75
- const fullPath = path.join(dirPath, file);
76
- const stat = fs.lstatSync(fullPath);
77
- if (stat.isDirectory()) {
78
- fs.rmSync(fullPath, { recursive: true, force: true });
51
+ const fullPath = join(dirPath, file);
52
+ const statData = lstatSync(fullPath);
53
+ if (statData.isDirectory()) {
54
+ rmSync(fullPath, { recursive: true, force: true });
79
55
  }
80
56
  else {
81
- fs.unlinkSync(fullPath);
57
+ unlinkSync(fullPath);
82
58
  }
83
59
  }
84
60
  }
@@ -91,7 +67,7 @@ export function clearDirectory(dirPath) {
91
67
  * @returns {boolean}
92
68
  */
93
69
  export function fileExists(filePath) {
94
- return fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();
70
+ return existsSync(filePath) && lstatSync(filePath).isFile();
95
71
  }
96
72
  /**
97
73
  * Checks whether a directory exists.
@@ -99,7 +75,7 @@ export function fileExists(filePath) {
99
75
  * @returns {boolean}
100
76
  */
101
77
  export function dirExists(dirPath) {
102
- return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
78
+ return existsSync(dirPath) && lstatSync(dirPath).isDirectory();
103
79
  }
104
80
  /**
105
81
  * Checks whether a directory is empty.
@@ -107,7 +83,7 @@ export function dirExists(dirPath) {
107
83
  * @returns {boolean}
108
84
  */
109
85
  export function isDirEmpty(dirPath) {
110
- return fs.existsSync(dirPath) && fs.readdirSync(dirPath).length === 0;
86
+ return readdirSync(dirPath).length === 0;
111
87
  }
112
88
  /*========================*
113
89
  * File Operations
@@ -119,8 +95,8 @@ export function isDirEmpty(dirPath) {
119
95
  * @param {number} [mode]
120
96
  */
121
97
  export function ensureCopyFile(src, dest, mode) {
122
- ensureDirectory(path.dirname(dest));
123
- fs.copyFileSync(src, dest, mode);
98
+ ensureDirectory(dirname(dest));
99
+ copyFileSync(src, dest, mode);
124
100
  }
125
101
  /**
126
102
  * Deletes a file (If the file exists).
@@ -129,30 +105,7 @@ export function ensureCopyFile(src, dest, mode) {
129
105
  */
130
106
  export function tryDeleteFile(filePath) {
131
107
  if (fileExists(filePath)) {
132
- fs.unlinkSync(filePath);
133
- return true;
134
- }
135
- return false;
136
- }
137
- /**
138
- * Copies a file to a destination.
139
- * @param {string} src
140
- * @param {string} dest
141
- * @param {number} [mode]
142
- * @returns {Promise<void>}
143
- */
144
- export function ensureCopyFileAsync(src, dest, mode) {
145
- ensureDirectory(path.dirname(dest));
146
- return fs.promises.copyFile(src, dest, mode);
147
- }
148
- /**
149
- * Deletes a file (If the file exists).
150
- * @param {string} filePath
151
- * @returns {Promise<boolean>}
152
- */
153
- export async function tryDeleteFileAsync(filePath) {
154
- if (fileExists(filePath)) {
155
- await fs.promises.unlink(filePath);
108
+ unlinkSync(filePath);
156
109
  return true;
157
110
  }
158
111
  return false;
@@ -164,24 +117,12 @@ export async function tryDeleteFileAsync(filePath) {
164
117
  * Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
165
118
  * @param {string} filePath
166
119
  * @param {string} content
167
- * @param {fs.WriteFileOptions} [ops='utf-8']
120
+ * @param {import('fs').WriteFileOptions} [ops='utf-8']
168
121
  */
169
122
  export function writeTextFile(filePath, content, ops = 'utf-8') {
170
- const dir = path.dirname(filePath);
171
- ensureDirectory(dir);
172
- fs.writeFileSync(filePath, content, ops);
173
- }
174
- /**
175
- * Writes text to a file (Ensures that the directory exists, creating it recursively if needed).
176
- * @param {string} filePath
177
- * @param {string} content
178
- * @param {fs.WriteFileOptions} [ops='utf-8']
179
- * @returns {Promise<void>}
180
- */
181
- export function writeTextFileAsync(filePath, content, ops = 'utf-8') {
182
- const dir = path.dirname(filePath);
123
+ const dir = dirname(filePath);
183
124
  ensureDirectory(dir);
184
- return fs.promises.writeFile(filePath, content, ops);
125
+ writeFileSync(filePath, content, ops);
185
126
  }
186
127
  /*========================*
187
128
  * Directory Listings
@@ -197,11 +138,11 @@ export function listFiles(dirPath, recursive = false) {
197
138
  const results = { files: [], dirs: [] };
198
139
  if (!dirExists(dirPath))
199
140
  return results;
200
- const entries = fs.readdirSync(dirPath);
141
+ const entries = readdirSync(dirPath);
201
142
  for (const entry of entries) {
202
- const fullPath = path.join(dirPath, entry);
203
- const stat = fs.lstatSync(fullPath);
204
- if (stat.isDirectory()) {
143
+ const fullPath = join(dirPath, entry);
144
+ const statData = lstatSync(fullPath);
145
+ if (statData.isDirectory()) {
205
146
  results.dirs.push(fullPath);
206
147
  if (recursive) {
207
148
  const results2 = listFiles(fullPath, true);
@@ -226,11 +167,11 @@ export function listDirs(dirPath, recursive = false) {
226
167
  const results = [];
227
168
  if (!dirExists(dirPath))
228
169
  return results;
229
- const entries = fs.readdirSync(dirPath);
170
+ const entries = readdirSync(dirPath);
230
171
  for (const entry of entries) {
231
- const fullPath = path.join(dirPath, entry);
232
- const stat = fs.lstatSync(fullPath);
233
- if (stat.isDirectory()) {
172
+ const fullPath = join(dirPath, entry);
173
+ const statData = lstatSync(fullPath);
174
+ if (statData.isDirectory()) {
234
175
  results.push(fullPath);
235
176
  if (recursive) {
236
177
  results.push(...listDirs(fullPath, true));
@@ -250,7 +191,7 @@ export function listDirs(dirPath, recursive = false) {
250
191
  export function fileSize(filePath) {
251
192
  if (!fileExists(filePath))
252
193
  return 0;
253
- const stats = fs.statSync(filePath);
194
+ const stats = statSync(filePath);
254
195
  return stats.size;
255
196
  }
256
197
  /**
@@ -288,16 +229,15 @@ export function backupFile(filePath, ext = 'bak') {
288
229
  * @returns {string} Full path to the most recent backup
289
230
  */
290
231
  export function getLatestBackupPath(filePath, ext = 'bak') {
291
- const dir = path.dirname(filePath);
292
- const baseName = path.basename(filePath);
293
- const backups = fs
294
- .readdirSync(dir)
232
+ const dir = dirname(filePath);
233
+ const baseName = basename(filePath);
234
+ const backups = readdirSync(dir)
295
235
  .filter((name) => name.startsWith(`${baseName}.${ext}.`))
296
236
  .sort()
297
237
  .reverse();
298
238
  if (backups.length === 0)
299
239
  throw new Error(`No backups found for ${filePath}`);
300
- return path.join(dir, backups[0]);
240
+ return join(dir, backups[0]);
301
241
  }
302
242
  /**
303
243
  * Restores the most recent backup of a file.
@@ -308,29 +248,6 @@ export function restoreLatestBackup(filePath, ext = 'bak') {
308
248
  const latestBackup = getLatestBackupPath(filePath, ext);
309
249
  ensureCopyFile(latestBackup, filePath);
310
250
  }
311
- /**
312
- * Restores the most recent backup of a file.
313
- * @param {string} filePath
314
- * @param {string} [ext='bak']
315
- * @returns {Promise<void>}
316
- */
317
- export function restoreLatestBackupAsync(filePath, ext = 'bak') {
318
- const latestBackup = getLatestBackupPath(filePath, ext);
319
- return ensureCopyFileAsync(latestBackup, filePath);
320
- }
321
- /**
322
- * Creates a backup copy of a file with .bak timestamp suffix.
323
- * @param {string} filePath
324
- * @param {string} [ext='bak']
325
- * @returns {Promise<void>}
326
- */
327
- export async function backupFileAsync(filePath, ext = 'bak') {
328
- if (!fileExists(filePath))
329
- return;
330
- const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
331
- const backupPath = `${filePath}.${ext}.${timestamp}`;
332
- return ensureCopyFileAsync(filePath, backupPath);
333
- }
334
251
  /*========================*
335
252
  * Rename Utilities
336
253
  *========================*/
@@ -351,7 +268,7 @@ export function renameFileBatch(dirPath, renameFn, extensions = []) {
351
268
  throw new TypeError('renameFn must be a function');
352
269
  if (!Array.isArray(extensions))
353
270
  throw new TypeError('extensions must be an array of strings');
354
- if (!fs.existsSync(dirPath) || !fs.statSync(dirPath).isDirectory())
271
+ if (!existsSync(dirPath) || !statSync(dirPath).isDirectory())
355
272
  throw new Error(`Directory not found or invalid: ${dirPath}`);
356
273
  for (const ext of extensions) {
357
274
  if (typeof ext !== 'string' || !ext.startsWith('.'))
@@ -360,15 +277,15 @@ export function renameFileBatch(dirPath, renameFn, extensions = []) {
360
277
  const files = listFiles(dirPath).files;
361
278
  let index = 0;
362
279
  for (const file of files) {
363
- const ext = path.extname(file);
280
+ const ext = extname(file);
364
281
  if (extensions.length && !extensions.includes(ext))
365
282
  continue;
366
- const originalName = path.basename(file);
283
+ const originalName = basename(file);
367
284
  const newName = renameFn(originalName, index++);
368
- const newPath = path.join(dirPath, newName);
285
+ const newPath = join(dirPath, newName);
369
286
  if (originalName === newName)
370
287
  continue;
371
- fs.renameSync(file, newPath);
288
+ renameSync(file, newPath);
372
289
  }
373
290
  }
374
291
  /**
@@ -380,8 +297,8 @@ export function renameFileBatch(dirPath, renameFn, extensions = []) {
380
297
  */
381
298
  export function renameFileRegex(dirPath, pattern, replacement, extensions = []) {
382
299
  renameFileBatch(dirPath, (filename) => {
383
- const ext = path.extname(filename);
384
- const name = path.basename(filename, ext).replace(pattern, replacement);
300
+ const ext = extname(filename);
301
+ const name = basename(filename, ext).replace(pattern, replacement);
385
302
  return `${name}${ext}`;
386
303
  }, extensions);
387
304
  }
@@ -393,8 +310,8 @@ export function renameFileRegex(dirPath, pattern, replacement, extensions = [])
393
310
  */
394
311
  export function renameFileAddPrefixSuffix(dirPath, { prefix = '', suffix = '' }, extensions = []) {
395
312
  renameFileBatch(dirPath, (filename) => {
396
- const ext = path.extname(filename);
397
- const name = path.basename(filename, ext);
313
+ const ext = extname(filename);
314
+ const name = basename(filename, ext);
398
315
  return `${prefix}${name}${suffix}${ext}`;
399
316
  }, extensions);
400
317
  }
@@ -424,9 +341,9 @@ export function renameFileNormalizeCase(dirPath, mode = 'lower', extensions = []
424
341
  else
425
342
  return text;
426
343
  };
427
- const rawExt = path.extname(filename);
344
+ const rawExt = extname(filename);
428
345
  const ext = normalizeExt ? changeToMode(rawExt) : rawExt;
429
- const name = changeToMode(path.basename(filename, rawExt));
346
+ const name = changeToMode(basename(filename, rawExt));
430
347
  return `${name}${ext}`;
431
348
  }, extensions);
432
349
  }
package/dist/v1/index.cjs CHANGED
@@ -16,7 +16,8 @@ var TinyNotifyCenter = require('./libs/TinyNotifyCenter.cjs');
16
16
  var TinyToastNotify = require('./libs/TinyToastNotify.cjs');
17
17
  var html = require('./basics/html.cjs');
18
18
  var TinyDragDropDetector = require('./libs/TinyDragDropDetector.cjs');
19
- var fileManager = require('./basics/fileManager.cjs');
19
+ var normalFuncs = require('./fileManager/normalFuncs.cjs');
20
+ var asyncFuncs = require('./fileManager/asyncFuncs.cjs');
20
21
  var TinyDragger = require('./libs/TinyDragger.cjs');
21
22
 
22
23
 
@@ -64,26 +65,32 @@ exports.getHtmlElPadding = html.getHtmlElPadding;
64
65
  exports.readJsonBlob = html.readJsonBlob;
65
66
  exports.saveJsonFile = html.saveJsonFile;
66
67
  exports.TinyDragDropDetector = TinyDragDropDetector;
67
- exports.backupFile = fileManager.backupFile;
68
- exports.clearDirectory = fileManager.clearDirectory;
69
- exports.dirExists = fileManager.dirExists;
70
- exports.dirSize = fileManager.dirSize;
71
- exports.ensureCopyFile = fileManager.ensureCopyFile;
72
- exports.ensureDirectory = fileManager.ensureDirectory;
73
- exports.fileExists = fileManager.fileExists;
74
- exports.fileSize = fileManager.fileSize;
75
- exports.getLatestBackupPath = fileManager.getLatestBackupPath;
76
- exports.isDirEmpty = fileManager.isDirEmpty;
77
- exports.listDirs = fileManager.listDirs;
78
- exports.listFiles = fileManager.listFiles;
79
- exports.readJsonFile = fileManager.readJsonFile;
80
- exports.renameFileAddPrefixSuffix = fileManager.renameFileAddPrefixSuffix;
81
- exports.renameFileBatch = fileManager.renameFileBatch;
82
- exports.renameFileNormalizeCase = fileManager.renameFileNormalizeCase;
83
- exports.renameFilePadNumbers = fileManager.renameFilePadNumbers;
84
- exports.renameFileRegex = fileManager.renameFileRegex;
85
- exports.restoreLatestBackup = fileManager.restoreLatestBackup;
86
- exports.tryDeleteFile = fileManager.tryDeleteFile;
87
- exports.writeJsonFile = fileManager.writeJsonFile;
88
- exports.writeTextFile = fileManager.writeTextFile;
68
+ exports.backupFile = normalFuncs.backupFile;
69
+ exports.clearDirectory = normalFuncs.clearDirectory;
70
+ exports.dirExists = normalFuncs.dirExists;
71
+ exports.dirSize = normalFuncs.dirSize;
72
+ exports.ensureCopyFile = normalFuncs.ensureCopyFile;
73
+ exports.ensureDirectory = normalFuncs.ensureDirectory;
74
+ exports.fileExists = normalFuncs.fileExists;
75
+ exports.fileSize = normalFuncs.fileSize;
76
+ exports.getLatestBackupPath = normalFuncs.getLatestBackupPath;
77
+ exports.isDirEmpty = normalFuncs.isDirEmpty;
78
+ exports.listDirs = normalFuncs.listDirs;
79
+ exports.listFiles = normalFuncs.listFiles;
80
+ exports.readJsonFile = normalFuncs.readJsonFile;
81
+ exports.renameFileAddPrefixSuffix = normalFuncs.renameFileAddPrefixSuffix;
82
+ exports.renameFileBatch = normalFuncs.renameFileBatch;
83
+ exports.renameFileNormalizeCase = normalFuncs.renameFileNormalizeCase;
84
+ exports.renameFilePadNumbers = normalFuncs.renameFilePadNumbers;
85
+ exports.renameFileRegex = normalFuncs.renameFileRegex;
86
+ exports.restoreLatestBackup = normalFuncs.restoreLatestBackup;
87
+ exports.tryDeleteFile = normalFuncs.tryDeleteFile;
88
+ exports.writeJsonFile = normalFuncs.writeJsonFile;
89
+ exports.writeTextFile = normalFuncs.writeTextFile;
90
+ exports.clearDirectoryAsync = asyncFuncs.clearDirectoryAsync;
91
+ exports.dirSizeAsync = asyncFuncs.dirSizeAsync;
92
+ exports.fileSizeAsync = asyncFuncs.fileSizeAsync;
93
+ exports.isDirEmptyAsync = asyncFuncs.isDirEmptyAsync;
94
+ exports.listDirsAsync = asyncFuncs.listDirsAsync;
95
+ exports.listFilesAsync = asyncFuncs.listFilesAsync;
89
96
  exports.TinyDragger = TinyDragger;
@@ -6,35 +6,41 @@ import TinyRateLimiter from './libs/TinyRateLimiter.mjs';
6
6
  import ColorSafeStringify from './libs/ColorSafeStringify.mjs';
7
7
  import TinyPromiseQueue from './libs/TinyPromiseQueue.mjs';
8
8
  import TinyLevelUp from '../legacy/libs/userLevel.mjs';
9
+ import { isDirEmptyAsync } from './fileManager/asyncFuncs.mjs';
10
+ import { fileSizeAsync } from './fileManager/asyncFuncs.mjs';
11
+ import { dirSizeAsync } from './fileManager/asyncFuncs.mjs';
12
+ import { listFilesAsync } from './fileManager/asyncFuncs.mjs';
13
+ import { listDirsAsync } from './fileManager/asyncFuncs.mjs';
9
14
  import { getHtmlElBorders } from './basics/html.mjs';
10
15
  import { getHtmlElBordersWidth } from './basics/html.mjs';
11
16
  import { getHtmlElMargin } from './basics/html.mjs';
12
17
  import { getHtmlElPadding } from './basics/html.mjs';
13
- import { getLatestBackupPath } from './basics/fileManager.mjs';
18
+ import { getLatestBackupPath } from './fileManager/normalFuncs.mjs';
14
19
  import { fetchJson } from './basics/html.mjs';
15
20
  import { readJsonBlob } from './basics/html.mjs';
16
21
  import { saveJsonFile } from './basics/html.mjs';
17
- import { readJsonFile } from './basics/fileManager.mjs';
18
- import { writeJsonFile } from './basics/fileManager.mjs';
19
- import { ensureDirectory } from './basics/fileManager.mjs';
20
- import { clearDirectory } from './basics/fileManager.mjs';
21
- import { fileExists } from './basics/fileManager.mjs';
22
- import { dirExists } from './basics/fileManager.mjs';
23
- import { isDirEmpty } from './basics/fileManager.mjs';
24
- import { ensureCopyFile } from './basics/fileManager.mjs';
25
- import { tryDeleteFile } from './basics/fileManager.mjs';
26
- import { writeTextFile } from './basics/fileManager.mjs';
27
- import { listFiles } from './basics/fileManager.mjs';
28
- import { listDirs } from './basics/fileManager.mjs';
29
- import { fileSize } from './basics/fileManager.mjs';
30
- import { dirSize } from './basics/fileManager.mjs';
31
- import { backupFile } from './basics/fileManager.mjs';
32
- import { restoreLatestBackup } from './basics/fileManager.mjs';
33
- import { renameFileBatch } from './basics/fileManager.mjs';
34
- import { renameFileRegex } from './basics/fileManager.mjs';
35
- import { renameFileAddPrefixSuffix } from './basics/fileManager.mjs';
36
- import { renameFileNormalizeCase } from './basics/fileManager.mjs';
37
- import { renameFilePadNumbers } from './basics/fileManager.mjs';
22
+ import { readJsonFile } from './fileManager/normalFuncs.mjs';
23
+ import { writeJsonFile } from './fileManager/normalFuncs.mjs';
24
+ import { ensureDirectory } from './fileManager/normalFuncs.mjs';
25
+ import { clearDirectoryAsync } from './fileManager/asyncFuncs.mjs';
26
+ import { clearDirectory } from './fileManager/normalFuncs.mjs';
27
+ import { fileExists } from './fileManager/normalFuncs.mjs';
28
+ import { dirExists } from './fileManager/normalFuncs.mjs';
29
+ import { isDirEmpty } from './fileManager/normalFuncs.mjs';
30
+ import { ensureCopyFile } from './fileManager/normalFuncs.mjs';
31
+ import { tryDeleteFile } from './fileManager/normalFuncs.mjs';
32
+ import { writeTextFile } from './fileManager/normalFuncs.mjs';
33
+ import { listFiles } from './fileManager/normalFuncs.mjs';
34
+ import { listDirs } from './fileManager/normalFuncs.mjs';
35
+ import { fileSize } from './fileManager/normalFuncs.mjs';
36
+ import { dirSize } from './fileManager/normalFuncs.mjs';
37
+ import { backupFile } from './fileManager/normalFuncs.mjs';
38
+ import { restoreLatestBackup } from './fileManager/normalFuncs.mjs';
39
+ import { renameFileBatch } from './fileManager/normalFuncs.mjs';
40
+ import { renameFileRegex } from './fileManager/normalFuncs.mjs';
41
+ import { renameFileAddPrefixSuffix } from './fileManager/normalFuncs.mjs';
42
+ import { renameFileNormalizeCase } from './fileManager/normalFuncs.mjs';
43
+ import { renameFilePadNumbers } from './fileManager/normalFuncs.mjs';
38
44
  import { documentIsFullScreen } from './basics/fullScreen.mjs';
39
45
  import { isScreenFilled } from './basics/fullScreen.mjs';
40
46
  import { requestFullScreen } from './basics/fullScreen.mjs';
@@ -64,5 +70,5 @@ import { getTimeDuration } from './basics/clock.mjs';
64
70
  import { shuffleArray } from './basics/array.mjs';
65
71
  import { toTitleCase } from './basics/text.mjs';
66
72
  import { toTitleCaseLowerFirst } from './basics/text.mjs';
67
- export { TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, getLatestBackupPath, fetchJson, readJsonBlob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, areHtmlElsColliding, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
73
+ export { TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, getLatestBackupPath, fetchJson, readJsonBlob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, areHtmlElsColliding, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
68
74
  //# sourceMappingURL=index.d.mts.map
package/dist/v1/index.mjs CHANGED
@@ -14,6 +14,7 @@ import TinyNotifyCenter from './libs/TinyNotifyCenter.mjs';
14
14
  import TinyToastNotify from './libs/TinyToastNotify.mjs';
15
15
  import { areHtmlElsColliding, readJsonBlob, saveJsonFile, fetchJson, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, } from './basics/html.mjs';
16
16
  import TinyDragDropDetector from './libs/TinyDragDropDetector.mjs';
17
- import { readJsonFile, writeJsonFile, ensureDirectory, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, getLatestBackupPath, } from './basics/fileManager.mjs';
17
+ import { readJsonFile, writeJsonFile, ensureDirectory, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, getLatestBackupPath, } from './fileManager/normalFuncs.mjs';
18
+ import { listFilesAsync, listDirsAsync, clearDirectoryAsync, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, } from './fileManager/asyncFuncs.mjs';
18
19
  import TinyDragger from './libs/TinyDragger.mjs';
19
- export { TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, getLatestBackupPath, fetchJson, readJsonBlob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, areHtmlElsColliding, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
20
+ export { TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getHtmlElBorders, getHtmlElBordersWidth, getHtmlElMargin, getHtmlElPadding, getLatestBackupPath, fetchJson, readJsonBlob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, areHtmlElsColliding, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
@@ -3,6 +3,7 @@
3
3
  var objFilter = require('../basics/objFilter.cjs');
4
4
  require('fs');
5
5
  require('path');
6
+ require('fs/promises');
6
7
 
7
8
  /**
8
9
  * @typedef {Object} UploaderConfig
package/docs/v1/README.md CHANGED
@@ -20,7 +20,6 @@ This folder contains the core scripts we have worked on so far. Each file is a m
20
20
  - 🔄 **[asyncReplace](./basics/asyncReplace.md)** — Asynchronously replaces matches in a string using a regex and an async function.
21
21
  - 🖼️ **[html](./basics/html.md)** — Utilities for handling DOM element interactions like collision detection and basic element manipulation.
22
22
  - 📺 **[fullScreen](./basics/fullScreen.md)** — A complete fullscreen API manager with detection, event handling, and cross-browser compatibility.
23
- * 📁 **[fileManager](./basics/fileManager.mjs.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
24
23
 
25
24
  ### 2. **`libs/`**
26
25
  - 🗂️ **[TinyPromiseQueue](./libs/TinyPromiseQueue.md)** — A class that allows sequential execution of asynchronous tasks, supporting task delays, cancellation, and queue management.
@@ -33,6 +32,9 @@ This folder contains the core scripts we have worked on so far. Each file is a m
33
32
  * 📂 **[TinyUploadClicker](./libs/TinyUploadClicker.md)** — A minimal utility to bind any clickable element to a hidden file input, offering full control over styling, behavior, and upload event hooks.
34
33
  * 🧲 **[TinyDragger](./libs/TinyDragger.md)** — A flexible drag-and-drop manager with collision detection, jail constraints, vibration feedback, visual proxies, revert-on-drop, and full custom event support.
35
34
 
35
+ ### 3. **`fileManager/`**
36
+ * 📁 **[main](./fileManager/main.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
37
+
36
38
  ---
37
39
 
38
40
  ## 🚀 Usage
@@ -32,6 +32,8 @@ A powerful and flexible utility toolkit for managing files and directories in No
32
32
 
33
33
  🧹 Deletes all contents inside a directory while keeping the directory itself.
34
34
 
35
+ * Async version: `clearDirectoryAsync`.
36
+
35
37
  ---
36
38
 
37
39
  ## 🧪 File Checks
@@ -48,6 +50,8 @@ A powerful and flexible utility toolkit for managing files and directories in No
48
50
 
49
51
  📭 Checks if a directory is empty.
50
52
 
53
+ * Async version: `isDirEmptyAsync`.
54
+
51
55
  ---
52
56
 
53
57
  ## 📄 File Operations
@@ -82,10 +86,14 @@ A powerful and flexible utility toolkit for managing files and directories in No
82
86
 
83
87
  📃 Lists all files and dirs in a directory. Can be recursive.
84
88
 
89
+ * Async version: `listFilesAsync`.
90
+
85
91
  ### `listDirs(dirPath: string, recursive?: boolean): string[]`
86
92
 
87
93
  📁 Lists all directories in a directory. Can be recursive.
88
94
 
95
+ * Async version: `listDirsAsync`.
96
+
89
97
  ---
90
98
 
91
99
  ## 📏 File Info
@@ -94,10 +102,14 @@ A powerful and flexible utility toolkit for managing files and directories in No
94
102
 
95
103
  ⚖️ Gets the size of a single file in bytes.
96
104
 
105
+ * Async version: `fileSizeAsync`.
106
+
97
107
  ### `dirSize(dirPath: string): number`
98
108
 
99
109
  📦 Gets the total size of all files inside a directory (recursive).
100
110
 
111
+ * Async version: `dirSizeAsync`.
112
+
101
113
  ---
102
114
 
103
115
  ## 💾 Backup Utilities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",
@@ -46,6 +46,10 @@
46
46
  "./basics": {
47
47
  "require": "./dist/v1/basics/index.cjs",
48
48
  "import": "./dist/v1/basics/index.mjs"
49
+ },
50
+ "./fileManager": {
51
+ "require": "./dist/v1/fileManager/index.cjs",
52
+ "import": "./dist/v1/fileManager/index.mjs"
49
53
  }
50
54
  },
51
55
  "repository": {