Comparing version 3.0.2 to 3.0.3
@@ -70,3 +70,3 @@ 'use strict'; | ||
} | ||
function _get(path, scope) { | ||
function _getPointer(path, scope) { | ||
if (path === '#' && !scope) { | ||
@@ -86,3 +86,3 @@ return _root; | ||
if (data) { | ||
return Promise.resolve(pointer(data, uri.hash.slice(i))); | ||
return Promise.resolve({ data: data, path: uri.hash.slice(i) }); | ||
} else { | ||
@@ -92,3 +92,3 @@ return _retriever(uri.url).then(function (data) { | ||
return _parse(data, uri.url).then(function (data) { | ||
return pointer(data, uri.hash); | ||
return { data: data, path: uri.hash }; | ||
}); | ||
@@ -99,2 +99,7 @@ }); | ||
} | ||
function _get(path, scope) { | ||
return _getPointer(path, scope).then(function (res) { | ||
return pointer(res.data, res.path); | ||
}); | ||
} | ||
function _parse(data, scope) { | ||
@@ -128,4 +133,13 @@ _root = data; | ||
return p.then(function () { | ||
return _get(ref, _scope).then(function (derefData) { | ||
data[key] = derefData; | ||
return _getPointer(ref, _scope).then(function (derefPointer) { | ||
Object.defineProperty(data, key, { | ||
get: function get() { | ||
return pointer(derefPointer.data, derefPointer.path); | ||
}, | ||
set: function set(v) { | ||
return pointer(derefPointer.data, derefPointer.path); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return true; | ||
@@ -132,0 +146,0 @@ }); |
{ | ||
"name": "jsonref", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Javascript References ($ref) and Pointers library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -83,3 +83,5 @@ # jsonref | ||
````javascript | ||
parse({ | ||
var jsonref = require('jsonref'); | ||
var schema = { | ||
"id": "http://my.site/myschema#", | ||
@@ -96,4 +98,6 @@ "definitions": { | ||
} | ||
}).then(function(data) { | ||
console.log(JSON.stringify(data, null, 2)); | ||
} | ||
jsonref.parse(schema).then(function(result) { | ||
console.log(JSON.stringify(result, null, 2)); | ||
}); | ||
@@ -126,3 +130,5 @@ ```` | ||
```javascript | ||
parse({ | ||
var jsonref = require('jsonref'); | ||
var schema = { | ||
"allOf": [ | ||
@@ -139,6 +145,8 @@ { "$ref": "http://json-schema.org/draft-04/schema#" }, | ||
] | ||
}, null, { | ||
} | ||
jsonref.parse(schema, { | ||
retriever: retriever | ||
}).then(function(data) { | ||
console.log(JSON.stringify(data, null, 2)); | ||
}).then(function(result) { | ||
console.log(JSON.stringify(result, null, 2)); | ||
}); | ||
@@ -154,5 +162,6 @@ ``` | ||
```javascript | ||
var jsonref = require('jsonref'); | ||
var store = {}; | ||
parse({ | ||
var schema = { | ||
"id": "http://my.site/myschema#", | ||
@@ -169,6 +178,8 @@ "definitions": { | ||
} | ||
}, null, { | ||
} | ||
jsonref.parse(schema, { | ||
store: store | ||
}).then(function(data) { | ||
console.log(JSON.stringify(store, null, 2)); | ||
}).then(function(result) { | ||
console.log(JSON.stringify(result, null, 2)); | ||
}); | ||
@@ -175,0 +186,0 @@ ``` |
@@ -55,3 +55,3 @@ import url from 'url'; | ||
} | ||
function _get(path, scope) { | ||
function _getPointer(path, scope) { | ||
if (path === '#' && !scope) { | ||
@@ -63,3 +63,3 @@ return _root; | ||
for (var i = uri.hash.length, k ; !data && i > 0 ; i--) { | ||
k = uri.url + uri.hash.slice(0, i).join('/') | ||
k = uri.url + uri.hash.slice(0, i).join('/'); | ||
if (k === '#') { | ||
@@ -72,3 +72,3 @@ data = _root; | ||
if (data) { | ||
return Promise.resolve(pointer(data, uri.hash.slice(i))); | ||
return Promise.resolve({ data: data, path: uri.hash.slice(i) }); | ||
} else { | ||
@@ -78,3 +78,3 @@ return _retriever(uri.url).then(function(data) { | ||
return _parse(data, uri.url).then(function(data) { | ||
return pointer(data, uri.hash); | ||
return { data: data, path: uri.hash }; | ||
}); | ||
@@ -85,2 +85,7 @@ }); | ||
} | ||
function _get(path, scope) { | ||
return _getPointer(path, scope).then(function(res) { | ||
return pointer(res.data, res.path); | ||
}); | ||
} | ||
function _parse(data, scope) { | ||
@@ -120,4 +125,13 @@ _root = data; | ||
return p.then(function() { | ||
return _get(ref, _scope).then(function(derefData) { | ||
data[key] = derefData; | ||
return _getPointer(ref, _scope).then(function(derefPointer) { | ||
Object.defineProperty(data, key, { | ||
get: function() { | ||
return pointer(derefPointer.data, derefPointer.path); | ||
}, | ||
set: function(v) { | ||
return pointer(derefPointer.data, derefPointer.path); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return true; | ||
@@ -124,0 +138,0 @@ }); |
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
108585
330
208