@flex-development/pathe
Version:
Universal drop-in replacement for node:path
71 lines (70 loc) • 2.17 kB
text/typescript
/**
* @file pathToFileURL
* @module pathe/lib/pathToFileURL
*/
import type { PathToFileUrlOptions } from '@flex-development/pathe';
export default pathToFileURL;
/**
* Convert a file `path` to a `file:` {@linkcode URL} string.
*
* > The following characters are percent-encoded when converting from file path
* > to a `URL`:
* >
* > - %: Only character not encoded by the `pathname` setter
* > - CR: Stripped out by the `pathname` setter (see [`whatwg/url#419`][419])
* > - LF: Stripped out by the `pathname` setter (see [`whatwg/url#419`][419])
* > - TAB: Stripped out by the `pathname` setter
*
* [419]: https://github.com/whatwg/url/issues/419
*
* @see {@linkcode ErrInvalidArgValue}
* @see {@linkcode PathToFileUrlOptions}
*
* @category
* utils
*
* @this {void}
*
* @param {string} path
* The path to handle
* @param {Omit<PathToFileUrlOptions, 'string'> & { string: true }} options
* Conversion options
* @param {true} options.string
* Return `file:` URL string?
* @return {string}
* `path` as `file:` URL string
* @throws {ErrInvalidArgValue}
*/
declare function pathToFileURL(this: void, path: string, options: Omit<PathToFileUrlOptions, 'string'> & {
string: true;
}): string;
/**
* Convert a file `path` to a `file:` {@linkcode URL}.
*
* > The following characters are percent-encoded when converting from file path
* > to a `URL`:
* >
* > - %: Only character not encoded by the `pathname` setter
* > - CR: Stripped out by the `pathname` setter (see [`whatwg/url#419`][419])
* > - LF: Stripped out by the `pathname` setter (see [`whatwg/url#419`][419])
* > - TAB: Stripped out by the `pathname` setter
*
* [419]: https://github.com/whatwg/url/issues/419
*
* @see {@linkcode ErrInvalidArgValue}
* @see {@linkcode PathToFileUrlOptions}
*
* @category
* utils
*
* @this {void}
*
* @param {string} path
* The path to handle
* @param {PathToFileUrlOptions | null | undefined} [options]
* Conversion options
* @return {URL}
* `path` as `file:` URL
* @throws {ErrInvalidArgValue}
*/
declare function pathToFileURL(this: void, path: string, options?: PathToFileUrlOptions | null | undefined): URL;