source: imaps-frontend/node_modules/relateurl/lib/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2
3var constants = require("./constants");
4var formatUrl = require("./format");
5var getOptions = require("./options");
6var objUtils = require("./util/object");
7var parseUrl = require("./parse");
8var relateUrl = require("./relate");
9
10
11
12function RelateUrl(from, options)
13{
14 this.options = getOptions(options,
15 {
16 defaultPorts: {ftp:21, http:80, https:443},
17 directoryIndexes: ["index.html"],
18 ignore_www: false,
19 output: RelateUrl.SHORTEST,
20 rejectedSchemes: ["data","javascript","mailto"],
21 removeAuth: false,
22 removeDirectoryIndexes: true,
23 removeEmptyQueries: false,
24 removeRootTrailingSlash: true,
25 schemeRelative: true,
26 site: undefined,
27 slashesDenoteHost: true
28 });
29
30 this.from = parseUrl.from(from, this.options, null);
31}
32
33
34
35/*
36 Usage: instance=new RelateUrl(); instance.relate();
37*/
38RelateUrl.prototype.relate = function(from, to, options)
39{
40 // relate(to,options)
41 if ( objUtils.isPlainObject(to) )
42 {
43 options = to;
44 to = from;
45 from = null;
46 }
47 // relate(to)
48 else if (!to)
49 {
50 to = from;
51 from = null;
52 }
53
54 options = getOptions(options, this.options);
55 from = from || options.site;
56 from = parseUrl.from(from, options, this.from);
57
58 if (!from || !from.href)
59 {
60 throw new Error("from value not defined.");
61 }
62 else if (from.extra.hrefInfo.minimumPathOnly)
63 {
64 throw new Error("from value supplied is not absolute: "+from.href);
65 }
66
67 to = parseUrl.to(to, options);
68
69 if (to.valid===false) return to.href;
70
71 to = relateUrl(from, to, options);
72 to = formatUrl(to, options);
73
74 return to;
75}
76
77
78
79/*
80 Usage: RelateUrl.relate();
81*/
82RelateUrl.relate = function(from, to, options)
83{
84 return new RelateUrl().relate(from, to, options);
85}
86
87
88
89// Make constants accessible from API
90objUtils.shallowMerge(RelateUrl, constants);
91
92
93
94module.exports = RelateUrl;
Note: See TracBrowser for help on using the repository browser.