webforai 1.6.0 → 1.6.1

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/cli/utils.js DELETED
@@ -1,52 +0,0 @@
1
- // src/cli/utils.ts
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- var isUrl = (maybeUrl) => {
5
- try {
6
- new URL(maybeUrl);
7
- return true;
8
- } catch {
9
- return false;
10
- }
11
- };
12
- function changeFileExtension(filePath, newExtension) {
13
- const parsed = path.parse(filePath);
14
- const ext = newExtension.startsWith(".") ? newExtension : `.${newExtension}`;
15
- return path.format({ ...parsed, ext });
16
- }
17
- function urlToFilename(url) {
18
- try {
19
- const urlObj = new URL(url);
20
- const hostname = urlObj.hostname.startsWith("www.") ? urlObj.hostname.slice(4) : urlObj.hostname;
21
- const domainParts = hostname.split(".").slice(-2).join("-");
22
- const pathParts = urlObj.pathname.split("/").filter(Boolean);
23
- const relevantPathParts = pathParts.slice(-2).map(decodeURIComponent).join("-");
24
- let filename = [domainParts, relevantPathParts].filter(Boolean).join("-");
25
- filename = filename.toLowerCase().replace(/[<>:"/\\|?*\x00-\x1F]/g, "").replace(/[\s.]+/g, "-").replace(/^-+|-+$/g, "");
26
- return filename || "output";
27
- } catch {
28
- return "output";
29
- }
30
- }
31
- var sourcePathToOutputPath = (sourcePath) => isUrl(sourcePath) ? `${urlToFilename(sourcePath)}.md` : changeFileExtension(sourcePath, "md");
32
- function getNextAvailableFilePath(filePath) {
33
- const parsed = path.parse(filePath);
34
- const dir = parsed.dir;
35
- const ext = parsed.ext;
36
- const baseName = parsed.name.replace(/_\d+$/, "");
37
- const match = parsed.name.match(/_(\d+)$/);
38
- let counter = match ? Number(match[1]) + 1 : 1;
39
- let newPath = path.join(dir, `${baseName}_${counter}${ext}`);
40
- while (fs.existsSync(newPath)) {
41
- counter++;
42
- newPath = path.join(dir, `${baseName}_${counter}${ext}`);
43
- }
44
- return newPath;
45
- }
46
- export {
47
- changeFileExtension,
48
- getNextAvailableFilePath,
49
- isUrl,
50
- sourcePathToOutputPath,
51
- urlToFilename
52
- };