json-schema-ref-parser
Advanced tools
Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.8
'use strict'; | ||
var path = require('path'), | ||
url = require('url'), | ||
util = require('./util'), | ||
_isString = require('lodash/lang/isString'), | ||
isWindows = /^win/.test(process.platform); | ||
var path = require('path'), | ||
url = require('url'), | ||
util = require('./util'), | ||
_isString = require('lodash/lang/isString'), | ||
isWindows = /^win/.test(process.platform), | ||
protocolPattern = /^[a-z0-9.+-]{2,}:/i; | ||
@@ -93,20 +94,31 @@ module.exports = PathOrUrl; | ||
// PathOrUrl objects are always absolute, so just return it as-is | ||
resolved = relative.format(); | ||
return relative.format(); | ||
} | ||
else if (this.isUrl || relative instanceof url.Url) { | ||
// Resolve as a URL | ||
relative = url.parse(relative); | ||
util.debug('Resolving path "%s", relative to "%s"', relative.href, this); | ||
var selfUrl = this.toUrl(); | ||
resolved = selfUrl.resolve(relative); | ||
util.debug(' Resolved to %s', resolved); | ||
if (relative instanceof url.Url) { | ||
// Urls can be absolute or relative, so treat it like a string | ||
relative = relative.format(); | ||
} | ||
util.debug('Resolving path "%s", relative to "%s"', relative, this); | ||
if (this.isUrl || protocolPattern.test(relative)) { | ||
// The result will be a URL if `relative` is any of: | ||
// - an absolute url (e.g. "http://www.google.com") | ||
// - a relative url (e.g. "../path/file.html") | ||
// - an absolute POSIX path (e.g. "/path/file") | ||
// - a relative POSIX path (e.g. "path/file") | ||
// - a relative Windows path (e.g. "path\\file.txt") | ||
// | ||
// The result will be a file path if `relative` is: | ||
// - an absolute Windows path (e.g. "C:\\path\\file.txt") | ||
resolved = url.resolve(this.format(), relative); | ||
} | ||
else { | ||
// Resolve as a file path | ||
util.debug('Resolving path "%s", relative to "%s"', relative, this); | ||
// The result will always be a file path | ||
var parsed = parseRelativeFile({}, this, relative, options); | ||
resolved = PathOrUrl.prototype.format.call(parsed); | ||
util.debug(' Resolved to %s', resolved); | ||
} | ||
util.debug(' Resolved to %s', resolved); | ||
return resolved; | ||
@@ -235,12 +247,9 @@ }; | ||
} | ||
else if (protocolPattern.test(href)) { | ||
// It's a full URL (e.g. https://host.com) | ||
parseUrl(this, url.parse(href)); | ||
} | ||
else { | ||
var u = url.parse(href); | ||
if (u.protocol) { | ||
// It's a full URL (e.g. https://host.com) | ||
parseUrl(this, u); | ||
} | ||
else { | ||
// It's a relative file path | ||
parseRelativeFile(this, PathOrUrl.cwd(), href, options); | ||
} | ||
// It's a relative file path | ||
parseRelativeFile(this, PathOrUrl.cwd(), href, options); | ||
} | ||
@@ -402,8 +411,9 @@ }; | ||
} | ||
else if (isWindows && dir.substr(1, 2) === ':\\') { | ||
var delimiter = dir.substr(1, 2); | ||
if (isWindows && (delimiter === ':\\' || delimiter === ':/')) { | ||
return dir.substr(0, 3); | ||
} | ||
else { | ||
return ''; | ||
} | ||
return ''; | ||
} |
{ | ||
"name": "json-schema-ref-parser", | ||
"version": "1.0.0-alpha.7", | ||
"version": "1.0.0-alpha.8", | ||
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2698153
21102