1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 x1 |
/**
* Utilities for working with
* {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/URL | URL}s.
*
* ```ts
* import { basename, join, normalize } from "@std/url";
* import { assertEquals } from "@std/assert";
*
* const url = new URL("https:///deno.land///std//assert//.//mod.ts");
* const normalizedUrl = normalize(url);
*
* assertEquals(normalizedUrl.href, "https://deno.land/std/assert/mod.ts");
* assertEquals(basename(normalizedUrl), "mod.ts");
*
* const joinedUrl = join(normalizedUrl, "..", "..", "async", "retry.ts");
*
* assertEquals(joinedUrl.href, "https://deno.land/std/async/retry.ts");
* ```
*
* @deprecated Use functions from
* {@linkcode https://jsr.io/@std/path/doc/posix/~ | @std/path/posix}
* instead (examples included). `@std/url` will be removed in the future.
*
* @module
*/
import { basename as _function_basename } from "jsr:@std/[email protected]"
/**
* Returns the base name of a URL or URL string, optionally removing a suffix.
*
* Trailing `/`s are ignored. If no path is present, the host name is returned.
* If a suffix is provided, it will be removed from the base name. URL queries
* and hashes are ignored.
*
* @param url The URL from which to extract the base name.
* @param suffix An optional suffix to remove from the base name.
* @return The base name of the URL.
*
* @example Basic usage
* ```ts
* import { basename } from "@std/url/basename";
* import { assertEquals } from "@std/assert";
*
* assertEquals(basename("https://deno.land/std/assert/mod.ts"), "mod.ts");
* assertEquals(basename(new URL("https://deno.land/std/assert/mod.ts")), "mod.ts");
* assertEquals(basename("https://deno.land/std/assert/mod.ts?a=b"), "mod.ts");
* assertEquals(basename("https://deno.land/std/assert/mod.ts#header"), "mod.ts");
* assertEquals(basename("https://deno.land/"), "deno.land");
* ```
*
* @example Removing a suffix
*
* Defining a suffix will remove it from the base name.
*
* ```ts
* import { basename } from "@std/url/basename";
* import { assertEquals } from "@std/assert";
*
* assertEquals(basename("https://deno.land/std/assert/mod.ts", ".ts"), "mod");
* assertEquals(basename(new URL("https://deno.land/std/assert/mod.ts"), ".ts"), "mod");
* assertEquals(basename("https://deno.land/std/assert/mod.ts?a=b", ".ts"), "mod");
* assertEquals(basename("https://deno.land/std/assert/mod.ts#header", ".ts"), "mod");
* ```
*
* @deprecated Use
* {@linkcode https://jsr.io/@std/path/doc/~/basename | @std/path/basename}
* instead. `@std/url` will be removed in the future.
*/
const basename = _function_basename as typeof _function_basename
export { basename }
import { dirname as _function_dirname } from "jsr:@std/[email protected]"
/**
* Returns the directory path URL of a URL or URL string.
*
* The directory path is the portion of a URL up to but excluding the final path
* segment. URL queries and hashes are ignored.
*
* @param url URL to extract the directory from.
* @return The directory path URL of the URL.
*
* @example Usage
* ```ts
* import { dirname } from "@std/url/dirname";
* import { assertEquals } from "@std/assert";
*
* assertEquals(dirname("https://deno.land/std/path/mod.ts"), new URL("https://deno.land/std/path"));
* assertEquals(dirname(new URL("https://deno.land/std/path/mod.ts")), new URL("https://deno.land/std/path"));
* ```
*
* @deprecated Use
* {@linkcode https://jsr.io/@std/path/doc/~/dirname | @std/path/dirname}
* instead. `@std/url` will be removed in the future.
*/
const dirname = _function_dirname as typeof _function_dirname
export { dirname }
import { extname as _function_extname } from "jsr:@std/[email protected]"
/**
* Returns the file extension of a given URL or string with leading period.
*
* The extension is sourced from the path portion of the URL. If there is no
* extension, an empty string is returned. URL queries and hashes are ignored.
*
* @param url The URL from which to extract the extension.
* @return The extension of the URL.
*
* @example Usage
* ```ts
* import { extname } from "@std/url/extname";
* import { assertEquals } from "@std/assert";
*
* assertEquals(extname("https://deno.land/std/path/mod.ts"), ".ts");
* assertEquals(extname("https://deno.land/std/path/mod"), "");
* assertEquals(extname("https://deno.land/std/path/mod.ts?a=b"), ".ts");
* assertEquals(extname("https://deno.land/"), "");
* ```
*
* @deprecated Use
* {@linkcode https://jsr.io/@std/path/doc/~/extname | @std/path/extname}
* instead. `@std/url` will be removed in the future.
*/
const extname = _function_extname as typeof _function_extname
export { extname }
import { join as _function_join } from "jsr:@std/[email protected]"
/**
* Joins a base URL or URL string, and a sequence of path segments together,
* then normalizes the resulting URL.
*
* @param url Base URL to be joined with the paths and normalized.
* @param paths Array of path segments to be joined to the base URL.
* @return A complete URL containing the base URL joined with the paths.
*
* @example Usage
*
* ```ts
* import { join } from "@std/url/join";
* import { assertEquals } from "@std/assert";
*
* assertEquals(join("https://deno.land/", "std", "path", "mod.ts").href, "https://deno.land/std/path/mod.ts");
* assertEquals(join("https://deno.land", "//std", "path/", "/mod.ts").href, "https://deno.land/std/path/mod.ts");
* ```
*
* @deprecated Use
* {@linkcode https://jsr.io/@std/path/doc/~/join | @std/path/join}
* instead. `@std/url` will be removed in the future.
*/
const join = _function_join as typeof _function_join
export { join }
import { normalize as _function_normalize } from "jsr:@std/[email protected]"
/**
* Normalizes the URL or URL string, resolving `..` and `.` segments. Multiple
* sequential `/`s are resolved into a single `/`.
*
* @param url URL to be normalized.
* @return Normalized URL.
*
* @example Usage
*
* ```ts
* import { normalize } from "@std/url/normalize";
* import { assertEquals } from "@std/assert";
*
* assertEquals(normalize("https:///deno.land///std//assert//.//mod.ts").href, "https://deno.land/std/assert/mod.ts");
* assertEquals(normalize("https://deno.land/std/assert/../async/retry.ts").href, "https://deno.land/std/async/retry.ts");
* ```
*
* @deprecated Use
* {@linkcode https://jsr.io/@std/path/doc/~/normalize | @std/path/normalize}
* instead. `@std/url` will be removed in the future.
*/
const normalize = _function_normalize as typeof _function_normalize
export { normalize }
|