Socket
Socket
Sign inDemoInstall

@hyperjump/browser

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyperjump/browser - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

json-reference/.index.js.swo

72

json-reference/index.js
const JsonPointer = require("@hyperjump/json-pointer");
const curry = require("just-curry-it");
const Promise = require("bluebird");
const Hyperjump = require("..");
const Json = require("../json");

@@ -33,4 +31,4 @@

const nil = Json.nil;
const source = Json.source;
const nil = Hyperjump.nil;
const source = Hyperjump.source;

@@ -43,32 +41,47 @@ const get = curry(async (url, doc, options = {}) => {

const value = (doc) => JsonPointer.get(pointer(doc), doc.jref);
const value = (subject) => {
if (isDocument(subject)) {
const doc = subject;
return JsonPointer.get(pointer(doc), doc.jref);
} else {
return subject;
}
};
const pointer = (doc) => decodeURIComponent(uriFragment(doc.url));
const entries = (doc, options = {}) => {
const items = Object.keys(value(doc))
.map(async (key) => {
const url = append(key, doc);
return [key, await get(url, doc, options)];
});
return Promise.all(items);
const entries = (subject, options = {}) => {
if (isDocument(subject)) {
return Promise.all(Object.keys(value(subject))
.map(async (key) => {
const url = append(key, subject);
return [key, await get(url, subject, options)];
}));
} else {
return Object.entries(subject);
}
};
const map = curry((fn, doc, options = {}) => {
const items = Object.keys(value(doc))
.map((key) => {
const url = append(key, doc);
return get(url, doc, options);
});
const map = curry(async (fn, subject, options = {}) => {
const list = (await entries(subject, options))
.map(([_key, item]) => fn(item));
return Promise.map(items, fn);
return Promise.all(list);
});
const pipeline = (fns) => {
const [handler = identity, ...handlers] = fns;
return (...args) => Promise.resolve(handler(...args))
.then(data => Promise.reduce(handlers, (acc, fn) => fn(acc), data));
};
const filter = curry(async (fn, subject, options = {}) => {
return reduce(async (acc, item) => {
return (await fn(item)) ? acc.concat(item) : acc;
}, [], subject, options);
});
const reduce = curry(async (fn, acc, subject, options = {}) => {
return (await entries(subject, options))
.reduce(async (acc, [_key, item]) => fn(await acc, item), acc);
});
const pipeline = curry((fns, subject) => {
return fns.reduce(async (acc, fn) => fn(await acc), subject);
});
const uriFragment = (url) => url.split("#", 2)[1] || "";

@@ -79,4 +92,7 @@ const uriReference = (url) => url.split("#", 1)[0];

const isId = (value) => isObject(value) && "$embedded" in value;
const append = (key, doc) => "#" + encodeURI(JsonPointer.append(key, pointer(doc))).replace(/#/g, "%23");
const identity = (a) => a;
const isDocument = (value) => isObject(value) && "url" in value;
const append = (key, doc) => {
const ptr = JsonPointer.append(key, pointer(doc));
return "#" + encodeURI(ptr).replace(/#/g, "%23");
};

@@ -86,3 +102,3 @@ module.exports = {

nil, source, get,
value, pointer, entries, map, pipeline
value, pointer, entries, map, filter, reduce, pipeline
};
{
"name": "@hyperjump/browser",
"version": "0.10.0",
"version": "0.11.0",
"description": "A generic hypermedia client for JSON Reference",

@@ -8,3 +8,3 @@ "scripts": {

"lint": "eslint .",
"test": "mocha '{,!(node_modules)}/*.spec.js'"
"test": "mocha './{,!(node_modules)}/*.spec.js'"
},

@@ -30,3 +30,2 @@ "repository": "github:jdesrosiers/hyperjump-browser",

"@hyperjump/json-pointer": "^0.3.1",
"bluebird": "^3.5.3",
"just-curry-it": "^3.1.0",

@@ -33,0 +32,0 @@ "make-fetch-happen": "^4.0.1"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc