relateurl
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -9,3 +9,3 @@ "use strict"; | ||
{ | ||
if (urlObj.auth && !options.removeAuth && (urlObj.extra.relation.maximumHost || options.output==constants.ABSOLUTE)) | ||
if (urlObj.auth && !options.removeAuth && (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE)) | ||
{ | ||
@@ -29,3 +29,3 @@ return urlObj.auth + "@"; | ||
{ | ||
if (urlObj.host.full && (urlObj.extra.relation.maximumAuth || options.output==constants.ABSOLUTE)) | ||
if (urlObj.host.full && (urlObj.extra.relation.maximumAuth || options.output===constants.ABSOLUTE)) | ||
{ | ||
@@ -48,11 +48,11 @@ return urlObj.host.full; | ||
if (urlObj.extra.relation.maximumHost || options.output==constants.ABSOLUTE || options.output==constants.ROOT_RELATIVE) | ||
if (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE || options.output===constants.ROOT_RELATIVE) | ||
{ | ||
str = absolutePath; | ||
} | ||
else if (relativePath.length<=absolutePath.length && options.output==constants.SHORTEST || options.output==constants.PATH_RELATIVE) | ||
else if (relativePath.length<=absolutePath.length && options.output===constants.SHORTEST || options.output===constants.PATH_RELATIVE) | ||
{ | ||
str = relativePath; | ||
if (str == "") | ||
if (str === "") | ||
{ | ||
@@ -76,3 +76,3 @@ var query = showQuery(urlObj,options) && !!getQuery(urlObj,options); | ||
if ( str=="/" && !resource && options.removeRootTrailingSlash && (!urlObj.extra.relation.minimumPort || options.output==constants.ABSOLUTE) ) | ||
if ( str==="/" && !resource && options.removeRootTrailingSlash && (!urlObj.extra.relation.minimumPort || options.output===constants.ABSOLUTE) ) | ||
{ | ||
@@ -117,5 +117,5 @@ str = ""; | ||
if (urlObj.extra.relation.maximumHost || options.output==constants.ABSOLUTE) | ||
if (urlObj.extra.relation.maximumHost || options.output===constants.ABSOLUTE) | ||
{ | ||
if (!urlObj.extra.relation.minimumScheme || !options.schemeRelative || options.output==constants.ABSOLUTE) | ||
if (!urlObj.extra.relation.minimumScheme || !options.schemeRelative || options.output===constants.ABSOLUTE) | ||
{ | ||
@@ -164,3 +164,3 @@ str += urlObj.scheme + "://"; | ||
{ | ||
return !urlObj.extra.relation.minimumQuery || options.output==constants.ABSOLUTE || options.output==constants.ROOT_RELATIVE; | ||
return !urlObj.extra.relation.minimumQuery || options.output===constants.ABSOLUTE || options.output===constants.ROOT_RELATIVE; | ||
} | ||
@@ -173,3 +173,3 @@ | ||
var removeIndex = options.removeDirectoryIndexes && urlObj.extra.resourceIsIndex; | ||
var removeMatchingResource = urlObj.extra.relation.minimumResource && options.output!=constants.ABSOLUTE && options.output!=constants.ROOT_RELATIVE; | ||
var removeMatchingResource = urlObj.extra.relation.minimumResource && options.output!==constants.ABSOLUTE && options.output!==constants.ROOT_RELATIVE; | ||
@@ -176,0 +176,0 @@ return !!urlObj.resource && !removeMatchingResource && !removeIndex; |
@@ -41,3 +41,3 @@ "use strict"; | ||
// relate(to,options) | ||
if ( objUtils.isObject(to) ) | ||
if ( objUtils.isPlainObject(to) ) | ||
{ | ||
@@ -91,9 +91,3 @@ options = to; | ||
// Make constants accessible from API | ||
for (var i in constants) | ||
{ | ||
if ( constants.hasOwnProperty(i) ) | ||
{ | ||
Object.defineProperty(RelateUrl, i, {value:constants[i]}); | ||
} | ||
} | ||
objUtils.shallowMerge(RelateUrl, constants); | ||
@@ -100,0 +94,0 @@ |
@@ -9,3 +9,3 @@ "use strict"; | ||
{ | ||
if ( objUtils.isObject(options) ) | ||
if ( objUtils.isPlainObject(options) ) | ||
{ | ||
@@ -18,5 +18,5 @@ var newOptions = {}; | ||
{ | ||
if (options[i] != undefined) | ||
if (options[i] !== undefined) | ||
{ | ||
newOptions[i] = mergeOption(defaults[i], options[i]); | ||
newOptions[i] = mergeOption(options[i], defaults[i]); | ||
} | ||
@@ -40,3 +40,3 @@ else | ||
function mergeOption(defaultValues, newValues) | ||
function mergeOption(newValues, defaultValues) | ||
{ | ||
@@ -51,5 +51,3 @@ if (defaultValues instanceof Object && newValues instanceof Object) | ||
{ | ||
defaultValues = objUtils.clone(defaultValues); | ||
return objUtils.shallowMerge(defaultValues, newValues); | ||
return objUtils.shallowMerge(newValues, defaultValues); | ||
} | ||
@@ -56,0 +54,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
if (host.indexOf("www.") == 0) | ||
if (host.indexOf("www.") === 0) | ||
{ | ||
@@ -17,0 +17,0 @@ stripped = host.substr(4); |
@@ -9,3 +9,3 @@ "use strict"; | ||
{ | ||
if (index == resource) | ||
if (index === resource) | ||
{ | ||
@@ -38,3 +38,3 @@ verdict = true; | ||
if (resource!="." && resource!="..") | ||
if (resource!=="." && resource!=="..") | ||
{ | ||
@@ -53,3 +53,3 @@ urlObj.resource = resource; | ||
} | ||
else if (path=="." || path=="..") | ||
else if (path==="." || path==="..") | ||
{ | ||
@@ -79,3 +79,3 @@ // "..?var", "..#anchor", etc ... not "..index.html" | ||
// TWEAK :: condition only for speed optimization | ||
if (path != "/") | ||
if (path !== "/") | ||
{ | ||
@@ -87,3 +87,3 @@ var cleaned = []; | ||
// Cleanup -- splitting "/dir/" becomes ["","dir",""] | ||
if (dir != "") | ||
if (dir !== "") | ||
{ | ||
@@ -90,0 +90,0 @@ cleaned.push(dir); |
@@ -9,3 +9,3 @@ "use strict"; | ||
{ | ||
if ( i==urlObj.scheme && options.defaultPorts.hasOwnProperty(i) ) | ||
if ( i===urlObj.scheme && options.defaultPorts.hasOwnProperty(i) ) | ||
{ | ||
@@ -19,3 +19,6 @@ defaultPort = options.defaultPorts[i]; | ||
{ | ||
if (urlObj.port == null) | ||
// Force same type as urlObj.port | ||
defaultPort = defaultPort.toString(); | ||
if (urlObj.port === null) | ||
{ | ||
@@ -25,3 +28,3 @@ urlObj.port = defaultPort; | ||
urlObj.extra.portIsDefault = (urlObj.port == defaultPort); | ||
urlObj.extra.portIsDefault = (urlObj.port === defaultPort); | ||
} | ||
@@ -28,0 +31,0 @@ } |
@@ -23,13 +23,13 @@ "use strict"; | ||
{ | ||
if ( i!="" && queryObj.hasOwnProperty(i) ) | ||
if ( i!=="" && queryObj.hasOwnProperty(i) ) | ||
{ | ||
var value = queryObj[i]; | ||
if (value != "" || !removeEmptyQueries) | ||
if (value !== "" || !removeEmptyQueries) | ||
{ | ||
str += (++count==1) ? "?" : "&"; | ||
str += (++count===1) ? "?" : "&"; | ||
i = encodeURIComponent(i); | ||
if (value != "") | ||
if (value !== "") | ||
{ | ||
@@ -36,0 +36,0 @@ str += i +"="+ encodeURIComponent(value).replace(/%20/g,"+"); |
@@ -26,3 +26,3 @@ "use strict"; | ||
// Remove ":" suffix | ||
if (scheme.indexOf(":") == scheme.length-1) | ||
if (scheme.indexOf(":") === scheme.length-1) | ||
{ | ||
@@ -74,3 +74,3 @@ scheme = scheme.substr(0, scheme.length-1); | ||
separatorOnlyQuery: urlObj.search=="?" | ||
separatorOnlyQuery: urlObj.search==="?" | ||
}, | ||
@@ -123,3 +123,3 @@ portIsDefault: null, | ||
{ | ||
valid = !(url.indexOf(rejectedScheme+":") == 0); | ||
valid = !(url.indexOf(rejectedScheme+":") === 0); | ||
@@ -126,0 +126,0 @@ // Break loop |
@@ -45,3 +45,3 @@ "use strict"; | ||
// If is relative path | ||
if (urlObj.extra.hrefInfo.minimumPathOnly && urlObj.path.absolute.string.indexOf("/")!=0) | ||
if (urlObj.extra.hrefInfo.minimumPathOnly && urlObj.path.absolute.string.indexOf("/")!==0) | ||
{ | ||
@@ -48,0 +48,0 @@ // Append path to site path |
@@ -9,13 +9,13 @@ "use strict"; | ||
// Matching scheme, scheme-relative or path-only | ||
var minimumScheme = (urlObj.scheme==siteUrlObj.scheme || !urlObj.scheme); | ||
var minimumScheme = (urlObj.scheme===siteUrlObj.scheme || !urlObj.scheme); | ||
// Matching auth, ignoring auth or path-only | ||
var minimumAuth = minimumScheme && (urlObj.auth==siteUrlObj.auth || options.removeAuth || pathOnly); | ||
var minimumAuth = minimumScheme && (urlObj.auth===siteUrlObj.auth || options.removeAuth || pathOnly); | ||
// Matching host or path-only | ||
var www = options.ignore_www ? "stripped" : "full"; | ||
var minimumHost = minimumAuth && (urlObj.host[www]==siteUrlObj.host[www] || pathOnly); | ||
var minimumHost = minimumAuth && (urlObj.host[www]===siteUrlObj.host[www] || pathOnly); | ||
// Matching port or path-only | ||
var minimumPort = minimumHost && (urlObj.port==siteUrlObj.port || pathOnly); | ||
var minimumPort = minimumHost && (urlObj.port===siteUrlObj.port || pathOnly); | ||
@@ -45,6 +45,6 @@ urlObj.extra.relation.minimumScheme = minimumScheme; | ||
// Matching port and path | ||
var minimumPath = minimumPort && urlObj.path.absolute.string==siteUrlObj.path.absolute.string; | ||
var minimumPath = minimumPort && urlObj.path.absolute.string===siteUrlObj.path.absolute.string; | ||
// Matching resource or query/hash-only or empty | ||
var matchingResource = (urlObj.resource==siteUrlObj.resource || !urlObj.resource && siteUrlObj.extra.resourceIsIndex) || (options.removeDirectoryIndexes && urlObj.extra.resourceIsIndex && !siteUrlObj.resource); | ||
var matchingResource = (urlObj.resource===siteUrlObj.resource || !urlObj.resource && siteUrlObj.extra.resourceIsIndex) || (options.removeDirectoryIndexes && urlObj.extra.resourceIsIndex && !siteUrlObj.resource); | ||
var minimumResource = minimumPath && (matchingResource || queryOnly || hashOnly || empty); | ||
@@ -56,5 +56,5 @@ | ||
var siteUrlQuery = siteUrlObj.query.string[query]; | ||
var minimumQuery = (minimumResource && !!urlQuery && urlQuery==siteUrlQuery) || ((hashOnly || empty) && !urlObj.extra.hrefInfo.separatorOnlyQuery); | ||
var minimumQuery = (minimumResource && !!urlQuery && urlQuery===siteUrlQuery) || ((hashOnly || empty) && !urlObj.extra.hrefInfo.separatorOnlyQuery); | ||
var minimumHash = minimumQuery && urlObj.hash==siteUrlObj.hash; | ||
var minimumHash = minimumQuery && urlObj.hash===siteUrlObj.hash; | ||
@@ -61,0 +61,0 @@ urlObj.extra.relation.minimumPath = minimumPath; |
@@ -23,3 +23,3 @@ "use strict"; | ||
{ | ||
if (absolutePath[i] != siteAbsoluteDir) | ||
if (absolutePath[i] !== siteAbsoluteDir) | ||
{ | ||
@@ -26,0 +26,0 @@ related = false; |
@@ -28,5 +28,8 @@ "use strict"; | ||
function isObject(obj) | ||
/* | ||
https://github.com/jonschlinkert/is-plain-object | ||
*/ | ||
function isPlainObject(obj) | ||
{ | ||
return obj instanceof Object && !(obj instanceof Array); | ||
return !!obj && typeof obj==="object" && obj.constructor===Object; | ||
} | ||
@@ -39,11 +42,11 @@ | ||
*/ | ||
function shallowMerge(source, obj, type) | ||
function shallowMerge(target, source) | ||
{ | ||
if (source instanceof Object && obj instanceof Object) | ||
if (target instanceof Object && source instanceof Object) | ||
{ | ||
for (var i in obj) | ||
for (var i in source) | ||
{ | ||
if ( obj.hasOwnProperty(i) ) | ||
if ( source.hasOwnProperty(i) ) | ||
{ | ||
source[i] = obj[i]; | ||
target[i] = source[i]; | ||
} | ||
@@ -53,3 +56,3 @@ } | ||
return source; | ||
return target; | ||
} | ||
@@ -62,4 +65,4 @@ | ||
clone: clone, | ||
isObject: isObject, | ||
isPlainObject: isPlainObject, | ||
shallowMerge: shallowMerge | ||
}; |
@@ -23,5 +23,5 @@ "use strict"; | ||
{ | ||
if (dir != "..") | ||
if (dir !== "..") | ||
{ | ||
if (dir != ".") | ||
if (dir !== ".") | ||
{ | ||
@@ -28,0 +28,0 @@ pathAbsolute.push(dir); |
{ | ||
"name": "relateurl", | ||
"description": "Minify URLs by converting them from absolute to relative.", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"homepage": "https://github.com/stevenvachon/relateurl", | ||
@@ -19,7 +19,13 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/stevenvachon/relateurl/blob/master/LICENSE" | ||
} | ||
], | ||
"devDependencies": { | ||
"browserify": "^5.9", | ||
"chai": "^1.9", | ||
"mocha": "^1.21", | ||
"uglify-js": "^2.4" | ||
"browserify": "^7.0.1", | ||
"chai": "^1.10", | ||
"mocha": "^2.0.1", | ||
"uglify-js": "^2.4.16" | ||
}, | ||
@@ -37,2 +43,3 @@ "engines": { | ||
"keywords": [ | ||
"uri", | ||
"url", | ||
@@ -39,0 +46,0 @@ "minifier", |
@@ -135,2 +135,3 @@ # relateurl [![NPM Version](http://badge.fury.io/js/relateurl.svg)](http://badge.fury.io/js/relateurl) [![Build Status](https://secure.travis-ci.org/stevenvachon/relateurl.svg)](http://travis-ci.org/stevenvachon/relateurl) | ||
## Release History | ||
* 0.2.6 minor enhancements | ||
* 0.2.5 added `options.removeRootTrailingSlash` | ||
@@ -145,3 +146,4 @@ * 0.2.4 added `options.site` | ||
## Roadmap | ||
* 0.2.6 decipher and return invalid input (special cases) to complete test suite | ||
* 0.2.7 possible [scheme exclusions](http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml) such as `tel:` | ||
* 0.2.7 decipher and return invalid input (special cases) to complete test suite | ||
* 0.3.0 test `options.slashesDenoteHost=false`, add something like `options.externalDirectoryIndexes=[]` for external sites | ||
@@ -151,2 +153,2 @@ | ||
[![Analytics](https://ga-beacon.appspot.com/UA-3614308-13/stevenvachon/relateurl)](https://github.com/igrigorik/ga-beacon "Google Analytics") [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/stevenvachon/relateurl/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
[![Analytics](https://ga-beacon.appspot.com/UA-3614308-13/stevenvachon/relateurl)](https://github.com/igrigorik/ga-beacon "Google Analytics") |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
0
152
31171
21
866
1