# Class: URIUtil

## URIUtil()

Some helper functions (static methods) related to URIs and to file paths.

## Constructor

#### new URIUtil()

Source:
  - res/URIUtil.js, line 27

### Methods

#### (static) csriURLToURI(url) → {string}

Converts specified URI to an actual URI if it's a "csri:" URL (Client Side Resource Identifier, an URL form common to XMLEditor and XXE server of an URI managed by client-code); returns specified URI as is otherwise.

"csri:" URL examples:

    csri://(file)@no-authority/tmp/doc.xml
    csri://(file)@myserver/share/docs/doc.xml
    csri://(urn)@opaque-uri/ietf:rfc:2648
    csri://(https)@www.xmlmind.com:80/xmleditor/index.html
    csri://(ftp)foo:bar@xmlmind.com/xmleditor/index.html

##### Parameters:

Name | Type | Description
--- | --- | ---
`url` | string | an URL, possibly a "csri:" one.

Source:
  - res/URIUtil.js, line 47

##### Returns:

corresponding URI.

Type
  string

#### (static) isAbsolutePath(path, pathSepar) → {boolean}

Tests whether specified path is absolute or relative.

On Windows, a drive relative path like "\foo\bar" is considered to be relative. Only "C:\foo\bar" or "\\my-server\foo\bar" are considered to be absolute.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path.
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs).

Source:
  - res/URIUtil.js, line 706

##### Returns:

`true` if absolute; `false` if relative.

Type
  boolean

#### (static) isAbsoluteURI(uri) → {boolean}

Tests whether specified URI is an absolute hierarchical URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.

Source:
  - res/URIUtil.js, line 317

##### Returns:

`true` if it's an absolute hierarchical URI; `false` otherwise.

Type
  boolean

#### (static) joinURI()

Join specified URI components and return resulting URI.

Specified URI components are joined as is, that is, without first encoding them using `encodeURIComponent`.

Source:
  - res/URIUtil.js, line 285

#### (static) normalizeFileURI()

Returns specified absolute URI after normalizing its authority if it's a "file:" URI. Otherwise returns specified URI as is.

Source:
  - res/URIUtil.js, line 437

#### (static) normalizePath(path, pathSepar) → {string}

Returns specified relative or absolute path after normalizing it, that is, after removing ".", ".." and duplicate path separators from it.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path.
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs).

Source:
  - res/URIUtil.js, line 751

##### Returns:

normalized path or original path if it is not possible to normalize it (examples: "../../foo/bar", "a/ /b/c").

Type
  string

#### (static) pathBasename(path, pathSepar) → {string}

Returns the base name of specified path. To make it simple, the substring after last '/'.

Examples:

- Returns the empty string for "`/`".
- Returns "`foo`" for "`foo`".
- Returns "`bar`" for "`/foo/bar`".
- Returns "`bar`" for "`/foo/bar/`".

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs)

Source:
  - res/URIUtil.js, line 822

##### Returns:

base name of specified path

Type
  string

#### (static) pathExtension(path, pathSepar) → {string}

Returns the extension of specified path. To make it simple, the substring after last '.', not including last '.'.

- Returns `null` for "`/tmp/test`".
- Returns the empty string for "`/tmp/test.`".
- Returns `null` for "`~/.profile`".
- Returns "`gz`" for "`/tmp/test.tar.gz`".

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path possibly having an extension
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs)

Source:
  - res/URIUtil.js, line 777

##### Returns:

extension if any; `null` otherwise

Type
  string

#### (static) pathParent(path, pathSepar, trailingSepar) → {string}

Returns the parent of specified path. To make it simple, the substring before last '/'.

Examples:

- Returns `null` for "`/`".
- Returns `null` for "`foo`".
- Returns "`/`" for "`/foo`".
- Returns "`/foo`" (or "`/foo/`") for "`/foo/bar`".
- Returns "`/foo`" (or "`/foo/`") for "`/foo/bar/`".

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs)
`trailingSepar` | string | if `true`, returned path ends with a trailing `pathSepar` character

Source:
  - res/URIUtil.js, line 865

##### Returns:

parent of specified path or `null` for `pathSepar` or if specified path does not contain the `pathSepar` character

Type
  string

#### (static) pathToFileURI(path, pathSeparopt) → {string}

