Merge pull request #30804 from BendingBender/iri

Add types for iri
This commit is contained in:
Andrew Casey
2018-12-03 18:12:18 -08:00
committed by GitHub
4 changed files with 156 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
// Type definitions for iri 1.3
// Project: https://github.com/awwright/node-iri
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export class IRI {
/**
* The constructor takes a single argument, a URI or IRI string:
*/
constructor(iri: string);
/**
* Returns UTF-16 IRI
*/
toString(): string;
/**
* Returns the IRI without the fragment component. Useful for dereferencing URLs on a network.
*/
defrag(): IRI;
/**
* IRIs with a fragment are not absolute.
*/
isAbsolute(): boolean;
/**
* Resolves the IRI against itself, having the effect of stripping the fragment and checking that the supplied IRI is valid (absolute).
*/
toAbsolute(): IRI;
/**
* Resolves the IRI against itself, having the effect of stripping the fragment and checking that the supplied IRI is valid (absolute).
*/
authority(): string | null;
/**
* Returns the fragment component of the IRI.
*/
fragment(): string | null;
/**
* Returns the hier-part of the IRI, the hierarchial component: Everything between the scheme and query, including leading `//` for the host, if it exists.
*/
hierpart(): string;
/**
* Returns the host component of the URI, either a domain name or string-formatted IP address. Excludes port number and username/password.
*/
host(): string;
/**
* Returns the path component of the hier-part. Does not include the authority/host, query, or fragment.
*/
path(): string;
/**
* Returns the port component of the authority as a string, or `null` if there is no port.
*/
port(): string | null;
/**
* Returns the query component of the IRI including leading "?", or `null` if there is no query component.
*/
query(): string | null;
/**
* Resolve the provided URI/IRI reference against this IRI.
*/
resolveReference(ref: string | IRI): IRI;
/**
* Returns the scheme of the IRI, e.g. "https", "file", or "urn".
*/
scheme(): string | null;
/**
* Returns the username/password component of the IRI.
*/
userinfo(): string | null;
/**
* Returns a URI formatted string with only 7-bit characters.
*/
toURIString(): string;
/**
* Decodes URI-encoded UTF-8 characters and returns a unicode string (Strings in ECMAScript/JavaScript are UTF-16).
*/
toIRIString(): string;
/**
* Returns a new IRI object with URI-encoded UTF-8 characters decoded.
*/
toIRI(): IRI;
}
/**
* Returns an iri.IRI object with UTF-8 escaped characterd decoded.
*/
export function fromURI(uri: string): IRI;
/**
* Returns an IRI string decoded from the given URI.
*/
export function toIRIString(uri: string): string;
+43
View File
@@ -0,0 +1,43 @@
import { IRI, fromURI, toIRIString } from 'iri';
const iri = new IRI('iri');
// $ExpectType string
iri.toString();
// $ExpectType IRI
iri.defrag();
// $ExpectType boolean
iri.isAbsolute();
// $ExpectType IRI
iri.toAbsolute();
// $ExpectType string | null
iri.authority();
// $ExpectType string | null
iri.fragment();
// $ExpectType string
iri.hierpart();
// $ExpectType string
iri.host();
// $ExpectType string
iri.path();
// $ExpectType string | null
iri.port();
// $ExpectType string | null
iri.query();
// $ExpectType IRI
iri.resolveReference('ref');
iri.resolveReference(iri);
// $ExpectType string | null
iri.scheme();
// $ExpectType string | null
iri.userinfo();
// $ExpectType string
iri.toURIString();
// $ExpectType string
iri.toIRIString();
// $ExpectType IRI
iri.toIRI();
// $ExpectType IRI
fromURI('u');
// $ExpectType string
toIRIString('u');
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"iri-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }