File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed
Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @file Internal - validateFileURL
3+ * @module pathe/internal/validateFileURL
4+ */
5+
6+ import validateURLString from '#internal/validate-url-string'
7+ import {
8+ ERR_INVALID_URL_SCHEME ,
9+ type ErrInvalidArgType ,
10+ type ErrInvalidUrlScheme
11+ } from '@flex-development/errnode'
12+
13+ /**
14+ * Check if `value` is a `file:` {@linkcode URL} object or string.
15+ *
16+ * @internal
17+ *
18+ * @param {unknown } value
19+ * Value to check
20+ * @param {string } name
21+ * Name of invalid argument or property
22+ * @return {value is URL | string }
23+ * `true` if `value` is `file:` URL object or string
24+ * @throws {ErrInvalidArgType }
25+ * If `value` is not `URL` object or string
26+ * @throws {ErrInvalidUrlScheme }
27+ * If `value` is not a `file:` URL object or string
28+ */
29+ function validateFileURL (
30+ value : unknown ,
31+ name : string
32+ ) : value is URL | string {
33+ validateURLString ( value , name )
34+ if ( String ( value ) . startsWith ( 'file:' ) ) return true
35+ throw new ERR_INVALID_URL_SCHEME ( 'file' )
36+ }
37+
38+ export default validateFileURL
Original file line number Diff line number Diff line change 11/**
22 * @file Unit Tests - fileURLToPath
33 * @module pathe/lib/tests/unit/fileURLToPath
4- * @see https://github.com/nodejs/node/blob/v23.2 .0/test/parallel/test-url-fileurltopath.js
4+ * @see https://github.com/nodejs/node/blob/v23.4 .0/test/parallel/test-url-fileurltopath.js
55 */
66
77import process from '#internal/process'
Original file line number Diff line number Diff line change 66import { isWindows } from '#internal/constants'
77import domainToUnicode from '#internal/domain-to-unicode'
88import process from '#internal/process'
9- import validateURLString from '#internal/validate-url-string '
9+ import validateFileURL from '#internal/validate-file-url '
1010import isDeviceRoot from '#lib/is-device-root'
1111import isSep from '#lib/is-sep'
1212import sep from '#lib/sep'
1313import toPosix from '#lib/to-posix'
1414import {
1515 ERR_INVALID_FILE_URL_HOST ,
1616 ERR_INVALID_FILE_URL_PATH ,
17- ERR_INVALID_URL_SCHEME ,
1817 type ErrInvalidFileUrlHost ,
1918 type ErrInvalidFileUrlPath ,
2019 type ErrInvalidUrlScheme
@@ -49,9 +48,7 @@ function fileURLToPath(
4948 url : URL | string ,
5049 options ?: FileUrlToPathOptions | null | undefined
5150) : string {
52- validateURLString ( url , 'url' )
53-
54- if ( ! String ( url ) . startsWith ( 'file:' ) ) throw new ERR_INVALID_URL_SCHEME ( 'file' )
51+ validateFileURL ( url , 'url' )
5552 if ( typeof url === 'string' ) url = new URL ( url )
5653
5754 /**
You can’t perform that action at this time.
0 commit comments