@imghop/core
Advanced tools
Comparing version 0.0.6-alpha.0 to 0.0.7-alpha.0
@@ -47,2 +47,12 @@ 'use strict'; | ||
if (params.width) { | ||
params.w = params.width; | ||
delete params.width; | ||
} | ||
if (params.height) { | ||
params.h = params.height; | ||
delete params.height; | ||
} | ||
if (params.quality !== undefined && (!params.format || !supportsQuality(params.format))) { | ||
@@ -49,0 +59,0 @@ delete params.quality; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("qs")),t=e(require("cross-fetch"));function o(){return(o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}exports.queryHelper=function(e,t){if(!e.startsWith("https://hop.imghop.dev/"))return e;var n,i=e.split("?"),a=i[0],u=i[1],p=r.parse(t);u&&(p=o({},r.parse(u),p)),void 0===p.quality||p.format&&("jpeg"===(n=p.format)||"webp"===n)||delete p.quality;var s=r.stringify(p);return s?a+"?"+s:a},exports.uploadImage=function(e){if(!e.apiKey)throw new Error("You need to provide an API-Key");if(!e.image)throw new Error("You need to provide an Image");var r;return(r=e.apiKey,function(e,n){return t("https://imghop.dev/api"+e,o({},n,{headers:{Authorization:r}}))})("/upload",{body:e.image,method:"PUT"}).then((function(e){return e.json()})).then((function(e){return e.url}))}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("qs")),r=e(require("cross-fetch"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}exports.queryHelper=function(e,r){if(!e.startsWith("https://hop.imghop.dev/"))return e;var i,n=e.split("?"),a=n[0],u=n[1],p=t.parse(r);u&&(p=o({},t.parse(u),p)),p.width&&(p.w=p.width,delete p.width),p.height&&(p.h=p.height,delete p.height),void 0===p.quality||p.format&&("jpeg"===(i=p.format)||"webp"===i)||delete p.quality;var h=t.stringify(p);return h?a+"?"+h:a},exports.uploadImage=function(e){if(!e.apiKey)throw new Error("You need to provide an API-Key");if(!e.image)throw new Error("You need to provide an Image");var t;return(t=e.apiKey,function(e,i){return r("https://imghop.dev/api"+e,o({},i,{headers:{Authorization:t}}))})("/upload",{body:e.image,method:"PUT"}).then((function(e){return e.json()})).then((function(e){return e.url}))}; | ||
//# sourceMappingURL=core.cjs.production.min.js.map |
@@ -41,2 +41,12 @@ import qs from 'qs'; | ||
if (params.width) { | ||
params.w = params.width; | ||
delete params.width; | ||
} | ||
if (params.height) { | ||
params.h = params.height; | ||
delete params.height; | ||
} | ||
if (params.quality !== undefined && (!params.format || !supportsQuality(params.format))) { | ||
@@ -43,0 +53,0 @@ delete params.quality; |
{ | ||
"version": "0.0.6-alpha.0", | ||
"version": "0.0.7-alpha.0", | ||
"license": "MIT", | ||
@@ -62,3 +62,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "3d35b9a41a47e8940c57e9af8de1c5c9cc70a1d3" | ||
"gitHead": "a3aee4234236391d4dcbcd02278603f035849e4c" | ||
} |
@@ -11,6 +11,13 @@ import { CDN_NAME, SUPPORTED_TYPES, supportsQuality } from './constants'; | ||
interface HttpQueryParams { | ||
w?: number; | ||
h?: number; | ||
q?: number; | ||
format?: SUPPORTED_TYPES; | ||
} | ||
export function queryHelper(url: string, options: QueryOptions) { | ||
if (!url.startsWith(CDN_NAME)) return url; | ||
const [plainUrl, currentQueryParams] = url.split('?'); | ||
let params = qs.parse(options as any) as QueryOptions; | ||
let params = qs.parse(options as any) as HttpQueryParams & QueryOptions; | ||
if (currentQueryParams) { | ||
@@ -20,3 +27,10 @@ const parsedParams = qs.parse(currentQueryParams); | ||
} | ||
if (params.width) { | ||
params.w = params.width; | ||
delete params.width; | ||
} | ||
if (params.height) { | ||
params.h = params.height; | ||
delete params.height; | ||
} | ||
if ( | ||
@@ -23,0 +37,0 @@ params.quality !== undefined && |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26830
254