From ba2ec87b4047aa52a19fab11f6f5f38e6b137b5e Mon Sep 17 00:00:00 2001 From: imgix-git-robot Date: Fri, 13 Jan 2023 17:13:21 +0000 Subject: [PATCH] chore(release): 3.8.0 # [3.8.0](https://github.com/imgix/js-core/compare/v3.7.1...v3.8.0) (2023-01-13) ### Bug Fixes * apply custom encoder to base64 parameters ([3ca78e1](https://github.com/imgix/js-core/commit/3ca78e1f1c29062668a0035f7c74b70816b0e9a1)) ### Features * add optional key parameter to custom encoder when encoding k,v pairs ([1023ab1](https://github.com/imgix/js-core/commit/1023ab1cc86f95c35da0c5a4cdb54d082a71baf4)) [skip ci] --- dist/imgix-js-core.umd.js | 2 +- dist/index.cjs.js | 9 +++++---- dist/index.d.ts | 13 +++++++++++-- dist/index.esm.js | 9 +++++---- package.json | 2 +- src/constants.js | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/dist/imgix-js-core.umd.js b/dist/imgix-js-core.umd.js index 87781ca8..e1dc3dc8 100644 --- a/dist/imgix-js-core.umd.js +++ b/dist/imgix-js-core.umd.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ImgixClient=e()}(this,function(){"use strict";function e(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function s(n){for(var t=1;tt.length)&&(e=t.length);for(var r=0,n=new Array(e);r{let r={};return t.forEach((t,e)=>r[t]=e),r})(d),F=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,p=String.fromCharCode.bind(String),g="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(t,e=t=>t)=>new Uint8Array(Array.prototype.slice.call(t,0).map(e)),b=t=>t.replace(/=/g,"").replace(/[+\/]/g,t=>"+"==t?"-":"_"),v=t=>t.replace(/[^A-Za-z0-9\+\/]/g,"");var m=e=>{let r,n,o,i,a="";var t=e.length%3;for(let t=0;t>18&63]+d[r>>12&63]+d[r>>6&63]+d[63&r]}return t?a.slice(0,t-3)+"===".substring(t):a};const w=t?t=>btoa(t):a?t=>Buffer.from(t,"binary").toString("base64"):m,A=a?t=>Buffer.from(t).toString("base64"):r=>{var n=[];for(let t=0,e=r.length;te?b(A(t)):A(t),D=t=>{var e;return t.length<2?(e=t.charCodeAt(0))<128?t:e<2048?p(192|e>>>6)+p(128|63&e):p(224|e>>>12&15)+p(128|e>>>6&63)+p(128|63&e):(e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320),p(240|e>>>18&7)+p(128|e>>>12&63)+p(128|e>>>6&63)+p(128|63&e))},W=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,x=t=>t.replace(W,D),T=a?t=>Buffer.from(t,"utf8").toString("base64"):c?t=>A(c.encode(t)):t=>w(x(t)),P=(t,e=!1)=>e?b(T(t)):T(t);t=t=>P(t,!0);const H=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,M=t=>{switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return p(55296+(e>>>10))+p(56320+(1023&e));case 3:return p((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return p((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},U=t=>t.replace(H,M);var j=e=>{if(e=e.replace(/\s+/g,""),!F.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let r,n="",o,i;for(let t=0;t>16&255):64===i?p(r>>16&255,r>>8&255):p(r>>16&255,r>>8&255,255&r);return n};const B=z?t=>atob(v(t)):a?t=>Buffer.from(t,"base64").toString("binary"):j,C=a?t=>g(Buffer.from(t,"base64")):t=>g(B(t),t=>t.charCodeAt(0)),R=t=>C(O(t)),Z=a?t=>Buffer.from(t,"base64").toString("utf8"):u?t=>u.decode(C(t)):t=>U(B(t)),O=t=>v(t.replace(/[-_]/g,t=>"-"==t?"+":"/")),_=t=>Z(O(t));function N(){var t=(t,e)=>Object.defineProperty(String.prototype,t,Q(e));t("fromBase64",function(){return _(this)}),t("toBase64",function(t){return P(this,t)}),t("toBase64URI",function(){return P(this,!0)}),t("toBase64URL",function(){return P(this,!0)}),t("toUint8Array",function(){return R(this)})}function q(){var t=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,Q(e));t("toBase64",function(t){return S(this,t)}),t("toBase64URI",function(){return S(this,!0)}),t("toBase64URL",function(){return S(this,!0)})}const Q=t=>({value:t,enumerable:!1,writable:!0,configurable:!0});const V={version:k,VERSION:"3.7.2",atob:B,atobPolyfill:j,btoa:w,btoaPolyfill:m,fromBase64:_,toBase64:P,encode:P,encodeURI:t,encodeURL:t,utob:x,btou:U,decode:_,isValid:t=>{return"string"==typeof t&&(t=t.replace(/\s+/g,"").replace(/={0,2}$/,""),!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t))},fromUint8Array:S,toUint8Array:R,extendString:N,extendUint8Array:q,extendBuiltins:()=>{N(),q()}};function $(t,e){return t(e={exports:{}},e.exports),e.exports}function G(t){return null!=t&&(X(t)||"function"==typeof(e=t).readFloatLE&&"function"==typeof e.slice&&X(e.slice(0,0))||!!t._isBuffer);var e}var J=$(function(t){var i,r;i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(t,e){return t<>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var e=0;e>>5]|=t[r]<<24-n%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;r>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],r=0,n=0;r>>6-2*n);return e}},t.exports=r}),E={utf8:{stringToBytes:function(t){return E.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(E.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],r=0;r>>24)|4278255360&(r[u]<<24|r[u]>>>8);r[e>>>5]|=128<>>9<<4)]=e;for(var c=g._ff,s=g._gg,l=g._hh,f=g._ii,u=0;u>>0,o=o+d>>>0,i=i+y>>>0,a=a+p>>>0}return b.endian([n,o,i,a])}var b,v,m,w;b=J,v=K.utf8,m=G,w=K.bin,g._ff=function(t,e,r,n,o,i,a){t=t+(e&r|~e&n)+(o>>>0)+a;return(t<>>32-i)+e},g._gg=function(t,e,r,n,o,i,a){t=t+(e&n|r&~n)+(o>>>0)+a;return(t<>>32-i)+e},g._hh=function(t,e,r,n,o,i,a){t=t+(e^r^n)+(o>>>0)+a;return(t<>>32-i)+e},g._ii=function(t,e,r,n,o,i,a){t=t+(r^(e|~n))+(o>>>0)+a;return(t<>>32-i)+e},g._blocksize=16,g._digestsize=16,t.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);t=b.wordsToBytes(g(t,e));return e&&e.asBytes?t:e&&e.asString?w.bytesToString(t):b.bytesToHex(t)}});const tt=/\+/g;function et(t=""){try{return decodeURIComponent(""+t)}catch{return""+t}}function rt(t=""){var e={};for(const o of(t="?"===t[0]?t.slice(1):t).split("&")){var r,n=o.match(/([^=]+)=?(.*)/)||[];n.length<2||"__proto__"!==(r=et(n[1]))&&"constructor"!==r&&(n=et((n[2]||"").replace(tt," ")),void 0!==e[r]?Array.isArray(e[r])?e[r].push(n):e[r]=[e[r],n]:e[r]=n)}return e}const nt=/^\w{2,}:(\/\/)?/,ot=/^\/\/[^/]+/;function it(t,e=!1){return nt.test(t)||e&&ot.test(t)}function at(t){return rt(I(t).search)}function I(t="",e){var r,n,o,i,a,u;return it(t,!0)?([r="",n,o=""]=(t.replace(/\\/g,"/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/)||[]).splice(1),[o="",i=""]=(o.match(/([^#/?]*)(.*)?/)||[]).splice(1),{pathname:i,search:a,hash:u}=ut(i.replace(/\/(?=[A-Za-z]:)/,"")),{protocol:r,auth:n?n.slice(0,Math.max(0,n.length-1)):"",host:o,pathname:i,search:a,hash:u}):e?I(e+t):ut(t)}function ut(t=""){var[t="",e="",r=""]=(t.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:t,search:e,hash:r}}var ct=/^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i,st={1:75,2:50,3:35,4:23,5:20},lt=[1,2,3,4,5],ft={domain:null,useHTTPS:!0,includeLibraryParam:!0,urlPrefix:"https://",secureURLToken:null};function L(t){var e=t.url,e=void 0===e?"":e,t=t.useHttps,t=void 0!==t&&t?"https://":"http://";return it(e,!0)?I(e):L({url:t+e})}function ht(t,e){if(!Number.isInteger(t)||!Number.isInteger(e)||t<=0||e<=0||et.length)&&(e=t.length);for(var r=0,n=new Array(e);r{let r={};return t.forEach((t,e)=>r[t]=e),r})(d),F=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,p=String.fromCharCode.bind(String),g="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):(t,e=t=>t)=>new Uint8Array(Array.prototype.slice.call(t,0).map(e)),b=t=>t.replace(/=/g,"").replace(/[+\/]/g,t=>"+"==t?"-":"_"),v=t=>t.replace(/[^A-Za-z0-9\+\/]/g,"");var m=e=>{let r,n,o,i,a="";var t=e.length%3;for(let t=0;t>18&63]+d[r>>12&63]+d[r>>6&63]+d[63&r]}return t?a.slice(0,t-3)+"===".substring(t):a};const w=t?t=>btoa(t):a?t=>Buffer.from(t,"binary").toString("base64"):m,A=a?t=>Buffer.from(t).toString("base64"):r=>{var n=[];for(let t=0,e=r.length;te?b(A(t)):A(t),D=t=>{var e;return t.length<2?(e=t.charCodeAt(0))<128?t:e<2048?p(192|e>>>6)+p(128|63&e):p(224|e>>>12&15)+p(128|e>>>6&63)+p(128|63&e):(e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320),p(240|e>>>18&7)+p(128|e>>>12&63)+p(128|e>>>6&63)+p(128|63&e))},W=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,x=t=>t.replace(W,D),T=a?t=>Buffer.from(t,"utf8").toString("base64"):c?t=>A(c.encode(t)):t=>w(x(t)),P=(t,e=!1)=>e?b(T(t)):T(t);t=t=>P(t,!0);const H=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,M=t=>{switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return p(55296+(e>>>10))+p(56320+(1023&e));case 3:return p((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return p((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},U=t=>t.replace(H,M);var j=e=>{if(e=e.replace(/\s+/g,""),!F.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let r,n="",o,i;for(let t=0;t>16&255):64===i?p(r>>16&255,r>>8&255):p(r>>16&255,r>>8&255,255&r);return n};const B=z?t=>atob(v(t)):a?t=>Buffer.from(t,"base64").toString("binary"):j,C=a?t=>g(Buffer.from(t,"base64")):t=>g(B(t),t=>t.charCodeAt(0)),R=t=>C(O(t)),Z=a?t=>Buffer.from(t,"base64").toString("utf8"):u?t=>u.decode(C(t)):t=>U(B(t)),O=t=>v(t.replace(/[-_]/g,t=>"-"==t?"+":"/")),_=t=>Z(O(t));function N(){var t=(t,e)=>Object.defineProperty(String.prototype,t,Q(e));t("fromBase64",function(){return _(this)}),t("toBase64",function(t){return P(this,t)}),t("toBase64URI",function(){return P(this,!0)}),t("toBase64URL",function(){return P(this,!0)}),t("toUint8Array",function(){return R(this)})}function q(){var t=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,Q(e));t("toBase64",function(t){return S(this,t)}),t("toBase64URI",function(){return S(this,!0)}),t("toBase64URL",function(){return S(this,!0)})}const Q=t=>({value:t,enumerable:!1,writable:!0,configurable:!0});const V={version:k,VERSION:"3.7.2",atob:B,atobPolyfill:j,btoa:w,btoaPolyfill:m,fromBase64:_,toBase64:P,encode:P,encodeURI:t,encodeURL:t,utob:x,btou:U,decode:_,isValid:t=>{return"string"==typeof t&&(t=t.replace(/\s+/g,"").replace(/={0,2}$/,""),!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t))},fromUint8Array:S,toUint8Array:R,extendString:N,extendUint8Array:q,extendBuiltins:()=>{N(),q()}};function $(t,e){return t(e={exports:{}},e.exports),e.exports}function G(t){return null!=t&&(X(t)||"function"==typeof(e=t).readFloatLE&&"function"==typeof e.slice&&X(e.slice(0,0))||!!t._isBuffer);var e}var J=$(function(t){var i,r;i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(t,e){return t<>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var e=0;e>>5]|=t[r]<<24-n%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;r>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],r=0,n=0;r>>6-2*n);return e}},t.exports=r}),E={utf8:{stringToBytes:function(t){return E.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(E.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],r=0;r>>24)|4278255360&(r[u]<<24|r[u]>>>8);r[e>>>5]|=128<>>9<<4)]=e;for(var c=g._ff,s=g._gg,l=g._hh,f=g._ii,u=0;u>>0,o=o+d>>>0,i=i+y>>>0,a=a+p>>>0}return b.endian([n,o,i,a])}var b,v,m,w;b=J,v=K.utf8,m=G,w=K.bin,g._ff=function(t,e,r,n,o,i,a){t=t+(e&r|~e&n)+(o>>>0)+a;return(t<>>32-i)+e},g._gg=function(t,e,r,n,o,i,a){t=t+(e&n|r&~n)+(o>>>0)+a;return(t<>>32-i)+e},g._hh=function(t,e,r,n,o,i,a){t=t+(e^r^n)+(o>>>0)+a;return(t<>>32-i)+e},g._ii=function(t,e,r,n,o,i,a){t=t+(r^(e|~n))+(o>>>0)+a;return(t<>>32-i)+e},g._blocksize=16,g._digestsize=16,t.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);t=b.wordsToBytes(g(t,e));return e&&e.asBytes?t:e&&e.asString?w.bytesToString(t):b.bytesToHex(t)}});const tt=/\+/g;function et(t=""){try{return decodeURIComponent(""+t)}catch{return""+t}}function rt(t=""){var e={};for(const o of(t="?"===t[0]?t.slice(1):t).split("&")){var r,n=o.match(/([^=]+)=?(.*)/)||[];n.length<2||"__proto__"!==(r=et(n[1]))&&"constructor"!==r&&(n=et((n[2]||"").replace(tt," ")),void 0!==e[r]?Array.isArray(e[r])?e[r].push(n):e[r]=[e[r],n]:e[r]=n)}return e}const nt=/^\w{2,}:(\/\/)?/,ot=/^\/\/[^/]+/;function it(t,e=!1){return nt.test(t)||e&&ot.test(t)}function at(t){return rt(I(t).search)}function I(t="",e){var r,n,o,i,a,u;return it(t,!0)?([r="",n,o=""]=(t.replace(/\\/g,"/").match(/([^/:]+:)?\/\/([^/@]+@)?(.*)/)||[]).splice(1),[o="",i=""]=(o.match(/([^#/?]*)(.*)?/)||[]).splice(1),{pathname:i,search:a,hash:u}=ut(i.replace(/\/(?=[A-Za-z]:)/,"")),{protocol:r,auth:n?n.slice(0,Math.max(0,n.length-1)):"",host:o,pathname:i,search:a,hash:u}):e?I(e+t):ut(t)}function ut(t=""){var[t="",e="",r=""]=(t.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:t,search:e,hash:r}}var ct=/^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i,st={1:75,2:50,3:35,4:23,5:20},lt=[1,2,3,4,5],ft={domain:null,useHTTPS:!0,includeLibraryParam:!0,urlPrefix:"https://",secureURLToken:null};function L(t){var e=t.url,e=void 0===e?"":e,t=t.useHttps,t=void 0!==t&&t?"https://":"http://";return it(e,!0)?I(e):L({url:t+e})}function ht(t,e){if(!Number.isInteger(t)||!Number.isInteger(e)||t<=0||e<=0||e 1 && arguments[1] !== undefined ? arguments[1] : {}; // If a custom encoder is present, use it // Otherwise just use the encodeURIComponent - var encode = options.encoder || encodeURIComponent; + var useCustomEncoder = !!options.encoder; + var customEncoder = options.encoder; var queryParams = [].concat(_toConsumableArray(this.settings.libraryParam ? ["ixlib=".concat(this.settings.libraryParam)] : []), _toConsumableArray(Object.entries(params).reduce(function (prev, _ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], @@ -343,8 +344,8 @@ var ImgixClient = /*#__PURE__*/function () { if (value == null) { return prev; } - var encodedKey = encode(key); - var encodedValue = key.substr(-2) === '64' ? jsBase64.Base64.encodeURI(value) : encode(value); + var encodedKey = useCustomEncoder ? customEncoder(key, value) : encodeURIComponent(key); + var encodedValue = key.substr(-2) === '64' ? useCustomEncoder ? customEncoder(value, key) : jsBase64.Base64.encodeURI(value) : useCustomEncoder ? customEncoder(value, key) : encodeURIComponent(value); prev.push("".concat(encodedKey, "=").concat(encodedValue)); return prev; }, []))); diff --git a/dist/index.d.ts b/dist/index.d.ts index 5559976b..01f1cd10 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -16,8 +16,8 @@ declare class ImgixClient { params?: {}, options?: { disablePathEncoding?: boolean }, ): string; - _sanitizePath(path: string, options?: { encode?: boolean }): string; - _buildParams(params: {}): string; + _sanitizePath(path: string, options?: _sanitizePathOptions): string; + _buildParams(params: {}, options?: _buildParamsOptions): string; _signParams(path: string, queryParams?: {}): string; buildSrcSet(path: string, params?: {}, options?: SrcSetOptions): string; _buildSrcSetPairs(path: string, params?: {}, options?: SrcSetOptions): string; @@ -52,4 +52,13 @@ export interface SrcSetOptions { disablePathEncoding?: boolean; } +export interface _sanitizePathOptions { + disablePathEncoding?: boolean, + encoder?: (path: string) => string +} + +export interface _buildParamsOptions { + encoder?: (value: string, key?: string) => string +} + export default ImgixClient; diff --git a/dist/index.esm.js b/dist/index.esm.js index 19ba6794..51cf80bc 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -145,7 +145,7 @@ function _toPropertyKey(arg) { } // package version used in the ix-lib parameter -var VERSION = '3.7.0'; +var VERSION = '3.7.1'; // regex pattern used to determine if a domain is valid var DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i; // minimum generated srcset width @@ -329,7 +329,8 @@ var ImgixClient = /*#__PURE__*/function () { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; // If a custom encoder is present, use it // Otherwise just use the encodeURIComponent - var encode = options.encoder || encodeURIComponent; + var useCustomEncoder = !!options.encoder; + var customEncoder = options.encoder; var queryParams = [].concat(_toConsumableArray(this.settings.libraryParam ? ["ixlib=".concat(this.settings.libraryParam)] : []), _toConsumableArray(Object.entries(params).reduce(function (prev, _ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], @@ -337,8 +338,8 @@ var ImgixClient = /*#__PURE__*/function () { if (value == null) { return prev; } - var encodedKey = encode(key); - var encodedValue = key.substr(-2) === '64' ? Base64.encodeURI(value) : encode(value); + var encodedKey = useCustomEncoder ? customEncoder(key, value) : encodeURIComponent(key); + var encodedValue = key.substr(-2) === '64' ? useCustomEncoder ? customEncoder(value, key) : Base64.encodeURI(value) : useCustomEncoder ? customEncoder(value, key) : encodeURIComponent(value); prev.push("".concat(encodedKey, "=").concat(encodedValue)); return prev; }, []))); diff --git a/package.json b/package.json index 541d52d5..5a10bb35 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@imgix/js-core", "description": "A JavaScript client library for generating image URLs with imgix", - "version": "3.7.1", + "version": "3.8.0", "repository": "https://github.com/imgix/js-core", "license": "BSD-2-Clause", "main": "dist/index.cjs.js", diff --git a/src/constants.js b/src/constants.js index 614ff19e..2284c3a1 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,5 @@ // package version used in the ix-lib parameter -export const VERSION = '3.7.1'; +export const VERSION = '3.8.0'; // regex pattern used to determine if a domain is valid export const DOMAIN_REGEX = /^(?:[a-z\d\-_]{1,62}\.){0,125}(?:[a-z\d](?:\-(?=\-*[a-z\d])|[a-z]|\d){0,62}\.)[a-z\d]{1,63}$/i; // minimum generated srcset width