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.
- package/dist/legacy/firebase/index.mjs +5 -5
- package/dist/v1/TinyBasicsEs.js +1 -1257
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyEssentials.js +336 -146
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +330 -147
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/index.cjs +0 -23
- package/dist/v1/basics/index.d.mts +1 -23
- package/dist/v1/basics/index.mjs +1 -2
- package/dist/v1/fileManager/asyncFuncs.cjs +272 -0
- package/dist/v1/fileManager/asyncFuncs.d.mts +93 -0
- package/dist/v1/fileManager/asyncFuncs.mjs +236 -0
- package/dist/v1/fileManager/index.cjs +35 -0
- package/dist/v1/fileManager/index.d.mts +30 -0
- package/dist/v1/fileManager/index.mjs +3 -0
- package/dist/v1/{basics/fileManager.cjs → fileManager/normalFuncs.cjs} +10 -105
- package/dist/v1/{basics/fileManager.d.mts → fileManager/normalFuncs.d.mts} +3 -56
- package/dist/v1/{basics/fileManager.mjs → fileManager/normalFuncs.mjs} +48 -131
- package/dist/v1/index.cjs +30 -23
- package/dist/v1/index.d.mts +29 -23
- package/dist/v1/index.mjs +3 -2
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +3 -1
- package/docs/v1/{basics/fileManager.md → fileManager/main.md} +12 -0
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { toTitleCase } from '
|
|
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 (!
|
|
14
|
+
if (!existsSync(filePath))
|
|
15
15
|
throw new Error(`File not found: ${filePath}`);
|
|
16
|
-
const content =
|
|
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
|
-
|
|
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 (!
|
|
63
|
-
|
|
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 (!
|
|
47
|
+
if (!existsSync(dirPath))
|
|
72
48
|
return;
|
|
73
|
-
const files =
|
|
49
|
+
const files = readdirSync(dirPath);
|
|
74
50
|
for (const file of files) {
|
|
75
|
-
const fullPath =
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
123
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
141
|
+
const entries = readdirSync(dirPath);
|
|
201
142
|
for (const entry of entries) {
|
|
202
|
-
const fullPath =
|
|
203
|
-
const
|
|
204
|
-
if (
|
|
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 =
|
|
170
|
+
const entries = readdirSync(dirPath);
|
|
230
171
|
for (const entry of entries) {
|
|
231
|
-
const fullPath =
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
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 =
|
|
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 =
|
|
292
|
-
const baseName =
|
|
293
|
-
const backups =
|
|
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
|
|
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 (!
|
|
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 =
|
|
280
|
+
const ext = extname(file);
|
|
364
281
|
if (extensions.length && !extensions.includes(ext))
|
|
365
282
|
continue;
|
|
366
|
-
const originalName =
|
|
283
|
+
const originalName = basename(file);
|
|
367
284
|
const newName = renameFn(originalName, index++);
|
|
368
|
-
const newPath =
|
|
285
|
+
const newPath = join(dirPath, newName);
|
|
369
286
|
if (originalName === newName)
|
|
370
287
|
continue;
|
|
371
|
-
|
|
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 =
|
|
384
|
-
const name =
|
|
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 =
|
|
397
|
-
const name =
|
|
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 =
|
|
344
|
+
const rawExt = extname(filename);
|
|
428
345
|
const ext = normalizeExt ? changeToMode(rawExt) : rawExt;
|
|
429
|
-
const name = changeToMode(
|
|
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
|
|
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 =
|
|
68
|
-
exports.clearDirectory =
|
|
69
|
-
exports.dirExists =
|
|
70
|
-
exports.dirSize =
|
|
71
|
-
exports.ensureCopyFile =
|
|
72
|
-
exports.ensureDirectory =
|
|
73
|
-
exports.fileExists =
|
|
74
|
-
exports.fileSize =
|
|
75
|
-
exports.getLatestBackupPath =
|
|
76
|
-
exports.isDirEmpty =
|
|
77
|
-
exports.listDirs =
|
|
78
|
-
exports.listFiles =
|
|
79
|
-
exports.readJsonFile =
|
|
80
|
-
exports.renameFileAddPrefixSuffix =
|
|
81
|
-
exports.renameFileBatch =
|
|
82
|
-
exports.renameFileNormalizeCase =
|
|
83
|
-
exports.renameFilePadNumbers =
|
|
84
|
-
exports.renameFileRegex =
|
|
85
|
-
exports.restoreLatestBackup =
|
|
86
|
-
exports.tryDeleteFile =
|
|
87
|
-
exports.writeJsonFile =
|
|
88
|
-
exports.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;
|
package/dist/v1/index.d.mts
CHANGED
|
@@ -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 './
|
|
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 './
|
|
18
|
-
import { writeJsonFile } from './
|
|
19
|
-
import { ensureDirectory } from './
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
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 './
|
|
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, };
|
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.
|
|
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": {
|