Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@technik-sde/foxy

Package Overview
Dependencies
Maintainers
43
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@technik-sde/foxy - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

3

dist/Foxy.d.ts

@@ -16,3 +16,4 @@ import Handler, { Request, Info } from "./handler/Handler";

get(methodName: string, request: Request): Promise<any>;
private findHandler;
isSupported(request: Request): boolean;
findHandler(methodName: string, request: Request): Handler;
}

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("foxy",[],t):"object"==typeof exports?exports.foxy=t():e.foxy=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";n.r(t),n.d(t,"Foxy",(function(){return r})),n.d(t,"handler",(function(){return u})),n.d(t,"utils",(function(){return o}));class r{constructor(e={}){this.handlers=e.handlers||[]}addHandler(e,t=0){null==this.handlers[t]&&this.handlers.push(e),this.handlers.splice(t,0,e)}removeHandler(e){this.handlers=this.handlers.filter(t=>t!==e)}getImageURL(e){return this.get("getImageURL",e)}getImageInfo(e){return this.get("getImageInfo",e)}getVideoURL(e){return this.get("getVideoURL",e)}getVideoInfo(e){return this.get("getVideoInfo",e)}getURL(e){return this.get("getURL",e)}get(e,t){const n=this.findHandler(e,t);if(null==n)throw new Error(`There is no handler for method '${e}(${JSON.stringify(t)})'`);return n[e](t)}findHandler(e,t){for(const n of this.handlers)if("function"==typeof n[e]&&!0===n.use(t))return n}}var o={loadImageInfo:function(e,t={}){const n={src:e,image:new Image,type:"",width:0,height:0};return fetch(e,t).then(e=>e.blob()).then(e=>(n.type=e.type.replace(/^[^/]+\//,""),URL.createObjectURL(e))).then(e=>new Promise((t,r)=>{n.image.addEventListener("load",()=>t()),n.image.addEventListener("error",r),n.image.src=e})).then(()=>(n.width=n.image.naturalWidth,n.height=n.image.naturalHeight,n))},loadVideoInfo:function(e,t={}){const n={src:e,width:0,height:0,video:document.createElement("video"),duration:0,poster:""};return fetch(e,t).then(e=>e.blob()).then(e=>(n.type=e.type.replace(/^[^/]+\//,""),URL.createObjectURL(e))).then(e=>new Promise((t,r)=>{n.video.addEventListener("error",r),n.video.addEventListener("loadedmetadata",()=>{const{video:e}=n;n.width=e.videoWidth,n.height=e.videoHeight,n.duration=e.duration,n.poster=e.poster,t(n)});const o=document.createElement("source");o.setAttribute("src",e),n.video.appendChild(o)}))},isHandler:function(e){return"[object Object]"===Object.prototype.toString.call(e)&&"function"==typeof e.use}};const i=/^https:\/\/images\.unsplash\.com\/photo-\d{13}-[0-9a-f]{12}/;function s(e){const t=e.url.replace(/\?.*$/,""),n=new URLSearchParams(e.url.replace(/^.*\?/,""));return e.width&&n.set("w",e.width),e.height&&n.set("h",e.height),e.quality&&n.set("q",e.quality),e.fit&&n.set("fit",e.fit),e.auto&&n.set("auto",e.auto),`${t}?${n.toString()}`}const u={unsplash:{use:e=>i.test(e.url),getImageURL:e=>Promise.resolve(s(e)),getImageInfo:e=>o.loadImageInfo(s(e))},image:{use:e=>/^https?:\/\//.test(e.url),getImageURL:e=>Promise.resolve(e.url),getImageInfo:e=>o.loadImageInfo(e.url)},video:{use:e=>/^https?:\/\//.test(e.url),getVideoURL:e=>Promise.resolve(e.url),getVideoInfo:e=>o.loadVideoInfo(e.url)}}}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("foxy",[],t):"object"==typeof exports?exports.foxy=t():e.foxy=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";n.r(t),n.d(t,"Foxy",(function(){return r})),n.d(t,"handler",(function(){return u})),n.d(t,"utils",(function(){return o}));class r{constructor(e={}){this.handlers=e.handlers||[]}addHandler(e,t=0){null==this.handlers[t]&&this.handlers.push(e),this.handlers.splice(t,0,e)}removeHandler(e){this.handlers=this.handlers.filter(t=>t!==e)}getImageURL(e){return this.get("getImageURL",e)}getImageInfo(e){return this.get("getImageInfo",e)}getVideoURL(e){return this.get("getVideoURL",e)}getVideoInfo(e){return this.get("getVideoInfo",e)}getURL(e){return this.get("getURL",e)}get(e,t){const n=this.findHandler(e,t);return null==n?Promise.reject(new Error(`There is no handler for method '${e}(${JSON.stringify(t)})'`)):n[e](t)}isSupported(e){return this.handlers.some(t=>t.use(e))}findHandler(e,t){return this.handlers.find(n=>"function"==typeof n[e]&&!0===n.use(t))}}var o={loadImageInfo:function(e,t={}){const n={src:e,image:new Image,type:"",width:0,height:0};return fetch(e,t).then(e=>e.blob()).then(e=>(n.type=e.type.replace(/^[^/]+\//,""),URL.createObjectURL(e))).then(e=>new Promise((t,r)=>{n.image.addEventListener("load",()=>t()),n.image.addEventListener("error",r),n.image.src=e})).then(()=>(n.width=n.image.naturalWidth,n.height=n.image.naturalHeight,n))},loadVideoInfo:function(e,t={}){const n={src:e,width:0,height:0,video:document.createElement("video"),duration:0,poster:""};return fetch(e,t).then(e=>e.blob()).then(e=>(n.type=e.type.replace(/^[^/]+\//,""),URL.createObjectURL(e))).then(e=>new Promise((t,r)=>{n.video.addEventListener("error",r),n.video.addEventListener("loadedmetadata",()=>{const{video:e}=n;n.width=e.videoWidth,n.height=e.videoHeight,n.duration=e.duration,n.poster=e.poster,t(n)});const o=document.createElement("source");o.setAttribute("src",e),n.video.appendChild(o)}))},isHandler:function(e){return"[object Object]"===Object.prototype.toString.call(e)&&"function"==typeof e.use}};const i=/^https:\/\/images\.unsplash\.com\/photo-\d{13}-[0-9a-f]{12}/;function s(e){const t=e.url.replace(/\?.*$/,""),n=new URLSearchParams(e.url.replace(/^.*\?/,""));return e.width&&n.set("w",e.width),e.height&&n.set("h",e.height),e.quality&&n.set("q",e.quality),e.fit&&n.set("fit",e.fit),e.auto&&n.set("auto",e.auto),`${t}?${n.toString()}`}const u={unsplash:{use:e=>i.test(e.url),getImageURL:e=>Promise.resolve(s(e)),getImageInfo:e=>o.loadImageInfo(s(e))},image:{use:e=>/^https?:\/\//.test(e.url),getImageURL:e=>Promise.resolve(e.url),getImageInfo:e=>o.loadImageInfo(e.url)},video:{use:e=>/^https?:\/\//.test(e.url),getVideoURL:e=>Promise.resolve(e.url),getVideoInfo:e=>o.loadVideoInfo(e.url)}}}])}));

@@ -7,4 +7,2 @@ import AnyObject from "../AnyObject";

export interface Info {
width: number;
height: number;
[p: string]: any;

@@ -11,0 +9,0 @@ }

{
"name": "@technik-sde/foxy",
"version": "0.2.0",
"version": "0.3.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/foxy.js",

@@ -50,3 +50,4 @@ import Handler, { Request, Info } from "./handler/Handler";

if (handler == null) {
throw new Error(`There is no handler for method '${methodName}(${JSON.stringify(request)})'`);
return Promise
.reject(new Error(`There is no handler for method '${methodName}(${JSON.stringify(request)})'`));
}

@@ -56,9 +57,10 @@ return handler[methodName](request);

private findHandler(methodName: string, request: Request): Handler {
for (const handler of this.handlers) {
if (typeof handler[methodName] === "function" && handler.use(request) === true) {
return handler;
}
}
isSupported(request: Request): boolean {
return this.handlers.some(handler => handler.use(request));
}
findHandler(methodName: string, request: Request): Handler {
return this.handlers
.find(handler => typeof handler[methodName] === "function" && handler.use(request) === true);
}
}

@@ -10,4 +10,2 @@ import AnyObject from "../AnyObject";

export interface Info {
width: number;
height: number;
[p: string]: any;

@@ -14,0 +12,0 @@ }

@@ -10,5 +10,7 @@ import "mocha";

it("should throw if no handler with 'methodName' is registered", () => {
it("should return error if no handler with 'methodName' is registered", async () => {
const foxy = new Foxy();
assert.throws(() => foxy.get("url", { url: "1234" }));
await foxy.get("url", { url: "1234" })
.then(() => assert.fail("promise should have aborted"))
.catch(e => assert.ok(e instanceof Error))
});

@@ -15,0 +17,0 @@

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