@d0paminedriven/fs 10.0.0 → 11.0.0
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/docs/index.d.ts +119 -0
- package/dist/docs/index.js +1027 -0
- package/dist/extract/client.d.ts +54 -0
- package/dist/extract/client.js +118 -0
- package/dist/extract/index.d.ts +69 -0
- package/dist/extract/index.js +622 -0
- package/dist/fs/index.d.ts +19 -55
- package/dist/fs/index.js +88 -19
- package/dist/fs-atomic/index.d.ts +28 -36
- package/dist/fs-atomic/index.js +88 -13
- package/dist/fs-base/index.d.ts +105 -111
- package/dist/fs-base/index.js +188 -12
- package/dist/fs-core/index.d.ts +20 -24
- package/dist/fs-core/index.js +44 -16
- package/dist/fs-fetch/index.d.ts +48 -62
- package/dist/fs-fetch/index.js +146 -18
- package/dist/fs-size/index.d.ts +16 -28
- package/dist/fs-size/index.js +64 -15
- package/dist/fs-tmp/index.d.ts +179 -192
- package/dist/fs-tmp/index.js +321 -17
- package/dist/images/index.d.ts +447 -0
- package/dist/images/index.js +899 -0
- package/dist/images/workup.d.ts +30 -0
- package/dist/images/workup.js +317 -0
- package/dist/index.d.ts +20 -22
- package/dist/index.js +20 -64
- package/dist/ld/index.d.ts +15 -13
- package/dist/ld/index.js +56 -6
- package/dist/mime/index.d.ts +299 -294
- package/dist/mime/index.js +348 -13
- package/dist/mixins/index.d.ts +34 -0
- package/dist/mixins/index.js +54 -0
- package/dist/types/index.d.ts +279 -215
- package/dist/types/index.js +11 -6
- package/dist/types/stream.d.ts +6 -4
- package/dist/types/stream.js +1 -1
- package/dist/url/index.d.ts +15 -18
- package/dist/url/index.js +21 -8
- package/dist/utils/index.d.ts +19 -23
- package/dist/utils/index.js +82 -7
- package/package.json +33 -13
- package/dist/chunk-5CACVZVF.js +0 -386
- package/dist/chunk-5H6GE5AO.js +0 -14
- package/dist/chunk-7JQ56XIH.js +0 -187
- package/dist/chunk-7LOAFIZM.js +0 -77
- package/dist/chunk-7QVYU63E.js +0 -7
- package/dist/chunk-DNR5ZI2T.js +0 -75
- package/dist/chunk-L2QMQOEJ.js +0 -366
- package/dist/chunk-NJHN5OE3.js +0 -33
- package/dist/chunk-OHKRQJZH.js +0 -82
- package/dist/chunk-OT5JEQKW.js +0 -139
- package/dist/chunk-PATMSIQK.js +0 -367
- package/dist/chunk-PB5A7ZFD.js +0 -79
- package/dist/chunk-VDKUXJE7.js +0 -240
- package/dist/chunk-Y5QWE4EG.js +0 -1335
- package/dist/chunk-YRCJWFZD.js +0 -107
- package/dist/image/index.d.ts +0 -182
- package/dist/image/index.js +0 -13
- package/dist/image/workup.d.ts +0 -40
- package/dist/image/workup.js +0 -12
package/dist/chunk-PATMSIQK.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FsCore
|
|
3
|
-
} from "./chunk-OHKRQJZH.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/fs-tmp/index.ts
|
|
9
|
-
import fsSync from "fs";
|
|
10
|
-
import fsAsync from "fs/promises";
|
|
11
|
-
import { resolve } from "path";
|
|
12
|
-
var FsTmp = class extends FsCore {
|
|
13
|
-
constructor(cwd) {
|
|
14
|
-
super(cwd ??= process.cwd());
|
|
15
|
-
this.cwd = cwd;
|
|
16
|
-
}
|
|
17
|
-
static {
|
|
18
|
-
__name(this, "FsTmp");
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Write data to a file in the system's tmp directory
|
|
22
|
-
* @param filename The filename (can include subdirectories like "img-probe/file.txt")
|
|
23
|
-
* @param data The data to write
|
|
24
|
-
* @param options Optional write stream options
|
|
25
|
-
* @returns The full path to the written file
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const fs = new Fs(process.cwd());
|
|
29
|
-
* const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
|
|
30
|
-
* // Or with a subdirectory:
|
|
31
|
-
* fs.writeTmp("img-probe/output.png", imageBuffer);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
writeTmp(filename, data, options) {
|
|
35
|
-
const fullPath = resolve(this.tmpDir, filename);
|
|
36
|
-
Promise.resolve(this.withWs(fullPath, data, options));
|
|
37
|
-
}
|
|
38
|
-
async writeTmpAsync(filename, data, options = {}) {
|
|
39
|
-
const fullPath = resolve(this.tmpDir, filename);
|
|
40
|
-
return await this.writeFileAsync(
|
|
41
|
-
fullPath,
|
|
42
|
-
data,
|
|
43
|
-
typeof options === "object" ? { ...options, mode: 511 } : options
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
async readTmpAsync(filename) {
|
|
47
|
-
const fullPath = resolve(this.tmpDir, filename);
|
|
48
|
-
if (!this.existsTmp(filename)) {
|
|
49
|
-
throw new Error(`Tmp file not found: ${filename}`);
|
|
50
|
-
}
|
|
51
|
-
return await fsAsync.readFile(fullPath);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Read a file from the tmp directory
|
|
55
|
-
* @param filename The filename to read (can include subdirectories)
|
|
56
|
-
* @returns Buffer containing the file data
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* const fs = new Fs(process.cwd());
|
|
60
|
-
* const data = fs.readTmp("session-data.json");
|
|
61
|
-
* const parsed = JSON.parse(data.toString("utf-8"));
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
readTmp(filename) {
|
|
65
|
-
const fullPath = resolve(this.tmpDir, filename);
|
|
66
|
-
if (!this.exists(fullPath)) {
|
|
67
|
-
throw new Error(`Tmp file not found: ${filename}`);
|
|
68
|
-
}
|
|
69
|
-
return this.fileToBuffer(fullPath);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Scan the tmp directory for files matching a pattern
|
|
73
|
-
* @param pattern Optional pattern to filter files (e.g., "img-probe")
|
|
74
|
-
* @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
|
|
75
|
-
* @returns Array of matching file paths relative to tmp directory
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* const fs = new Fs(process.cwd());
|
|
79
|
-
* // Get all img-probe files
|
|
80
|
-
* const imgFiles = fs.scanTmp("img-probe");
|
|
81
|
-
* // Get all files in tmp (non-recursive)
|
|
82
|
-
* const allFiles = fs.scanTmp();
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
scanTmp(pattern, options = {
|
|
86
|
-
recursive: false,
|
|
87
|
-
withFileTypes: false,
|
|
88
|
-
encoding: "utf-8"
|
|
89
|
-
}) {
|
|
90
|
-
const dirs = resolve(this.tmpDir);
|
|
91
|
-
const tmpContents = this.readDir(dirs, options);
|
|
92
|
-
if (!pattern) {
|
|
93
|
-
return tmpContents;
|
|
94
|
-
}
|
|
95
|
-
if (typeof pattern === "string") {
|
|
96
|
-
return tmpContents.filter((t) => t.includes(pattern));
|
|
97
|
-
}
|
|
98
|
-
return tmpContents.filter((path) => {
|
|
99
|
-
return pattern.test(path);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Extract specific files from tmp directory to a target location
|
|
104
|
-
* @param pattern Pattern to match files (e.g., "img-probe")
|
|
105
|
-
* @param targetDir Target directory to extract files to
|
|
106
|
-
* @param options Options for extraction behavior
|
|
107
|
-
* @returns Array of extracted file paths
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* const fs = new Fs(process.cwd());
|
|
111
|
-
* // Extract all img-probe files to ./output
|
|
112
|
-
* const extracted = fs.extractFromTmp("img-probe", "./output");
|
|
113
|
-
* // Extract with custom behavior
|
|
114
|
-
* fs.extractFromTmp("session-", "./sessions", {
|
|
115
|
-
* preserveStructure: true,
|
|
116
|
-
* cleanupAfter: true
|
|
117
|
-
* });
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
extractFromTmp(pattern, targetDir, options) {
|
|
121
|
-
const {
|
|
122
|
-
preserveStructure = false,
|
|
123
|
-
cleanupAfter = false,
|
|
124
|
-
overwrite = true
|
|
125
|
-
} = options ?? {};
|
|
126
|
-
const matchingFiles = this.scanTmp(pattern);
|
|
127
|
-
const extracted = [];
|
|
128
|
-
for (const file of matchingFiles) {
|
|
129
|
-
const sourcePath = resolve(this.tmpDir, file);
|
|
130
|
-
const lastSegment = file.includes("/") ? file.split("/").pop() : file;
|
|
131
|
-
if (!lastSegment) continue;
|
|
132
|
-
const targetPath = preserveStructure ? resolve(targetDir, file) : resolve(targetDir, lastSegment);
|
|
133
|
-
if (this.exists(targetPath) && !overwrite) {
|
|
134
|
-
console.warn(`Skipping existing file: ${targetPath}`);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const data = this.fileToBuffer(sourcePath);
|
|
138
|
-
this.withWs(targetPath, data);
|
|
139
|
-
extracted.push(targetPath);
|
|
140
|
-
if (cleanupAfter) {
|
|
141
|
-
this.rmFile(sourcePath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return extracted;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Clean up tmp files matching a pattern
|
|
148
|
-
* @param pattern Pattern to match files for deletion
|
|
149
|
-
* @param maxAge Optional max age in milliseconds (only delete files older than this)
|
|
150
|
-
* @returns Number of files removed
|
|
151
|
-
* @example
|
|
152
|
-
* ```ts
|
|
153
|
-
* const fs = new Fs(process.cwd());
|
|
154
|
-
* // Remove all img-probe files
|
|
155
|
-
* fs.cleanupTmp("img-probe");
|
|
156
|
-
* // Remove session files older than 1 hour
|
|
157
|
-
* fs.cleanupTmp("session-", 60 * 60 * 1000);
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
cleanupTmp(pattern, maxAge) {
|
|
161
|
-
const matchingFiles = this.scanTmp(pattern);
|
|
162
|
-
let removed = 0;
|
|
163
|
-
for (const file of matchingFiles) {
|
|
164
|
-
const fullPath = resolve(this.tmpDir, file);
|
|
165
|
-
try {
|
|
166
|
-
const stats = fsSync.statSync(fullPath);
|
|
167
|
-
if (maxAge) {
|
|
168
|
-
const age = Date.now() - stats.mtimeMs;
|
|
169
|
-
if (age < maxAge) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (stats.isDirectory()) {
|
|
174
|
-
this.rmDirSync(fullPath);
|
|
175
|
-
} else {
|
|
176
|
-
this.rmFile(fullPath);
|
|
177
|
-
}
|
|
178
|
-
removed++;
|
|
179
|
-
} catch (err) {
|
|
180
|
-
console.warn(`Failed to remove tmp file ${file}:`, err);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return removed;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Generate a unique tmp filename with optional prefix
|
|
187
|
-
* @param prefix Optional prefix for the filename
|
|
188
|
-
* @param extension Optional file extension (without dot)
|
|
189
|
-
* @returns Unique filename
|
|
190
|
-
* @example
|
|
191
|
-
* ```ts
|
|
192
|
-
* const fs = new Fs(process.cwd());
|
|
193
|
-
* const filename = fs.uniqueTmpName("img-probe", "png");
|
|
194
|
-
* // Returns: "img-probe-1701234567890-a3b2c1.png"
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
uniqueTmpName(prefix, extension) {
|
|
198
|
-
const timestamp = Date.now();
|
|
199
|
-
const random = Math.random().toString(36).substring(2, 8);
|
|
200
|
-
const parts = [prefix ?? "tmp", timestamp, random].join("-");
|
|
201
|
-
return extension ? `${parts}.${extension}` : parts;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Async generator for cleaning tmp files with batched removal
|
|
205
|
-
* @param pattern Pattern to match files for deletion
|
|
206
|
-
* @param batchSize Number of files to remove per batch (default 10)
|
|
207
|
-
* @yields Progress information during cleanup
|
|
208
|
-
* @returns Final cleanup summary
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* const fs = new Fs(process.cwd());
|
|
212
|
-
* // Clean up with progress tracking
|
|
213
|
-
* for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
|
|
214
|
-
* console.log(progress);
|
|
215
|
-
* }
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
async *cleanTmpGenerator(pattern, batchSize = 10) {
|
|
219
|
-
const files = this.scanTmp(pattern);
|
|
220
|
-
const batches = await this.arrToArrOfArrs({
|
|
221
|
-
arrToFragment: files,
|
|
222
|
-
arrOfArrsAggregator: [],
|
|
223
|
-
interval: batchSize
|
|
224
|
-
});
|
|
225
|
-
let totalRemoved = 0;
|
|
226
|
-
for (const [index, batch] of batches.entries()) {
|
|
227
|
-
yield {
|
|
228
|
-
action: "removing",
|
|
229
|
-
batch: [...batch],
|
|
230
|
-
batchNumber: index + 1,
|
|
231
|
-
totalBatches: batches.length,
|
|
232
|
-
totalFound: files.length,
|
|
233
|
-
removed: totalRemoved
|
|
234
|
-
};
|
|
235
|
-
for (const file of batch) {
|
|
236
|
-
this.rmTmpFile(file);
|
|
237
|
-
totalRemoved++;
|
|
238
|
-
}
|
|
239
|
-
yield {
|
|
240
|
-
action: "batch-complete",
|
|
241
|
-
batchNumber: index + 1,
|
|
242
|
-
batchSize: batch.length,
|
|
243
|
-
totalRemoved,
|
|
244
|
-
remaining: files.length - totalRemoved
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
action: "complete",
|
|
249
|
-
totalRemoved,
|
|
250
|
-
totalBatches: batches.length,
|
|
251
|
-
pattern: pattern.toString()
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Async version of withWs with atomic write support and progress tracking
|
|
256
|
-
* @param path Target file path
|
|
257
|
-
* @param data Streamable data to write
|
|
258
|
-
* @param options Optional atomic write and abort signal
|
|
259
|
-
* @returns Promise with path and bytes written
|
|
260
|
-
* @example
|
|
261
|
-
* ```ts
|
|
262
|
-
* const fs = new Fs(process.cwd());
|
|
263
|
-
* // Simple async write
|
|
264
|
-
* const result = await fs.asyncWithWs("output.txt", "Hello World");
|
|
265
|
-
* console.log(`Wrote ${result.bytes} bytes to ${result.path}`);
|
|
266
|
-
*
|
|
267
|
-
* // Atomic write with temp file
|
|
268
|
-
* const { path, bytes } = await fs.asyncWithWs(
|
|
269
|
-
* "critical-data.json",
|
|
270
|
-
* JSON.stringify(data),
|
|
271
|
-
* { atomic: true }
|
|
272
|
-
* );
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
async asyncWithWs(path, data, options) {
|
|
276
|
-
const { atomic = false, signal: _signal = AbortSignal } = options ?? {};
|
|
277
|
-
let bytes = 0;
|
|
278
|
-
if (!atomic) {
|
|
279
|
-
try {
|
|
280
|
-
if (/\//g.test(path)) {
|
|
281
|
-
return this.generateDirIfDNETmp(this.pathHandler(path), {
|
|
282
|
-
recursive: true
|
|
283
|
-
});
|
|
284
|
-
} else return path;
|
|
285
|
-
} catch (error) {
|
|
286
|
-
console.error(
|
|
287
|
-
`[asyncWithWs non-atomic error]: `.concat(
|
|
288
|
-
error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
289
|
-
)
|
|
290
|
-
);
|
|
291
|
-
} finally {
|
|
292
|
-
const readable = this.toReadable(data);
|
|
293
|
-
const chunks = [];
|
|
294
|
-
for await (const chunk of readable) {
|
|
295
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
296
|
-
}
|
|
297
|
-
const buffer = Buffer.concat(chunks);
|
|
298
|
-
try {
|
|
299
|
-
this.withWs(path, buffer);
|
|
300
|
-
} catch (err) {
|
|
301
|
-
console.error(err);
|
|
302
|
-
} finally {
|
|
303
|
-
return { path, bytes: buffer.length };
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
let tmpName;
|
|
308
|
-
try {
|
|
309
|
-
if (/\//g.test(path)) {
|
|
310
|
-
this.generateDirIfDNETmp(this.pathHandler(path), {
|
|
311
|
-
recursive: true
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
tmpName = this.uniqueTmpName("atomic", "tmp");
|
|
315
|
-
} catch (error) {
|
|
316
|
-
console.error(
|
|
317
|
-
`[asyncWithWs atomic setup error]: `.concat(
|
|
318
|
-
error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
319
|
-
)
|
|
320
|
-
);
|
|
321
|
-
if (tmpName) {
|
|
322
|
-
try {
|
|
323
|
-
this.rmTmpFile(tmpName);
|
|
324
|
-
} catch (err) {
|
|
325
|
-
console.error(err);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
} finally {
|
|
329
|
-
if (tmpName) {
|
|
330
|
-
let newPath = null;
|
|
331
|
-
let newBytes = 0;
|
|
332
|
-
const readable = this.toReadable(data);
|
|
333
|
-
const chunks = [];
|
|
334
|
-
for await (const chunk of readable) {
|
|
335
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
336
|
-
}
|
|
337
|
-
const buffer = Buffer.concat(chunks);
|
|
338
|
-
bytes = buffer.length;
|
|
339
|
-
try {
|
|
340
|
-
await this.writeTmpAsync(tmpName, buffer.toString());
|
|
341
|
-
const tmpPath = resolve(this.tmpDir, tmpName);
|
|
342
|
-
const finalPath = resolve(this.cwd, path);
|
|
343
|
-
await fsAsync.rename(tmpPath, finalPath);
|
|
344
|
-
newPath = path;
|
|
345
|
-
newBytes = bytes;
|
|
346
|
-
} catch (err) {
|
|
347
|
-
console.error(`[asyncWithWs atomic rename error]:`, err);
|
|
348
|
-
if (this.existsTmp(tmpName)) {
|
|
349
|
-
try {
|
|
350
|
-
this.rmTmpFile(tmpName);
|
|
351
|
-
} catch (err2) {
|
|
352
|
-
console.error(err2);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
throw err;
|
|
356
|
-
}
|
|
357
|
-
return { path, bytes, newPath, newBytes };
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return { path, bytes: 0 };
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
export {
|
|
365
|
-
FsTmp
|
|
366
|
-
};
|
|
367
|
-
//# sourceMappingURL=chunk-PATMSIQK.js.map
|
package/dist/chunk-PB5A7ZFD.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__name
|
|
3
|
-
} from "./chunk-7QVYU63E.js";
|
|
4
|
-
|
|
5
|
-
// src/ld/index.ts
|
|
6
|
-
import { Extract } from "@d0paminedriven/metadata";
|
|
7
|
-
var LevenshteinDistance = class extends Extract {
|
|
8
|
-
static {
|
|
9
|
-
__name(this, "LevenshteinDistance");
|
|
10
|
-
}
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
createMatrix(rows, cols, initialValue) {
|
|
15
|
-
const matrix = Array.of();
|
|
16
|
-
for (let r = 0; r < rows; r++) {
|
|
17
|
-
const row = new Array(cols).fill(initialValue);
|
|
18
|
-
matrix.push(row);
|
|
19
|
-
}
|
|
20
|
-
return matrix;
|
|
21
|
-
}
|
|
22
|
-
inBounds(matrix, row, col) {
|
|
23
|
-
if (!matrix[row]) return false;
|
|
24
|
-
return row >= 0 && row < matrix.length && col >= 0 && col < matrix[row].length;
|
|
25
|
-
}
|
|
26
|
-
getCell(matrix, row, col) {
|
|
27
|
-
if (!matrix[row]) {
|
|
28
|
-
throw new Error(`getRow: row does not exist`);
|
|
29
|
-
}
|
|
30
|
-
if (!this.inBounds(matrix, row, col) || !matrix[row][col]) return 0;
|
|
31
|
-
return matrix[row][col];
|
|
32
|
-
}
|
|
33
|
-
setCell(matrix, row, col, value) {
|
|
34
|
-
if (!matrix[row]) return false;
|
|
35
|
-
if (!this.inBounds(matrix, row, col)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
matrix[row][col] = value;
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Computes the Levenshtein distance between two strings, i.e.,
|
|
43
|
-
* the minimum number of single-character edits (insertions,
|
|
44
|
-
* deletions, or substitutions) needed to transform `a` into `b`.
|
|
45
|
-
*/
|
|
46
|
-
calculate(a, b) {
|
|
47
|
-
const strA = a ?? "";
|
|
48
|
-
const strB = b ?? "";
|
|
49
|
-
const dp = this.createMatrix(strA.length + 1, strB.length + 1, 0);
|
|
50
|
-
for (let i = 0; i < dp.length; i++) {
|
|
51
|
-
for (let j = 0; j < (dp[i] ?? []).length; j++) {
|
|
52
|
-
if (i === 0) {
|
|
53
|
-
this.setCell(dp, i, j, j);
|
|
54
|
-
} else if (j === 0) {
|
|
55
|
-
this.setCell(dp, i, j, i);
|
|
56
|
-
} else {
|
|
57
|
-
const charA = strA[i - 1];
|
|
58
|
-
const charB = strB[j - 1];
|
|
59
|
-
if (charA === charB) {
|
|
60
|
-
const diag = this.getCell(dp, i - 1, j - 1);
|
|
61
|
-
this.setCell(dp, i, j, diag);
|
|
62
|
-
} else {
|
|
63
|
-
const top = this.getCell(dp, i - 1, j);
|
|
64
|
-
const left = this.getCell(dp, i, j - 1);
|
|
65
|
-
const diag = this.getCell(dp, i - 1, j - 1);
|
|
66
|
-
const val = 1 + Math.min(top, left, diag);
|
|
67
|
-
this.setCell(dp, i, j, val);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return this.getCell(dp, strA.length, strB.length);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export {
|
|
77
|
-
LevenshteinDistance
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=chunk-PB5A7ZFD.js.map
|
package/dist/chunk-VDKUXJE7.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ImageService
|
|
3
|
-
} from "./chunk-Y5QWE4EG.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-7QVYU63E.js";
|
|
7
|
-
|
|
8
|
-
// src/fs-base/index.ts
|
|
9
|
-
import fsSync from "fs";
|
|
10
|
-
import { Readable } from "stream";
|
|
11
|
-
import { devNull, EOL, homedir, hostname, platform, tmpdir } from "os";
|
|
12
|
-
import { join, relative, resolve } from "path";
|
|
13
|
-
import { ReadableStream as WebReadableStream } from "stream/web";
|
|
14
|
-
import * as dotenv from "dotenv";
|
|
15
|
-
import expand from "dotenv-expand";
|
|
16
|
-
var FsBase = class extends ImageService {
|
|
17
|
-
constructor(cwd) {
|
|
18
|
-
super(cwd ?? process.cwd());
|
|
19
|
-
this.cwd = cwd;
|
|
20
|
-
}
|
|
21
|
-
static {
|
|
22
|
-
__name(this, "FsBase");
|
|
23
|
-
}
|
|
24
|
-
get tmpDir() {
|
|
25
|
-
return tmpdir();
|
|
26
|
-
}
|
|
27
|
-
get homeDir() {
|
|
28
|
-
return homedir();
|
|
29
|
-
}
|
|
30
|
-
get platform() {
|
|
31
|
-
return platform();
|
|
32
|
-
}
|
|
33
|
-
get hostname() {
|
|
34
|
-
return hostname();
|
|
35
|
-
}
|
|
36
|
-
get devNull() {
|
|
37
|
-
return devNull;
|
|
38
|
-
}
|
|
39
|
-
get eol() {
|
|
40
|
-
return EOL;
|
|
41
|
-
}
|
|
42
|
-
get env() {
|
|
43
|
-
return dotenv.config({ processEnv: {}, quiet: true });
|
|
44
|
-
}
|
|
45
|
-
parseDotEnv() {
|
|
46
|
-
const env = expand.expand(this.env);
|
|
47
|
-
if (typeof env !== "undefined") {
|
|
48
|
-
if (env.error) {
|
|
49
|
-
throw new Error(env.error.message);
|
|
50
|
-
} else {
|
|
51
|
-
return env.parsed;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error("env returned undefined");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
relative(from, to) {
|
|
58
|
-
return relative(from, to);
|
|
59
|
-
}
|
|
60
|
-
isHomeTargeted(path) {
|
|
61
|
-
if (/^(~\/\.?)$/g.test(path)) {
|
|
62
|
-
return true;
|
|
63
|
-
} else if (path.includes(this.homeDir)) {
|
|
64
|
-
return true;
|
|
65
|
-
} else {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
isRootPathTargeted(path) {
|
|
70
|
-
if (/^(?:\.\/|\.|\/|root|\.\.\/|cwd|\.\/\.)$/g.test(path)) {
|
|
71
|
-
return true;
|
|
72
|
-
} else {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
pathHandler(path) {
|
|
77
|
-
return /\//g.test(path) === true ? path.split(/([/])/gim).reverse().slice(2).reverse().join("") : path;
|
|
78
|
-
}
|
|
79
|
-
isUint8Array(v) {
|
|
80
|
-
return v instanceof Uint8Array;
|
|
81
|
-
}
|
|
82
|
-
isBuffer(v) {
|
|
83
|
-
return Buffer.isBuffer(v);
|
|
84
|
-
}
|
|
85
|
-
isWebReadableStream(v) {
|
|
86
|
-
return v instanceof WebReadableStream;
|
|
87
|
-
}
|
|
88
|
-
isAsyncIterable(v) {
|
|
89
|
-
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
90
|
-
}
|
|
91
|
-
formatHelper(f) {
|
|
92
|
-
if (/([A-Za-z]+-[A-Za-z]+)/g.test(f) === true) {
|
|
93
|
-
const formatting = f.split(/-/g).map((v) => v.substring(0, 1).toUpperCase().concat(v.substring(1))).join(" ");
|
|
94
|
-
return formatting;
|
|
95
|
-
} else return f.substring(0, 1).toUpperCase().concat(f.substring(1));
|
|
96
|
-
}
|
|
97
|
-
cleanDataUrl(props) {
|
|
98
|
-
return props.replace(
|
|
99
|
-
/^data:(?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*;base64,/i,
|
|
100
|
-
""
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
toReadable(data) {
|
|
104
|
-
if (typeof data === "string") return Readable.from([Buffer.from(data)]);
|
|
105
|
-
if (this.isBuffer(data) || this.isUint8Array(data))
|
|
106
|
-
return Readable.from([data]);
|
|
107
|
-
if (this.isWebReadableStream(data)) return Readable.fromWeb(data);
|
|
108
|
-
if (this.isAsyncIterable(data)) return Readable.from(data);
|
|
109
|
-
if (data instanceof Readable) return data;
|
|
110
|
-
throw new TypeError("Unsupported data type for toReadable()");
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
*
|
|
114
|
-
* @param target path to the file or directory to check for existence
|
|
115
|
-
* @returns true if the file or directory exists, false otherwise
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* const fs = new Fs(process.cwd());
|
|
119
|
-
* const exists = fs.exists("my-file.txt");
|
|
120
|
-
* console.log(exists); // true if the file exists, false otherwise
|
|
121
|
-
* ```
|
|
122
|
-
* @description
|
|
123
|
-
* This method checks if a file or directory exists at the specified path input
|
|
124
|
-
*
|
|
125
|
-
* Additional Note:
|
|
126
|
-
*
|
|
127
|
-
* say you have a directory that begins with a dot, such as `.turbo`;
|
|
128
|
-
*
|
|
129
|
-
* in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
|
|
130
|
-
*
|
|
131
|
-
*/
|
|
132
|
-
exists(target) {
|
|
133
|
-
if (!/\//gm.test(target)) {
|
|
134
|
-
if (/\./g.test(target)) {
|
|
135
|
-
return fsSync.existsSync(resolve(join(this.cwd, target)));
|
|
136
|
-
} else {
|
|
137
|
-
const statsSync = fsSync.statSync(resolve(join(this.cwd, target)), {
|
|
138
|
-
throwIfNoEntry: false
|
|
139
|
-
});
|
|
140
|
-
const isDir = statsSync?.isDirectory();
|
|
141
|
-
if (isDir) {
|
|
142
|
-
return isDir;
|
|
143
|
-
} else return false;
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
if (/\./g.test(target)) {
|
|
147
|
-
return fsSync.existsSync(relative(this.cwd ?? process.cwd(), target));
|
|
148
|
-
} else {
|
|
149
|
-
const statsSync = fsSync.statSync(relative(this.cwd, target), {
|
|
150
|
-
throwIfNoEntry: false
|
|
151
|
-
});
|
|
152
|
-
const isDir = statsSync?.isDirectory();
|
|
153
|
-
if (isDir) {
|
|
154
|
-
return isDir;
|
|
155
|
-
} else return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param ms milliseconds to wait
|
|
162
|
-
* @returns a promise that resolves after the specified number of milliseconds
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* const fs = new Fs(process.cwd());
|
|
166
|
-
* await fs.wait(1000); // waits for 1 second
|
|
167
|
-
* console.log("Done waiting!");
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
* Alternatively, you can use it like this:
|
|
171
|
-
* ```ts
|
|
172
|
-
* const fs = new Fs(process.cwd());
|
|
173
|
-
* fs.wait(1000).then(() => { // waits for 1 second
|
|
174
|
-
* console.log("Done waiting!");
|
|
175
|
-
* // do something after waiting
|
|
176
|
-
* });
|
|
177
|
-
* ```
|
|
178
|
-
*
|
|
179
|
-
* @description
|
|
180
|
-
* This method is useful for delaying execution in asynchronous code, such as when you need to wait for a file operation to complete or when you want to introduce a delay in a loop.
|
|
181
|
-
*/
|
|
182
|
-
wait(ms) {
|
|
183
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
|
|
187
|
-
* @param arr An array or readonly array of strings and/or Buffers
|
|
188
|
-
* @returns An array of strings with Buffers converted to UTF-8 strings.
|
|
189
|
-
*/
|
|
190
|
-
handleBuffStrArrUnion(arr) {
|
|
191
|
-
return arr.map(
|
|
192
|
-
(v) => Buffer.isBuffer(v) ? Buffer.from(v).toString("utf-8") : v
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
* @param path path to the directory relative to the cwd
|
|
198
|
-
* @param options options for reading the directory, defaults to recursive
|
|
199
|
-
*
|
|
200
|
-
* The following two examples are equivalent:
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* ```ts
|
|
204
|
-
* const fs = new Fs(process.cwd());
|
|
205
|
-
* const files = fs.readDir("./my-directory", { recursive: true });
|
|
206
|
-
* console.log(files);
|
|
207
|
-
* ```
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const fs = new Fs(process.cwd());
|
|
211
|
-
* const files = fs.readDir("my-directory", { recursive: true });
|
|
212
|
-
* console.log(files);
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
* @returns an array of strings representing the contents of the directory
|
|
216
|
-
*/
|
|
217
|
-
readDir(path, options = {
|
|
218
|
-
recursive: true,
|
|
219
|
-
withFileTypes: false,
|
|
220
|
-
encoding: "utf-8"
|
|
221
|
-
}) {
|
|
222
|
-
if (this.isRootPathTargeted(path)) {
|
|
223
|
-
return this.handleBuffStrArrUnion(
|
|
224
|
-
fsSync.readdirSync(resolve(join(this.cwd, "./")), { ...options })
|
|
225
|
-
);
|
|
226
|
-
} else {
|
|
227
|
-
return this.handleBuffStrArrUnion(
|
|
228
|
-
fsSync.readdirSync(
|
|
229
|
-
relative(this.cwd ??= process.cwd(), path),
|
|
230
|
-
options
|
|
231
|
-
)
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
export {
|
|
238
|
-
FsBase
|
|
239
|
-
};
|
|
240
|
-
//# sourceMappingURL=chunk-VDKUXJE7.js.map
|