mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
Add definitions for relateurl (https://github.com/stevenvachon/relateurl)
This commit is contained in:
20
relateurl/relateurl-tests.ts
Normal file
20
relateurl/relateurl-tests.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference path="relateurl.d.ts" />
|
||||
|
||||
import * as RelateUrl from 'relateurl';
|
||||
|
||||
var from = "http://www.domain.com/asdf/";
|
||||
var to = "http://www.domain.com/asdf/asdf";
|
||||
var to1 = "http://www.domain.com/asdf/asdf1";
|
||||
var to2 = "http://www.domain.com/asdf/asdf1";
|
||||
var to3 = "http://www.domain.com/asdf/asdf1";
|
||||
var options = {site: "http://www.domain.com/asdf2/"};
|
||||
var customOptions = {output: RelateUrl.ABSOLUTE};
|
||||
|
||||
// Single Instance
|
||||
var result = RelateUrl.relate(from, to, options);
|
||||
|
||||
// Reusable Instances
|
||||
var instance = new RelateUrl(from, options);
|
||||
var result1 = instance.relate(to1);
|
||||
var result2 = instance.relate(to2, customOptions);
|
||||
var result3 = instance.relate(to3);
|
||||
125
relateurl/relateurl.d.ts
vendored
Normal file
125
relateurl/relateurl.d.ts
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
// Type definitions for relateurl v0.2.6
|
||||
// Project: https://github.com/stevenvachon/relateurl
|
||||
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'relateurl' {
|
||||
namespace RelateUrl {
|
||||
interface Options {
|
||||
/**
|
||||
* Type: Object
|
||||
* Default value: {ftp:21, http:80, https:443}
|
||||
*
|
||||
* Extend the list with any ports you need. Any URLs containing these default ports will have them removed. Example: http://example.com:80/ will become http://example.com/.
|
||||
*/
|
||||
defaultPorts?: Object;
|
||||
|
||||
/**
|
||||
* Type: Array
|
||||
* Default value: ["index.html"]
|
||||
*
|
||||
* Extend the list with any resources you need. Works with options.removeDirectoryIndexes.
|
||||
*/
|
||||
directoryIndexes?: Array<string>;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: false
|
||||
*
|
||||
* This will, for example, consider any domains containing http://www.example.com/ to be related to any that contain http://example.com/.
|
||||
*/
|
||||
ignore_www?: boolean;
|
||||
|
||||
/**
|
||||
* Type: constant or String
|
||||
* Choices: RelateUrl.ABSOLUTE,RelateUrl.PATH_RELATIVE,RelateUrl.ROOT_RELATIVE,RelateUrl.SHORTEST
|
||||
* Choices: "absolute","pathRelative","rootRelative","shortest"
|
||||
* Default value: RelateUrl.SHORTEST
|
||||
*
|
||||
* RelateUrl.ABSOLUTE will produce an absolute URL. Overrides options.schemeRelative with a value of false.
|
||||
* RelateUrl.PATH_RELATIVE will produce something like ../child-of-parent/etc/.
|
||||
* RelateUrl.ROOT_RELATIVE will produce something like /child-of-root/etc/.
|
||||
* RelateUrl.SHORTEST will choose whichever is shortest between root- and path-relative.
|
||||
*/
|
||||
output?: string;
|
||||
|
||||
/**
|
||||
* Type: Array
|
||||
* Default value: ["data","javascript","mailto"]
|
||||
*
|
||||
* Extend the list with any additional schemes. Example: javascript:something will not be modified.
|
||||
*/
|
||||
rejectedSchemes?: Array<string>;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: false
|
||||
*
|
||||
* Remove user authentication information from the output URL.
|
||||
*/
|
||||
removeAuth?: boolean;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: true
|
||||
*
|
||||
* Remove any resources that match any found in options.directoryIndexes.
|
||||
*/
|
||||
removeDirectoryIndexes?: boolean;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: false
|
||||
*
|
||||
* Remove empty query variables. Example: http://domain.com/?var1&var2=&var3=asdf will become http://domain.com/?var3=adsf. This does not apply to unrelated URLs (with other protocols, auths, hosts and/or ports).
|
||||
*/
|
||||
removeEmptyQueries?: boolean;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: true
|
||||
*
|
||||
* Remove trailing slashes from root paths. Example: http://domain.com/?var will become http://domain.com?var while http://domain.com/dir/?var will not be modified.
|
||||
*/
|
||||
removeRootTrailingSlash?: boolean;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: true
|
||||
*
|
||||
* Output URLs relative to the scheme. Example: http://example.com/ will become //example.com/.
|
||||
*/
|
||||
schemeRelative?: boolean;
|
||||
|
||||
/**
|
||||
* Type: String
|
||||
* Default value: undefined
|
||||
*
|
||||
* An options-based version of the from argument. If both are specified, from takes priority.
|
||||
*/
|
||||
site?: string;
|
||||
|
||||
/**
|
||||
* Type: Boolean
|
||||
* Default value: true
|
||||
*
|
||||
* Passed to Node's url.parse.
|
||||
*/
|
||||
slashesDenoteHost?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
class RelateUrl {
|
||||
static ABSOLUTE: string;
|
||||
static PATH_RELATIVE: string;
|
||||
static ROOT_RELATIVE: string;
|
||||
static SHORTEST: string;
|
||||
|
||||
static relate(from: string, to: string, options?: RelateUrl.Options): string;
|
||||
|
||||
constructor(from: string, options?: RelateUrl.Options);
|
||||
relate(to: string, options?: RelateUrl.Options): string;
|
||||
}
|
||||
|
||||
export = RelateUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user