scrapfly-sdk 0.10.2 → 0.10.4

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.
Files changed (100) hide show
  1. package/esm/batch.d.ts.map +1 -1
  2. package/esm/batch.js +4 -0
  3. package/esm/client.d.ts.map +1 -1
  4. package/esm/client.js +17 -8
  5. package/package.json +1 -1
  6. package/script/batch.d.ts.map +1 -1
  7. package/script/batch.js +4 -0
  8. package/script/client.d.ts.map +1 -1
  9. package/script/client.js +17 -8
  10. package/src/_dnt.shims.ts +64 -0
  11. package/src/batch.ts +272 -0
  12. package/src/browserconfig.ts +118 -0
  13. package/src/client.ts +1609 -0
  14. package/src/crawl.ts +251 -0
  15. package/src/crawlerconfig.ts +363 -0
  16. package/src/crawlerresult.ts +471 -0
  17. package/src/deps/jsr.io/@std/path/1.0.1/_common/assert_path.ts +10 -0
  18. package/src/deps/jsr.io/@std/path/1.0.1/_common/basename.ts +53 -0
  19. package/src/deps/jsr.io/@std/path/1.0.1/_common/common.ts +26 -0
  20. package/src/deps/jsr.io/@std/path/1.0.1/_common/constants.ts +49 -0
  21. package/src/deps/jsr.io/@std/path/1.0.1/_common/dirname.ts +9 -0
  22. package/src/deps/jsr.io/@std/path/1.0.1/_common/format.ts +25 -0
  23. package/src/deps/jsr.io/@std/path/1.0.1/_common/from_file_url.ts +10 -0
  24. package/src/deps/jsr.io/@std/path/1.0.1/_common/glob_to_reg_exp.ts +290 -0
  25. package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize.ts +9 -0
  26. package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize_string.ts +74 -0
  27. package/src/deps/jsr.io/@std/path/1.0.1/_common/relative.ts +10 -0
  28. package/src/deps/jsr.io/@std/path/1.0.1/_common/strip_trailing_separators.ts +25 -0
  29. package/src/deps/jsr.io/@std/path/1.0.1/_common/to_file_url.ts +17 -0
  30. package/src/deps/jsr.io/@std/path/1.0.1/_os.ts +31 -0
  31. package/src/deps/jsr.io/@std/path/1.0.1/basename.ts +35 -0
  32. package/src/deps/jsr.io/@std/path/1.0.1/common.ts +35 -0
  33. package/src/deps/jsr.io/@std/path/1.0.1/constants.ts +18 -0
  34. package/src/deps/jsr.io/@std/path/1.0.1/dirname.ts +28 -0
  35. package/src/deps/jsr.io/@std/path/1.0.1/extname.ts +27 -0
  36. package/src/deps/jsr.io/@std/path/1.0.1/format.ts +30 -0
  37. package/src/deps/jsr.io/@std/path/1.0.1/from_file_url.ts +30 -0
  38. package/src/deps/jsr.io/@std/path/1.0.1/glob_to_regexp.ts +94 -0
  39. package/src/deps/jsr.io/@std/path/1.0.1/is_absolute.ts +30 -0
  40. package/src/deps/jsr.io/@std/path/1.0.1/is_glob.ts +49 -0
  41. package/src/deps/jsr.io/@std/path/1.0.1/join.ts +28 -0
  42. package/src/deps/jsr.io/@std/path/1.0.1/join_globs.ts +42 -0
  43. package/src/deps/jsr.io/@std/path/1.0.1/mod.ts +55 -0
  44. package/src/deps/jsr.io/@std/path/1.0.1/normalize.ts +31 -0
  45. package/src/deps/jsr.io/@std/path/1.0.1/normalize_glob.ts +45 -0
  46. package/src/deps/jsr.io/@std/path/1.0.1/parse.ts +44 -0
  47. package/src/deps/jsr.io/@std/path/1.0.1/posix/_util.ts +10 -0
  48. package/src/deps/jsr.io/@std/path/1.0.1/posix/basename.ts +39 -0
  49. package/src/deps/jsr.io/@std/path/1.0.1/posix/constants.ts +15 -0
  50. package/src/deps/jsr.io/@std/path/1.0.1/posix/dirname.ts +55 -0
  51. package/src/deps/jsr.io/@std/path/1.0.1/posix/extname.ts +73 -0
  52. package/src/deps/jsr.io/@std/path/1.0.1/posix/format.ts +31 -0
  53. package/src/deps/jsr.io/@std/path/1.0.1/posix/from_file_url.ts +25 -0
  54. package/src/deps/jsr.io/@std/path/1.0.1/posix/glob_to_regexp.ts +94 -0
  55. package/src/deps/jsr.io/@std/path/1.0.1/posix/is_absolute.ts +25 -0
  56. package/src/deps/jsr.io/@std/path/1.0.1/posix/join.ts +27 -0
  57. package/src/deps/jsr.io/@std/path/1.0.1/posix/join_globs.ts +44 -0
  58. package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize.ts +41 -0
  59. package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize_glob.ts +42 -0
  60. package/src/deps/jsr.io/@std/path/1.0.1/posix/parse.ts +121 -0
  61. package/src/deps/jsr.io/@std/path/1.0.1/posix/relative.ts +103 -0
  62. package/src/deps/jsr.io/@std/path/1.0.1/posix/resolve.ts +69 -0
  63. package/src/deps/jsr.io/@std/path/1.0.1/posix/to_file_url.ts +32 -0
  64. package/src/deps/jsr.io/@std/path/1.0.1/posix/to_namespaced_path.ts +21 -0
  65. package/src/deps/jsr.io/@std/path/1.0.1/relative.ts +32 -0
  66. package/src/deps/jsr.io/@std/path/1.0.1/resolve.ts +32 -0
  67. package/src/deps/jsr.io/@std/path/1.0.1/to_file_url.ts +30 -0
  68. package/src/deps/jsr.io/@std/path/1.0.1/to_namespaced_path.ts +31 -0
  69. package/src/deps/jsr.io/@std/path/1.0.1/types.ts +40 -0
  70. package/src/deps/jsr.io/@std/path/1.0.1/windows/_util.ts +28 -0
  71. package/src/deps/jsr.io/@std/path/1.0.1/windows/basename.ts +48 -0
  72. package/src/deps/jsr.io/@std/path/1.0.1/windows/constants.ts +15 -0
  73. package/src/deps/jsr.io/@std/path/1.0.1/windows/dirname.ts +114 -0
  74. package/src/deps/jsr.io/@std/path/1.0.1/windows/extname.ts +86 -0
  75. package/src/deps/jsr.io/@std/path/1.0.1/windows/format.ts +31 -0
  76. package/src/deps/jsr.io/@std/path/1.0.1/windows/from_file_url.ts +34 -0
  77. package/src/deps/jsr.io/@std/path/1.0.1/windows/glob_to_regexp.ts +92 -0
  78. package/src/deps/jsr.io/@std/path/1.0.1/windows/is_absolute.ts +40 -0
  79. package/src/deps/jsr.io/@std/path/1.0.1/windows/join.ts +72 -0
  80. package/src/deps/jsr.io/@std/path/1.0.1/windows/join_globs.ts +45 -0
  81. package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize.ts +132 -0
  82. package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize_glob.ts +42 -0
  83. package/src/deps/jsr.io/@std/path/1.0.1/windows/parse.ts +184 -0
  84. package/src/deps/jsr.io/@std/path/1.0.1/windows/relative.ts +128 -0
  85. package/src/deps/jsr.io/@std/path/1.0.1/windows/resolve.ts +174 -0
  86. package/src/deps/jsr.io/@std/path/1.0.1/windows/to_file_url.ts +38 -0
  87. package/src/deps/jsr.io/@std/path/1.0.1/windows/to_namespaced_path.ts +60 -0
  88. package/src/deps.ts +4 -0
  89. package/src/errors.ts +55 -0
  90. package/src/extractionconfig.ts +175 -0
  91. package/src/logger.ts +51 -0
  92. package/src/main.ts +61 -0
  93. package/src/monitoringconfig.ts +50 -0
  94. package/src/polyfill.ts +37 -0
  95. package/src/result.ts +338 -0
  96. package/src/scrapeconfig.ts +448 -0
  97. package/src/screenshotconfig.ts +204 -0
  98. package/src/types.ts +2 -0
  99. package/src/utils.ts +86 -0
  100. package/src/webhookserver.ts +66 -0
@@ -0,0 +1,32 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { isWindows } from "./_os.js";
5
+ import { resolve as posixResolve } from "./posix/resolve.js";
6
+ import { resolve as windowsResolve } from "./windows/resolve.js";
7
+
8
+ /**
9
+ * Resolves path segments into a path.
10
+ *
11
+ * @example Usage
12
+ * ```ts
13
+ * import { resolve } from "@std/path/resolve";
14
+ * import { assertEquals } from "@std/assert";
15
+ *
16
+ * if (Deno.build.os === "windows") {
17
+ * assertEquals(resolve("C:\\foo", "bar", "baz"), "C:\\foo\\bar\\baz");
18
+ * assertEquals(resolve("C:\\foo", "C:\\bar", "baz"), "C:\\bar\\baz");
19
+ * } else {
20
+ * assertEquals(resolve("/foo", "bar", "baz"), "/foo/bar/baz");
21
+ * assertEquals(resolve("/foo", "/bar", "baz"), "/bar/baz");
22
+ * }
23
+ * ```
24
+ *
25
+ * @param pathSegments Path segments to process to path.
26
+ * @returns The resolved path.
27
+ */
28
+ export function resolve(...pathSegments: string[]): string {
29
+ return isWindows
30
+ ? windowsResolve(...pathSegments)
31
+ : posixResolve(...pathSegments);
32
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { isWindows } from "./_os.js";
5
+ import { toFileUrl as posixToFileUrl } from "./posix/to_file_url.js";
6
+ import { toFileUrl as windowsToFileUrl } from "./windows/to_file_url.js";
7
+
8
+ /**
9
+ * Converts a path string to a file URL.
10
+ *
11
+ * @example Usage
12
+ * ```ts
13
+ * import { toFileUrl } from "@std/path/to-file-url";
14
+ * import { assertEquals } from "@std/assert";
15
+ *
16
+ * if (Deno.build.os === "windows") {
17
+ * assertEquals(toFileUrl("\\home\\foo"), new URL("file:///home/foo"));
18
+ * assertEquals(toFileUrl("C:\\Users\\foo"), new URL("file:///C:/Users/foo"));
19
+ * assertEquals(toFileUrl("\\\\127.0.0.1\\home\\foo"), new URL("file://127.0.0.1/home/foo"));
20
+ * } else {
21
+ * assertEquals(toFileUrl("/home/foo"), new URL("file:///home/foo"));
22
+ * }
23
+ * ```
24
+ *
25
+ * @param path Path to convert to file URL.
26
+ * @returns The file URL equivalent to the path.
27
+ */
28
+ export function toFileUrl(path: string): URL {
29
+ return isWindows ? windowsToFileUrl(path) : posixToFileUrl(path);
30
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { isWindows } from "./_os.js";
5
+ import { toNamespacedPath as posixToNamespacedPath } from "./posix/to_namespaced_path.js";
6
+ import { toNamespacedPath as windowsToNamespacedPath } from "./windows/to_namespaced_path.js";
7
+
8
+ /**
9
+ * Resolves path to a namespace path. This is a no-op on
10
+ * non-windows systems.
11
+ *
12
+ * @example Usage
13
+ * ```ts
14
+ * import { toNamespacedPath } from "@std/path/to-namespaced-path";
15
+ * import { assertEquals } from "@std/assert";
16
+ *
17
+ * if (Deno.build.os === "windows") {
18
+ * assertEquals(toNamespacedPath("C:\\foo\\bar"), "\\\\?\\C:\\foo\\bar");
19
+ * } else {
20
+ * assertEquals(toNamespacedPath("/foo/bar"), "/foo/bar");
21
+ * }
22
+ * ```
23
+ *
24
+ * @param path Path to resolve to namespace.
25
+ * @returns The resolved namespace path.
26
+ */
27
+ export function toNamespacedPath(path: string): string {
28
+ return isWindows
29
+ ? windowsToNamespacedPath(path)
30
+ : posixToNamespacedPath(path);
31
+ }
@@ -0,0 +1,40 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ /**
5
+ * A parsed path object generated by path.parse() or consumed by path.format().
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { parse } from "@std/path";
10
+ *
11
+ * const parsedPathObj = parse("c:\\path\\dir\\index.html");
12
+ * parsedPathObj.root; // "c:\\"
13
+ * parsedPathObj.dir; // "c:\\path\\dir"
14
+ * parsedPathObj.base; // "index.html"
15
+ * parsedPathObj.ext; // ".html"
16
+ * parsedPathObj.name; // "index"
17
+ * ```
18
+ */
19
+ export interface ParsedPath {
20
+ /**
21
+ * The root of the path such as '/' or 'c:\'
22
+ */
23
+ root: string;
24
+ /**
25
+ * The full directory path of the parent such as '/home/user/dir' or 'c:\path\dir'
26
+ */
27
+ dir: string;
28
+ /**
29
+ * The file name including extension (if any) such as 'index.html'
30
+ */
31
+ base: string;
32
+ /**
33
+ * The file extension (if any) such as '.html'
34
+ */
35
+ ext: string;
36
+ /**
37
+ * The file name without extension (if any) such as 'index'
38
+ */
39
+ name: string;
40
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright the Browserify authors. MIT License.
3
+ // Ported from https://github.com/browserify/path-browserify/
4
+ // This module is browser compatible.
5
+
6
+ import {
7
+ CHAR_BACKWARD_SLASH,
8
+ CHAR_FORWARD_SLASH,
9
+ CHAR_LOWERCASE_A,
10
+ CHAR_LOWERCASE_Z,
11
+ CHAR_UPPERCASE_A,
12
+ CHAR_UPPERCASE_Z,
13
+ } from "../_common/constants.js";
14
+
15
+ export function isPosixPathSeparator(code: number): boolean {
16
+ return code === CHAR_FORWARD_SLASH;
17
+ }
18
+
19
+ export function isPathSeparator(code: number): boolean {
20
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
21
+ }
22
+
23
+ export function isWindowsDeviceRoot(code: number): boolean {
24
+ return (
25
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) ||
26
+ (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z)
27
+ );
28
+ }
@@ -0,0 +1,48 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import {
5
+ assertArgs,
6
+ lastPathSegment,
7
+ stripSuffix,
8
+ } from "../_common/basename.js";
9
+ import { CHAR_COLON } from "../_common/constants.js";
10
+ import { stripTrailingSeparators } from "../_common/strip_trailing_separators.js";
11
+ import { isPathSeparator, isWindowsDeviceRoot } from "./_util.js";
12
+
13
+ /**
14
+ * Return the last portion of a `path`.
15
+ * Trailing directory separators are ignored, and optional suffix is removed.
16
+ *
17
+ * @example Usage
18
+ * ```ts
19
+ * import { basename } from "@std/path/windows/basename";
20
+ * import { assertEquals } from "@std/assert";
21
+ *
22
+ * assertEquals(basename("C:\\user\\Documents\\"), "Documents");
23
+ * assertEquals(basename("C:\\user\\Documents\\image.png"), "image.png");
24
+ * assertEquals(basename("C:\\user\\Documents\\image.png", ".png"), "image");
25
+ * ```
26
+ *
27
+ * @param path The path to extract the name from.
28
+ * @param suffix The suffix to remove from extracted name.
29
+ * @returns The extracted name.
30
+ */
31
+ export function basename(path: string, suffix = ""): string {
32
+ assertArgs(path, suffix);
33
+
34
+ // Check for a drive letter prefix so as not to mistake the following
35
+ // path separator as an extra separator at the end of the path that can be
36
+ // disregarded
37
+ let start = 0;
38
+ if (path.length >= 2) {
39
+ const drive = path.charCodeAt(0);
40
+ if (isWindowsDeviceRoot(drive)) {
41
+ if (path.charCodeAt(1) === CHAR_COLON) start = 2;
42
+ }
43
+ }
44
+
45
+ const lastSegment = lastPathSegment(path, isPathSeparator, start);
46
+ const strippedSegment = stripTrailingSeparators(lastSegment, isPathSeparator);
47
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
48
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ /**
5
+ * The character used to separate entries in the PATH environment variable.
6
+ */
7
+ export const DELIMITER = ";" as const;
8
+ /**
9
+ * The character used to separate components of a file path.
10
+ */
11
+ export const SEPARATOR = "\\" as const;
12
+ /**
13
+ * A regular expression that matches one or more path separators.
14
+ */
15
+ export const SEPARATOR_PATTERN = /[\\/]+/;
@@ -0,0 +1,114 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { assertArg } from "../_common/dirname.js";
5
+ import { CHAR_COLON } from "../_common/constants.js";
6
+ import { stripTrailingSeparators } from "../_common/strip_trailing_separators.js";
7
+ import {
8
+ isPathSeparator,
9
+ isPosixPathSeparator,
10
+ isWindowsDeviceRoot,
11
+ } from "./_util.js";
12
+
13
+ /**
14
+ * Return the directory path of a `path`.
15
+ *
16
+ * @example Usage
17
+ * ```ts
18
+ * import { dirname } from "@std/path/windows/dirname";
19
+ * import { assertEquals } from "@std/assert";
20
+ *
21
+ * const dir = dirname("C:\\foo\\bar\\baz.ext");
22
+ * assertEquals(dir, "C:\\foo\\bar");
23
+ * ```
24
+ *
25
+ * @param path The path to get the directory from.
26
+ * @returns The directory path.
27
+ */
28
+ export function dirname(path: string): string {
29
+ assertArg(path);
30
+
31
+ const len = path.length;
32
+ let rootEnd = -1;
33
+ let end = -1;
34
+ let matchedSlash = true;
35
+ let offset = 0;
36
+ const code = path.charCodeAt(0);
37
+
38
+ // Try to match a root
39
+ if (len > 1) {
40
+ if (isPathSeparator(code)) {
41
+ // Possible UNC root
42
+
43
+ rootEnd = offset = 1;
44
+
45
+ if (isPathSeparator(path.charCodeAt(1))) {
46
+ // Matched double path separator at beginning
47
+ let j = 2;
48
+ let last = j;
49
+ // Match 1 or more non-path separators
50
+ for (; j < len; ++j) {
51
+ if (isPathSeparator(path.charCodeAt(j))) break;
52
+ }
53
+ if (j < len && j !== last) {
54
+ // Matched!
55
+ last = j;
56
+ // Match 1 or more path separators
57
+ for (; j < len; ++j) {
58
+ if (!isPathSeparator(path.charCodeAt(j))) break;
59
+ }
60
+ if (j < len && j !== last) {
61
+ // Matched!
62
+ last = j;
63
+ // Match 1 or more non-path separators
64
+ for (; j < len; ++j) {
65
+ if (isPathSeparator(path.charCodeAt(j))) break;
66
+ }
67
+ if (j === len) {
68
+ // We matched a UNC root only
69
+ return path;
70
+ }
71
+ if (j !== last) {
72
+ // We matched a UNC root with leftovers
73
+
74
+ // Offset by 1 to include the separator after the UNC root to
75
+ // treat it as a "normal root" on top of a (UNC) root
76
+ rootEnd = offset = j + 1;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ } else if (isWindowsDeviceRoot(code)) {
82
+ // Possible device root
83
+
84
+ if (path.charCodeAt(1) === CHAR_COLON) {
85
+ rootEnd = offset = 2;
86
+ if (len > 2) {
87
+ if (isPathSeparator(path.charCodeAt(2))) rootEnd = offset = 3;
88
+ }
89
+ }
90
+ }
91
+ } else if (isPathSeparator(code)) {
92
+ // `path` contains just a path separator, exit early to avoid
93
+ // unnecessary work
94
+ return path;
95
+ }
96
+
97
+ for (let i = len - 1; i >= offset; --i) {
98
+ if (isPathSeparator(path.charCodeAt(i))) {
99
+ if (!matchedSlash) {
100
+ end = i;
101
+ break;
102
+ }
103
+ } else {
104
+ // We saw the first non-path separator
105
+ matchedSlash = false;
106
+ }
107
+ }
108
+
109
+ if (end === -1) {
110
+ if (rootEnd === -1) return ".";
111
+ else end = rootEnd;
112
+ }
113
+ return stripTrailingSeparators(path.slice(0, end), isPosixPathSeparator);
114
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { CHAR_COLON, CHAR_DOT } from "../_common/constants.js";
5
+ import { assertPath } from "../_common/assert_path.js";
6
+ import { isPathSeparator, isWindowsDeviceRoot } from "./_util.js";
7
+
8
+ /**
9
+ * Return the extension of the `path` with leading period.
10
+ *
11
+ * @example Usage
12
+ * ```ts
13
+ * import { extname } from "@std/path/windows/extname";
14
+ * import { assertEquals } from "@std/assert";
15
+ *
16
+ * const ext = extname("file.ts");
17
+ * assertEquals(ext, ".ts");
18
+ * ```
19
+ *
20
+ * @param path The path to get the extension from.
21
+ * @returns The extension of the `path`.
22
+ */
23
+ export function extname(path: string): string {
24
+ assertPath(path);
25
+
26
+ let start = 0;
27
+ let startDot = -1;
28
+ let startPart = 0;
29
+ let end = -1;
30
+ let matchedSlash = true;
31
+ // Track the state of characters (if any) we see before our first dot and
32
+ // after any path separator we find
33
+ let preDotState = 0;
34
+
35
+ // Check for a drive letter prefix so as not to mistake the following
36
+ // path separator as an extra separator at the end of the path that can be
37
+ // disregarded
38
+
39
+ if (
40
+ path.length >= 2 &&
41
+ path.charCodeAt(1) === CHAR_COLON &&
42
+ isWindowsDeviceRoot(path.charCodeAt(0))
43
+ ) {
44
+ start = startPart = 2;
45
+ }
46
+
47
+ for (let i = path.length - 1; i >= start; --i) {
48
+ const code = path.charCodeAt(i);
49
+ if (isPathSeparator(code)) {
50
+ // If we reached a path separator that was not part of a set of path
51
+ // separators at the end of the string, stop now
52
+ if (!matchedSlash) {
53
+ startPart = i + 1;
54
+ break;
55
+ }
56
+ continue;
57
+ }
58
+ if (end === -1) {
59
+ // We saw the first non-path separator, mark this as the end of our
60
+ // extension
61
+ matchedSlash = false;
62
+ end = i + 1;
63
+ }
64
+ if (code === CHAR_DOT) {
65
+ // If this is our first dot, mark it as the start of our extension
66
+ if (startDot === -1) startDot = i;
67
+ else if (preDotState !== 1) preDotState = 1;
68
+ } else if (startDot !== -1) {
69
+ // We saw a non-dot and non-path separator before our dot, so we should
70
+ // have a good chance at having a non-empty extension
71
+ preDotState = -1;
72
+ }
73
+ }
74
+
75
+ if (
76
+ startDot === -1 ||
77
+ end === -1 ||
78
+ // We saw a non-dot character immediately before the dot
79
+ preDotState === 0 ||
80
+ // The (right-most) trimmed path component is exactly '..'
81
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
82
+ ) {
83
+ return "";
84
+ }
85
+ return path.slice(startDot, end);
86
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { _format, assertArg } from "../_common/format.js";
5
+ import type { ParsedPath } from "../types.js";
6
+
7
+ /**
8
+ * Generate a path from `ParsedPath` object.
9
+ *
10
+ * @example Usage
11
+ * ```ts
12
+ * import { format } from "@std/path/windows/format";
13
+ * import { assertEquals } from "@std/assert";
14
+ *
15
+ * const path = format({
16
+ * root: "C:\\",
17
+ * dir: "C:\\path\\dir",
18
+ * base: "file.txt",
19
+ * ext: ".txt",
20
+ * name: "file"
21
+ * });
22
+ * assertEquals(path, "C:\\path\\dir\\file.txt");
23
+ * ```
24
+ *
25
+ * @param pathObject The path object to format.
26
+ * @returns The formatted path.
27
+ */
28
+ export function format(pathObject: Partial<ParsedPath>): string {
29
+ assertArg(pathObject);
30
+ return _format("\\", pathObject);
31
+ }
@@ -0,0 +1,34 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { assertArg } from "../_common/from_file_url.js";
5
+
6
+ /**
7
+ * Converts a file URL to a path string.
8
+ *
9
+ * @example Usage
10
+ * ```ts
11
+ * import { fromFileUrl } from "@std/path/windows/from-file-url";
12
+ * import { assertEquals } from "@std/assert";
13
+ *
14
+ * assertEquals(fromFileUrl("file:///home/foo"), "\\home\\foo");
15
+ * assertEquals(fromFileUrl("file:///C:/Users/foo"), "C:\\Users\\foo");
16
+ * assertEquals(fromFileUrl("file://localhost/home/foo"), "\\home\\foo");
17
+ * ```
18
+ *
19
+ * @param url The file URL to convert.
20
+ * @returns The path string.
21
+ */
22
+ export function fromFileUrl(url: URL | string): string {
23
+ url = assertArg(url);
24
+ let path = decodeURIComponent(
25
+ url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
26
+ ).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\");
27
+ if (url.hostname !== "") {
28
+ // Note: The `URL` implementation guarantees that the drive letter and
29
+ // hostname are mutually exclusive. Otherwise it would not have been valid
30
+ // to append the hostname and path like this.
31
+ path = `\\\\${url.hostname}${path}`;
32
+ }
33
+ return path;
34
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import {
5
+ _globToRegExp,
6
+ type GlobConstants,
7
+ type GlobOptions,
8
+ } from "../_common/glob_to_reg_exp.js";
9
+
10
+ const constants: GlobConstants = {
11
+ sep: "(?:\\\\|/)+",
12
+ sepMaybe: "(?:\\\\|/)*",
13
+ seps: ["\\", "/"],
14
+ globstar: "(?:[^\\\\/]*(?:\\\\|/|$)+)*",
15
+ wildcard: "[^\\\\/]*",
16
+ escapePrefix: "`",
17
+ };
18
+
19
+ /** Convert a glob string to a regular expression.
20
+ *
21
+ * Tries to match bash glob expansion as closely as possible.
22
+ *
23
+ * Basic glob syntax:
24
+ * - `*` - Matches everything without leaving the path segment.
25
+ * - `?` - Matches any single character.
26
+ * - `{foo,bar}` - Matches `foo` or `bar`.
27
+ * - `[abcd]` - Matches `a`, `b`, `c` or `d`.
28
+ * - `[a-d]` - Matches `a`, `b`, `c` or `d`.
29
+ * - `[!abcd]` - Matches any single character besides `a`, `b`, `c` or `d`.
30
+ * - `[[:<class>:]]` - Matches any character belonging to `<class>`.
31
+ * - `[[:alnum:]]` - Matches any digit or letter.
32
+ * - `[[:digit:]abc]` - Matches any digit, `a`, `b` or `c`.
33
+ * - See https://facelessuser.github.io/wcmatch/glob/#posix-character-classes
34
+ * for a complete list of supported character classes.
35
+ * - `\` - Escapes the next character for an `os` other than `"windows"`.
36
+ * - \` - Escapes the next character for `os` set to `"windows"`.
37
+ * - `/` - Path separator.
38
+ * - `\` - Additional path separator only for `os` set to `"windows"`.
39
+ *
40
+ * Extended syntax:
41
+ * - Requires `{ extended: true }`.
42
+ * - `?(foo|bar)` - Matches 0 or 1 instance of `{foo,bar}`.
43
+ * - `@(foo|bar)` - Matches 1 instance of `{foo,bar}`. They behave the same.
44
+ * - `*(foo|bar)` - Matches _n_ instances of `{foo,bar}`.
45
+ * - `+(foo|bar)` - Matches _n > 0_ instances of `{foo,bar}`.
46
+ * - `!(foo|bar)` - Matches anything other than `{foo,bar}`.
47
+ * - See https://www.linuxjournal.com/content/bash-extended-globbing.
48
+ *
49
+ * Globstar syntax:
50
+ * - Requires `{ globstar: true }`.
51
+ * - `**` - Matches any number of any path segments.
52
+ * - Must comprise its entire path segment in the provided glob.
53
+ * - See https://www.linuxjournal.com/content/globstar-new-bash-globbing-option.
54
+ *
55
+ * Note the following properties:
56
+ * - The generated `RegExp` is anchored at both start and end.
57
+ * - Repeating and trailing separators are tolerated. Trailing separators in the
58
+ * provided glob have no meaning and are discarded.
59
+ * - Absolute globs will only match absolute paths, etc.
60
+ * - Empty globs will match nothing.
61
+ * - Any special glob syntax must be contained to one path segment. For example,
62
+ * `?(foo|bar/baz)` is invalid. The separator will take precedence and the
63
+ * first segment ends with an unclosed group.
64
+ * - If a path segment ends with unclosed groups or a dangling escape prefix, a
65
+ * parse error has occurred. Every character for that segment is taken
66
+ * literally in this event.
67
+ *
68
+ * Limitations:
69
+ * - A negative group like `!(foo|bar)` will wrongly be converted to a negative
70
+ * look-ahead followed by a wildcard. This means that `!(foo).js` will wrongly
71
+ * fail to match `foobar.js`, even though `foobar` is not `foo`. Effectively,
72
+ * `!(foo|bar)` is treated like `!(@(foo|bar)*)`. This will work correctly if
73
+ * the group occurs not nested at the end of the segment.
74
+ *
75
+ * @example Usage
76
+ * ```ts
77
+ * import { globToRegExp } from "@std/path/windows/glob-to-regexp";
78
+ * import { assertEquals } from "@std/assert";
79
+ *
80
+ * assertEquals(globToRegExp("*.js"), /^[^\\/]*\.js(?:\\|\/)*$/);
81
+ * ```
82
+ *
83
+ * @param glob Glob string to convert.
84
+ * @param options Conversion options.
85
+ * @returns The regular expression equivalent to the glob.
86
+ */
87
+ export function globToRegExp(
88
+ glob: string,
89
+ options: GlobOptions = {},
90
+ ): RegExp {
91
+ return _globToRegExp(constants, glob, options);
92
+ }
@@ -0,0 +1,40 @@
1
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { CHAR_COLON } from "../_common/constants.js";
5
+ import { assertPath } from "../_common/assert_path.js";
6
+ import { isPathSeparator, isWindowsDeviceRoot } from "./_util.js";
7
+
8
+ /**
9
+ * Verifies whether provided path is absolute.
10
+ *
11
+ * @example Usage
12
+ * ```ts
13
+ * import { isAbsolute } from "@std/path/windows/is-absolute";
14
+ * import { assert, assertFalse } from "@std/assert";
15
+ *
16
+ * assert(isAbsolute("C:\\foo\\bar"));
17
+ * assertFalse(isAbsolute("..\\baz"));
18
+ * ```
19
+ *
20
+ * @param path The path to verify.
21
+ * @returns `true` if the path is absolute, `false` otherwise.
22
+ */
23
+ export function isAbsolute(path: string): boolean {
24
+ assertPath(path);
25
+
26
+ const len = path.length;
27
+ if (len === 0) return false;
28
+
29
+ const code = path.charCodeAt(0);
30
+ if (isPathSeparator(code)) {
31
+ return true;
32
+ } else if (isWindowsDeviceRoot(code)) {
33
+ // Possible device root
34
+
35
+ if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
36
+ if (isPathSeparator(path.charCodeAt(2))) return true;
37
+ }
38
+ }
39
+ return false;
40
+ }