Skip to content

Interface: Uri

Uniform Resource Identifier (Uri) http://tools.ietf.org/html/rfc3986. This class is a simple parser which creates the basic component parts (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation and encoding.

txt
      foo://example.com:8042/over/there?name=ferret#nose
      \_/   \______________/\_________/ \_________/ \__/
       |           |            |            |        |
    scheme     authority       path        query   fragment
       |   _____________________|__
      / \ /                        \
      urn:example:animal:ferret:nose

Implements

  • UriComponents

Properties

PropertyModifierTypeDescription
authorityreadonlystringauthority is the 'www.example.com' part of 'http://www.example.com/some/path?query#fragment'. The part between the first double slashes and the next slash.
fragmentreadonlystringfragment is the 'fragment' part of 'http://www.example.com/some/path?query#fragment'.
pathreadonlystringpath is the '/some/path' part of 'http://www.example.com/some/path?query#fragment'.
queryreadonlystringquery is the 'query' part of 'http://www.example.com/some/path?query#fragment'.
schemereadonlystringscheme is the 'http' part of 'http://www.example.com/some/path?query#fragment'. The part before the first colon.

Accessors

fsPath

Get Signature

ts
get fsPath(): string;

Returns a string representing the corresponding file system path of this Uri. Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the platform specific path separator.

  • Will not validate the path for invalid characters and semantics.
  • Will not look at the scheme of this Uri.
  • The result shall not be used for display purposes but for accessing a file on disk.

The difference to Uri#path is the use of the platform specific separator and the handling of UNC paths. See the below sample of a file-uri with an authority (UNC path).

ts
const u = Uri.parse("file://server/c$/folder/file.txt");
u.authority === "server";
u.path === "/shares/c$/file.txt";
u.fsPath === "\\server\c$\folder\file.txt";

Using Uri#path to read a file (using fs-apis) would not be enough because parts of the path, namely the server name, would be missing. Therefore Uri#fsPath exists - it's sugar to ease working with URIs that represent files on disk (file scheme).

Returns

string

Methods

toJSON()

ts
toJSON(): UriComponents;

Returns

UriComponents


toString()

ts
toString(skipEncoding?: boolean): string;

Creates a string representation for this Uri. It's guaranteed that calling Uri.parse with the result of this function creates an Uri which is equal to this Uri.

  • The result shall not be used for display purposes but for externalization or transport.
  • The result will be encoded using the percentage encoding and encoding happens mostly ignore the scheme-specific encoding rules.

Parameters

ParameterTypeDescription
skipEncoding?booleanDo not encode the result, default is false

Returns

string


with()

ts
with(change: {
  authority?: string | null;
  fragment?: string | null;
  path?: string | null;
  query?: string | null;
  scheme?: string;
}): Uri;

Parameters

ParameterType
change{ authority?: string | null; fragment?: string | null; path?: string | null; query?: string | null; scheme?: string; }
change.authority?string | null
change.fragment?string | null
change.path?string | null
change.query?string | null
change.scheme?string

Returns

Uri