Comparing version 3.0.4 to 3.1.0
@@ -8,5 +8,8 @@ 'use strict'; | ||
}); | ||
exports.resolveUri = resolveUri; | ||
exports.normalizeUri = normalizeUri; | ||
exports.pointer = pointer; | ||
exports.scope = scope; | ||
exports.parse = parse; | ||
exports.normalize = normalize; | ||
@@ -25,2 +28,22 @@ var _url = require('url'); | ||
function resolveUri(path, scope) { | ||
var resolvedPath = _url2.default.resolve(scope || '', path || ''); | ||
var parsedPath = _url2.default.parse(resolvedPath); | ||
var hash = parsedPath.hash; | ||
delete parsedPath.hash; | ||
var out = { | ||
url: _url2.default.format(parsedPath) | ||
}; | ||
if (hash) { | ||
out.hash = hash.split('/'); | ||
} else { | ||
out.hash = ['#']; | ||
} | ||
return out; | ||
} | ||
function normalizeUri(path, scope, omitEmptyFragment) { | ||
var uri = resolveUri(path, scope); | ||
var hash = uri.hash.join('/'); | ||
return uri.url + (!omitEmptyFragment || hash !== '#' ? hash : ''); | ||
} | ||
function pointer(data, path) { | ||
@@ -48,23 +71,4 @@ var _data = data; | ||
var _root; | ||
function _resolve(path, scope) { | ||
var resolvedPath = _url2.default.resolve(scope || '', path || ''); | ||
var parsedPath = _url2.default.parse(resolvedPath); | ||
var hash = parsedPath.hash; | ||
delete parsedPath.hash; | ||
var out = { | ||
url: _url2.default.format(parsedPath) | ||
}; | ||
if (hash) { | ||
out.hash = hash.split('/'); | ||
} else { | ||
out.hash = ['#']; | ||
} | ||
return out; | ||
} | ||
function _normalize(path, scope) { | ||
var uri = _resolve(path, scope); | ||
return uri.url + uri.hash.join('/'); | ||
} | ||
function _register(path, scope, data) { | ||
var resolved = _normalize(path, scope); | ||
var resolved = normalizeUri(path, scope); | ||
_store[resolved] = data; | ||
@@ -77,3 +81,3 @@ return resolved; | ||
} else { | ||
var uri = _resolve(path, scope); | ||
var uri = resolveUri(path, scope); | ||
var data; | ||
@@ -108,3 +112,3 @@ for (var i = uri.hash.length, k; !data && i > 0; i--) { | ||
if (scope) { | ||
scope = _normalize(null, scope); | ||
scope = normalizeUri(null, scope); | ||
_register(null, scope, data); | ||
@@ -184,2 +188,26 @@ } | ||
} | ||
function normalize(data, scope) { | ||
if (scope) { | ||
scope = normalizeUri(null, scope); | ||
} | ||
if ((typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') { | ||
var _scope, i, o; | ||
if (typeof data.id === 'string') { | ||
_scope = normalizeUri(data.id, scope); | ||
} else { | ||
_scope = scope || '#'; | ||
} | ||
for (i in data) { | ||
o = data[i]; | ||
if ((typeof o === 'undefined' ? 'undefined' : _typeof(o)) === 'object') { | ||
if (isRef(o)) { | ||
o.$ref = normalizeUri(o.$ref, _scope, true); | ||
} else { | ||
normalize(o, _scope + '/' + i); | ||
} | ||
} | ||
} | ||
} | ||
return data; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "jsonref", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "Javascript References ($ref) and Pointers library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,2 +9,22 @@ import url from 'url'; | ||
export function resolveUri(path, scope) { | ||
var resolvedPath = url.resolve(scope || '', path || ''); | ||
var parsedPath = url.parse(resolvedPath); | ||
var hash = parsedPath.hash; | ||
delete parsedPath.hash; | ||
var out = { | ||
url: url.format(parsedPath) | ||
}; | ||
if (hash) { | ||
out.hash = hash.split('/'); | ||
} else { | ||
out.hash = ['#']; | ||
} | ||
return out; | ||
} | ||
export function normalizeUri(path, scope, omitEmptyFragment) { | ||
var uri = resolveUri(path, scope); | ||
var hash = uri.hash.join('/') | ||
return uri.url + (!omitEmptyFragment || hash !== '#' ? hash : ''); | ||
} | ||
export function pointer(data, path) { | ||
@@ -32,23 +52,4 @@ var _data = data; | ||
var _root; | ||
function _resolve(path, scope) { | ||
var resolvedPath = url.resolve(scope || '', path || ''); | ||
var parsedPath = url.parse(resolvedPath); | ||
var hash = parsedPath.hash; | ||
delete parsedPath.hash; | ||
var out = { | ||
url: url.format(parsedPath) | ||
}; | ||
if (hash) { | ||
out.hash = hash.split('/'); | ||
} else { | ||
out.hash = ['#']; | ||
} | ||
return out; | ||
} | ||
function _normalize(path, scope) { | ||
var uri = _resolve(path, scope); | ||
return uri.url + uri.hash.join('/'); | ||
} | ||
function _register(path, scope, data) { | ||
var resolved = _normalize(path, scope); | ||
var resolved = normalizeUri(path, scope); | ||
_store[resolved] = data; | ||
@@ -61,3 +62,3 @@ return resolved; | ||
} else { | ||
var uri = _resolve(path, scope); | ||
var uri = resolveUri(path, scope); | ||
var data; | ||
@@ -92,3 +93,3 @@ for (var i = uri.hash.length, k ; !data && i > 0 ; i--) { | ||
if (scope) { | ||
scope = _normalize(null, scope); | ||
scope = normalizeUri(null, scope); | ||
_register(null, scope, data); | ||
@@ -165,1 +166,25 @@ } | ||
} | ||
export function normalize(data, scope) { | ||
if (scope) { | ||
scope = normalizeUri(null, scope); | ||
} | ||
if (typeof data === 'object') { | ||
var _scope, i, o; | ||
if (typeof data.id === 'string') { | ||
_scope = normalizeUri(data.id, scope); | ||
} else { | ||
_scope = scope || '#'; | ||
} | ||
for (i in data) { | ||
o = data[i]; | ||
if (typeof o === 'object') { | ||
if (isRef(o)) { | ||
o.$ref = normalizeUri(o.$ref, _scope, true); | ||
} else { | ||
normalize(o, _scope + '/' + i); | ||
} | ||
} | ||
} | ||
} | ||
return data; | ||
} |
Sorry, the diff of this file is not supported yet
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
96208
375