@hyperjump/browser
Advanced tools
Comparing version 0.7.0 to 0.8.0
const JsonPointer = require("@hyperjump/json-pointer"); | ||
const curry = require("just-curry-it"); | ||
const Promise = require("bluebird"); | ||
@@ -29,9 +30,9 @@ const Hyperjump = require(".."); | ||
const get = async (url, doc = nil, options = {}) => { | ||
const get = curry(async (url, doc, options = {}) => { | ||
const defaultHeaders = { "Accept": "application/reference+json" }; | ||
options.headers = { ...defaultHeaders, ...options.headers }; | ||
return await Hyperjump.get(url, doc, options); | ||
}; | ||
}); | ||
const value = (doc) => JsonPointer.get(pointer(doc))(Json.value(doc)); | ||
const value = (doc) => JsonPointer.get(pointer(doc), Json.value(doc)); | ||
@@ -43,3 +44,3 @@ const pointer = (doc) => decodeURIComponent(uriFragment(doc.url)); | ||
.map(async (key) => { | ||
const url = append(doc, key); | ||
const url = append(key, doc); | ||
return [key, await get(url, doc, options)]; | ||
@@ -51,6 +52,6 @@ }); | ||
const map = (fn, doc, options = {}) => { | ||
const map = curry((fn, doc, options = {}) => { | ||
const items = Object.keys(value(doc)) | ||
.map((key) => { | ||
const url = append(doc, key); | ||
const url = append(key, doc); | ||
return get(url, doc, options); | ||
@@ -60,3 +61,3 @@ }); | ||
return Promise.map(items, fn); | ||
}; | ||
}); | ||
@@ -67,4 +68,4 @@ const uriFragment = (url) => url.split("#", 2)[1] || ""; | ||
const isId = (value) => isObject(value) && "$id" in value; | ||
const append = (doc, key) => "#" + encodeURI(JsonPointer.append(pointer(doc), key)); | ||
const append = (key, doc) => "#" + encodeURI(JsonPointer.append(key, pointer(doc))); | ||
module.exports = { contentType, contentTypeHandler, get, nil, source, value, pointer, entries, map }; |
{ | ||
"name": "@hyperjump/browser", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "A generic hypermedia client for JSON Reference", | ||
@@ -28,6 +28,7 @@ "scripts": { | ||
"dependencies": { | ||
"@hyperjump/json-pointer": "^0.2.2", | ||
"@hyperjump/json-pointer": "^0.3.0", | ||
"bluebird": "^3.5.3", | ||
"just-curry-it": "^3.1.0", | ||
"make-fetch-happen": "^4.0.1" | ||
} | ||
} |
@@ -76,3 +76,3 @@ Hyperjump Browser | ||
// Get a document by absolute URL | ||
const doc = await JRef.get("http://json-reference.hyperjump.io/example1"); | ||
const doc = await JRef.get("http://json-reference.hyperjump.io/example1", JRef.nil); | ||
@@ -89,7 +89,7 @@ // Get a document with a relative URL using another document as the context | ||
// Map over a document whose value is an array | ||
const eee = JRef.get("#/eee"); | ||
const eee = JRef.get("#/eee", doc); | ||
const types = await JRef.map((item) => typeof JRef.value(item), eee); // => ["string", "number"]; | ||
// Get the key/value pairs of a document whose value is an object | ||
const ddd = JRef.get("#/ddd"); | ||
const ddd = JRef.get("#/ddd", doc); | ||
await JRef.entries(ddd); // => [ | ||
@@ -96,0 +96,0 @@ // ["111", JRef.get("#/ddd/111", doc)], |
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
12581
93
4
+ Addedjust-curry-it@^3.1.0
+ Added@hyperjump/json-pointer@0.3.1(transitive)
+ Addedjust-curry-it@3.2.1(transitive)
- Removed@hyperjump/json-pointer@0.2.2(transitive)