Convert specified path to a "file:" URI.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`path` | string |  |  | relative or absolute path.
`pathSepar` | string | <optional> | FILE_PATH_SEPARATOR | pathSepar - the character used to separate file path segments (that is, '\' on Windows).

Source:
  - res/URIUtil.js, line 518

##### Returns:

corresponding relative or absolute "file:" URI. Note that if `path` is relative, this URI will have no "file:" scheme (e.g. returns "tmp/my%20doc.xml" for "tmp\\my doc.xml");

Type
  string

#### (static) relativizePath(path, basePath, pathSepar) → {string}

Returns specified path after making it relative to the other path (when this is possible).

IMPORTANT: a directory path is expected to end with `pathSepar`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | an absolute path.
`basePath` | string | another absolute path which is used as a base.
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs)

Source:
  - res/URIUtil.js, line 911

##### Returns:

the relative path when possible; specified path as is otherwise (Windows example: when specified paths don't have the same drive.

Type
  string

#### (static) relativizeURI(uri, baseURI) → {string}

Returns specified URI after making it relative to the other URI (when this is possible).

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | an absolute, valid URI.
`baseURI` | string | another absolute, valid URI which is used as a base URI.

Source:
  - res/URIUtil.js, line 333

##### Returns:

the relative URI when possible; specified uri as is otherwise (for example, when specified URIs don't have the same scheme or authority).

Type
  string

#### (static) resolvePath(path, basePath, pathSepar) → {string}

Resolves specified path against specified base.

IMPORTANT: a directory path is expected to end with `pathSepar`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`path` | string | relative or absolute path.
`basePath` | string | relative or absolute path.
`pathSepar` | string | the character used to separate path segments (that is, '/' for URIs).

Source:
  - res/URIUtil.js, line 722

##### Returns:

resolved path.

Type
  string

#### (static) resolveURI(uri, baseURI) → {string}

Returns specified relative URI after resolving it against the other URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.
`baseURI` | string | an absolute, valid URI which is used as a base URI.

Source:
  - res/URIUtil.js, line 413

##### Returns:

the resolved URI when possible; specified uri as is otherwise (for example, when specified URI is already absolute).

Type
  string

#### (static) splitURI(uri) → {array}

Splits specified URI into its components: scheme, authority, path, query, fragment.

Note that returned URI components are NOT decoded using `decodeURIComponent`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.

Source:
  - res/URIUtil.js, line 169

##### Returns:

an array containing scheme, authority, path, query, fragment, each of this component possibly being `null` or just the empty string.

Type
  array

#### (static) uriBasename(uri) → {string}

Returns the basename, if any, of specified URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.

Source:
  - res/URIUtil.js, line 92
See:
  - URLUtil#uriRawBasename

##### Returns:

the basename of specified URI decoded using `decodeURIComponent` if any; `null` otherwise.

Type
  string

#### (static) uriExtension(uri) → {string}

Returns the file extension, if any, of specified URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.

Source:
  - res/URIUtil.js, line 246

##### Returns:

the file extension of specified URI if any; `null` otherwise.

Type
  string

#### (static) uriParent(uri, trailingSeparopt) → {string}

Returns the parent, if any, of specified URI.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`uri` | string |  |  | a relative or absolute, valid URI.
`trailingSepar` | string | <optional> | true | trailingSepar - if `true`, returned URI has a path which ends with a trailing `'/'` character.

Source:
  - res/URIUtil.js, line 266

##### Returns:

the parent of specified URI if any; `null` otherwise.

Type
  string

#### (static) uriRawBasename(uri) → {string}

Returns the basename, if any, of specified URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.

Source:
  - res/URIUtil.js, line 105
See:
  - URLUtil#uriBasename

##### Returns:

the basename of specified URI if any; `null` otherwise.

Type
  string

#### (static) uriSetBasename(uri, basename) → {string}

Changes the basename of specified URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.
`basename` | string | the new basename to be encoded using `encodeURIComponent`.

Source:
  - res/URIUtil.js, line 128
See:
  - URLUtil#uriSetRawBasename

##### Returns:

modified URI; `null` if specified URI has no path.

Type
  string

#### (static) uriSetRawBasename(uri, basename) → {string}

Changes the basename of specified URI.

##### Parameters:

Name | Type | Description
--- | --- | ---
`uri` | string | a relative or absolute, valid URI.
`basename` | string | the new basename.

Source:
  - res/URIUtil.js, line 141
See:
  - URLUtil#uriSetBasename

##### Returns:

modified URI; `null` if specified URI has no path.

Type
  string

#### (static) uriToFilePath(uri, pathSeparopt) → {string}

Returns the file path corresponding to specified absolute "file:" URI.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`uri` | string |  |  | an absolute, valid, "file:" URI.
`pathSepar` | string | <optional> | FILE_PATH_SEPARATOR | pathSepar - the character used to separate file path segments (that is, '\' on Windows).

Source:
  - res/URIUtil.js, line 470

##### Returns:

corresponding absolute file path when possible, `null` otherwise.

Type
  string