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

cropduster

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cropduster - npm Package Compare versions

Comparing version 5.5.0 to 6.0.0

2

dist/cropduster.browser.js

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

var CD=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",o={CORS_PROXY_SERVER:"http://cors.movableink.com",$:(e,t)=>(t||(t=document),[...t.querySelectorAll(e)]),_initParams(){o._urlParams={};const e=/([^&=]+)=?([^&]*)/g,t=o._searchString();let r=e.exec(t);for(;r;)o._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:e=>o.params()[e],params(e){let t=o._urlParams;return void 0===t&&(o._initParams(),t=o._urlParams),e?t[e]:t},_searchString:()=>window.location.search.substring(1),autofill(){o.param("init");const e=o._urlParams;for(const t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById(`autofill_${t}`)&&(document.getElementById(`autofill_${t}`).innerHTML=e[t])},throwError(e){o.miCaptureFallback(()=>{MICapture.error(e)},()=>{o.log("Capturama error: "+e)})},cancelRequest(e){o.miCaptureFallback(()=>{MICapture.cancel(e)},()=>{o.log(`Request canceled: ${e}`)})},setImageRedirect(e){const t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough(e){const t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData(e){const t=document.getElementById("mi-data")||document.createElement("div");let r;t.id="mi-data",t.style.display="none";try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(const n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl(e){const t=document.createElement("a");t.href=e;let r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":`:${t.port}`;const{hostname:n,pathname:a,search:s,hash:u}=t;return`${o.CORS_PROXY_SERVER}/${n}${r}${a}${s}${u}`},_readyToCapture:!0,_reset(){o._readyToCapture=!0},pause(e,t="manual suspension"){e&&(t+=`, will end in ${e}ms`,setTimeout(()=>{o.resume(t)},e)),o.miCaptureFallback(()=>{MICapture.pause(t)},()=>{o.log(`paused: ${t}`)})},resume(e){o.miCaptureFallback(()=>{MICapture.resume(e)},()=>{o.log(`resuming paused capture: ${e}`)})},getCORS(e,t={},r){return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=o.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),o.get(e,t,r)},_textForResponse(e,t){const r=/charset\=(.+)$/,n=/^utf\-8$/i;return Promise.resolve().then(()=>{if(t&&r.test(t)){const[,e]=r.exec(t);if(!n.test(e))return new TextDecoder(e)}}).then(t=>t?e.arrayBuffer().then(e=>t.decode(e)):e.text(),()=>e.text())},get(e,t={},r){"function"==typeof t&&(r=t,t={});const a=`xhr: ${e}`,s=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)};o.pause(t.maxSuspension||0,a);const u=o._optionsForFetch(t);return fetch(e,u).then(e=>{if(!e.ok)throw new Error(e.statusText);const t=e.headers.get("Content-Type");return this._textForResponse(e,t).then(r=>{const n=e.status;return s(r,n,t),{data:r,status:n,contentType:t,response:e}})}).then(e=>(o.resume(a),e),t=>{throw o.log(`Error encountered in CD.get for ${e}: ${t}`),o.resume(a),s(null),t})},getImage(e,t={},r){"function"==typeof t&&(r=t,t={});const a=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)},s=`getImage: ${e}`;return new Promise(function(r,n){const u=new Image;u.onload=function(){o.resume(s),a(u),r(u)},u.onerror=function(e){o.resume(s),a(null),n(e)},o.pause(t.maxSuspension,s),u.src=e})},getImages(e,t={},r,a){const s="getImages:";o.pause(t.maxSuspension,s),"function"==typeof t&&(a=r,r=t,t={});const u=e.map(e=>this.getImage(e,t.maxSuspension).then(e=>(r&&r(e),e)));return Promise.all(u).then(e=>(a&&(o.log(n),a(e)),o.resume(s),e),e=>{throw o.resume(s),new Error("Not all images loaded successfully")})},waitForAsset(e){o.miCaptureFallback(()=>{MICapture.waitForAsset(e)},()=>{o.log(`Wait for asset: ${e}`)})},log(e){console.log(e)},miCaptureFallback(e,t){const r=!!window.MICapture&&"object"==typeof window.MICapture;return r?e():t()},_hashForRequest(e,t){const r=`${e}${JSON.stringify(t)}`;let n=0;if(0===r.length)return n;for(let o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()},_optionsForFetch(e){const t={redirect:"follow",headers:new Headers(e.headers||{}),method:e.method||"GET",body:e.body,mode:"cors"};return e.withoutCredentials||(t.credentials="include"),t}};t.default=o}]);
var CD=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",o={CORS_PROXY_SERVER:"http://cors.movableink.com",$:(e,t)=>(t||(t=document),[...t.querySelectorAll(e)]),_initParams(){o._urlParams={};const e=/([^&=]+)=?([^&]*)/g,t=o._searchString();let r=e.exec(t);for(;r;)o._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:e=>o.params()[e],params(e){let t=o._urlParams;return void 0===t&&(o._initParams(),t=o._urlParams),e?t[e]:t},_searchString:()=>window.location.search.substring(1),autofill(){o.param("init");const e=o._urlParams;for(const t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById(`autofill_${t}`)&&(document.getElementById(`autofill_${t}`).innerHTML=e[t])},throwError(e){o.miCaptureFallback(()=>{MICapture.error(e)},()=>{o.log("Capturama error: "+e)})},cancelRequest(e){o.miCaptureFallback(()=>{MICapture.cancel(e)},()=>{o.log(`Request canceled: ${e}`)})},setImageRedirect(e){const t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough(e){const t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData(e){const t=document.getElementById("mi-data")||document.createElement("div");let r;t.id="mi-data",t.style.display="none";try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(const n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl(e){const t=document.createElement("a");t.href=e;let r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":`:${t.port}`;const{hostname:n,pathname:a,search:s,hash:u}=t;return`${o.CORS_PROXY_SERVER}/${n}${r}${a}${s}${u}`},_readyToCapture:!0,_reset(){o._readyToCapture=!0},pause(e,t="manual suspension"){e&&(t+=`, will end in ${e}ms`,setTimeout(()=>{o.resume(t)},e)),o.miCaptureFallback(()=>{MICapture.pause(t)},()=>{o.log(`paused: ${t}`)})},resume(e){o.miCaptureFallback(()=>{MICapture.resume(e)},()=>{o.log(`resuming paused capture: ${e}`)})},getCORS(e,t={},r){return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=o.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),o.get(e,t,r)},get(e,t={},r){"function"==typeof t&&(r=t,t={});const a=`xhr: ${e}`,s=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)};return o.pause(t.maxSuspension||0,a),(u=e,i=t,new Promise((e,t)=>{const r=new XMLHttpRequest;if(r.onerror=function(){t(this.status)},r.onload=function(){e(this)},r.open(i.method||"GET",u,!0),i.withoutCredentials||(r.withCredentials=!0),i.headers){const{headers:e}=i;Object.keys(e).forEach(t=>{r.setRequestHeader(t,e[t])})}r.send(i.body)})).then(e=>{const t=e.getResponseHeader("content-type"),{status:r,responseText:n}=e;return s(n,r,t),{data:n,status:r,contentType:t,response:e}}).then(e=>(o.resume(a),e),t=>{throw o.log(`Error encountered in CD.get for ${e}: ${t}`),o.resume(a),s(null),t});var u,i},getImage(e,t={},r){"function"==typeof t&&(r=t,t={});const a=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)},s=`getImage: ${e}`;return new Promise(function(r,n){const u=new Image;u.onload=function(){o.resume(s),a(u),r(u)},u.onerror=function(e){o.resume(s),a(null),n(e)},o.pause(t.maxSuspension,s),u.src=e})},getImages(e,t={},r,a){const s="getImages:";o.pause(t.maxSuspension,s),"function"==typeof t&&(a=r,r=t,t={});const u=e.map(e=>this.getImage(e,t.maxSuspension).then(e=>(r&&r(e),e)));return Promise.all(u).then(e=>(a&&(o.log(n),a(e)),o.resume(s),e),e=>{throw o.resume(s),new Error("Not all images loaded successfully")})},waitForAsset(e){o.miCaptureFallback(()=>{MICapture.waitForAsset(e)},()=>{o.log(`Wait for asset: ${e}`)})},log(e){console.log(e)},miCaptureFallback(e,t){const r=!!window.MICapture&&"object"==typeof window.MICapture;return r?e():t()},_hashForRequest(e,t){const r=`${e}${JSON.stringify(t)}`;let n=0;if(0===r.length)return n;for(let o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()}};t.default=o}]);
//# sourceMappingURL=cropduster.browser.js.map

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cropduster=t():e.cropduster=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",o={CORS_PROXY_SERVER:"http://cors.movableink.com",$:(e,t)=>(t||(t=document),[...t.querySelectorAll(e)]),_initParams(){o._urlParams={};const e=/([^&=]+)=?([^&]*)/g,t=o._searchString();let r=e.exec(t);for(;r;)o._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:e=>o.params()[e],params(e){let t=o._urlParams;return void 0===t&&(o._initParams(),t=o._urlParams),e?t[e]:t},_searchString:()=>window.location.search.substring(1),autofill(){o.param("init");const e=o._urlParams;for(const t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById(`autofill_${t}`)&&(document.getElementById(`autofill_${t}`).innerHTML=e[t])},throwError(e){o.miCaptureFallback(()=>{MICapture.error(e)},()=>{o.log("Capturama error: "+e)})},cancelRequest(e){o.miCaptureFallback(()=>{MICapture.cancel(e)},()=>{o.log(`Request canceled: ${e}`)})},setImageRedirect(e){const t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough(e){const t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData(e){const t=document.getElementById("mi-data")||document.createElement("div");let r;t.id="mi-data",t.style.display="none";try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(const n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl(e){const t=document.createElement("a");t.href=e;let r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":`:${t.port}`;const{hostname:n,pathname:a,search:s,hash:u}=t;return`${o.CORS_PROXY_SERVER}/${n}${r}${a}${s}${u}`},_readyToCapture:!0,_reset(){o._readyToCapture=!0},pause(e,t="manual suspension"){e&&(t+=`, will end in ${e}ms`,setTimeout(()=>{o.resume(t)},e)),o.miCaptureFallback(()=>{MICapture.pause(t)},()=>{o.log(`paused: ${t}`)})},resume(e){o.miCaptureFallback(()=>{MICapture.resume(e)},()=>{o.log(`resuming paused capture: ${e}`)})},getCORS(e,t={},r){return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=o.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),o.get(e,t,r)},_textForResponse(e,t){const r=/charset\=(.+)$/,n=/^utf\-8$/i;return Promise.resolve().then(()=>{if(t&&r.test(t)){const[,e]=r.exec(t);if(!n.test(e))return new TextDecoder(e)}}).then(t=>t?e.arrayBuffer().then(e=>t.decode(e)):e.text(),()=>e.text())},get(e,t={},r){"function"==typeof t&&(r=t,t={});const a=`xhr: ${e}`,s=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)};o.pause(t.maxSuspension||0,a);const u=o._optionsForFetch(t);return fetch(e,u).then(e=>{if(!e.ok)throw new Error(e.statusText);const t=e.headers.get("Content-Type");return this._textForResponse(e,t).then(r=>{const n=e.status;return s(r,n,t),{data:r,status:n,contentType:t,response:e}})}).then(e=>(o.resume(a),e),t=>{throw o.log(`Error encountered in CD.get for ${e}: ${t}`),o.resume(a),s(null),t})},getImage(e,t={},r){"function"==typeof t&&(r=t,t={});const a=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)},s=`getImage: ${e}`;return new Promise(function(r,n){const u=new Image;u.onload=function(){o.resume(s),a(u),r(u)},u.onerror=function(e){o.resume(s),a(null),n(e)},o.pause(t.maxSuspension,s),u.src=e})},getImages(e,t={},r,a){const s="getImages:";o.pause(t.maxSuspension,s),"function"==typeof t&&(a=r,r=t,t={});const u=e.map(e=>this.getImage(e,t.maxSuspension).then(e=>(r&&r(e),e)));return Promise.all(u).then(e=>(a&&(o.log(n),a(e)),o.resume(s),e),e=>{throw o.resume(s),new Error("Not all images loaded successfully")})},waitForAsset(e){o.miCaptureFallback(()=>{MICapture.waitForAsset(e)},()=>{o.log(`Wait for asset: ${e}`)})},log(e){console.log(e)},miCaptureFallback(e,t){const r=!!window.MICapture&&"object"==typeof window.MICapture;return r?e():t()},_hashForRequest(e,t){const r=`${e}${JSON.stringify(t)}`;let n=0;if(0===r.length)return n;for(let o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()},_optionsForFetch(e){const t={redirect:"follow",headers:new Headers(e.headers||{}),method:e.method||"GET",body:e.body,mode:"cors"};return e.withoutCredentials||(t.credentials="include"),t}};t.default=o}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cropduster=t():e.cropduster=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n="callbacks are deprecated in cropduster, prefer using promises for asynchronous operations",o={CORS_PROXY_SERVER:"http://cors.movableink.com",$:(e,t)=>(t||(t=document),[...t.querySelectorAll(e)]),_initParams(){o._urlParams={};const e=/([^&=]+)=?([^&]*)/g,t=o._searchString();let r=e.exec(t);for(;r;)o._urlParams[decodeURIComponent(r[1])]=decodeURIComponent(r[2]),r=e.exec(t)},param:e=>o.params()[e],params(e){let t=o._urlParams;return void 0===t&&(o._initParams(),t=o._urlParams),e?t[e]:t},_searchString:()=>window.location.search.substring(1),autofill(){o.param("init");const e=o._urlParams;for(const t in e)"undefined"!==e[t]&&e[t].length>0&&document.getElementById(`autofill_${t}`)&&(document.getElementById(`autofill_${t}`).innerHTML=e[t])},throwError(e){o.miCaptureFallback(()=>{MICapture.error(e)},()=>{o.log("Capturama error: "+e)})},cancelRequest(e){o.miCaptureFallback(()=>{MICapture.cancel(e)},()=>{o.log(`Request canceled: ${e}`)})},setImageRedirect(e){const t=document.getElementById("mi-redirect-image")||document.createElement("a");return t.href=e,t.id="mi-redirect-image",t.style.display="none",document.body.appendChild(t),t},setClickthrough(e){const t=document.getElementById("mi_dynamic_link")||document.createElement("a");return t.href=e,t.id="mi_dynamic_link",t.style.display="none",document.body.appendChild(t),t},setExtraData(e){const t=document.getElementById("mi-data")||document.createElement("div");let r;t.id="mi-data",t.style.display="none";try{r=JSON.parse(t.getAttribute("data-mi-data"))||{}}catch(e){r={}}for(const n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.setAttribute("data-mi-data",JSON.stringify(r)),document.body.appendChild(t),t},proxyUrl(e){const t=document.createElement("a");t.href=e;let r="";r="0"===t.port||""===t.port?"https:"===t.protocol?":443":"":`:${t.port}`;const{hostname:n,pathname:a,search:s,hash:u}=t;return`${o.CORS_PROXY_SERVER}/${n}${r}${a}${s}${u}`},_readyToCapture:!0,_reset(){o._readyToCapture=!0},pause(e,t="manual suspension"){e&&(t+=`, will end in ${e}ms`,setTimeout(()=>{o.resume(t)},e)),o.miCaptureFallback(()=>{MICapture.pause(t)},()=>{o.log(`paused: ${t}`)})},resume(e){o.miCaptureFallback(()=>{MICapture.resume(e)},()=>{o.log(`resuming paused capture: ${e}`)})},getCORS(e,t={},r){return"function"==typeof t&&(r=t,t={}),t.corsCacheTime=t.corsCacheTime||1e4,/cors.movableink.com/.test(e)||(e=o.proxyUrl(e)),t.headers=t.headers||{},t.headers["x-reverse-proxy-ttl"]=t.corsCacheTime/1e3,t.headers["x-mi-cbe"]=this._hashForRequest(e,t),o.get(e,t,r)},get(e,t={},r){"function"==typeof t&&(r=t,t={});const a=`xhr: ${e}`,s=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)};return o.pause(t.maxSuspension||0,a),(u=e,i=t,new Promise((e,t)=>{const r=new XMLHttpRequest;if(r.onerror=function(){t(this.status)},r.onload=function(){e(this)},r.open(i.method||"GET",u,!0),i.withoutCredentials||(r.withCredentials=!0),i.headers){const{headers:e}=i;Object.keys(e).forEach(t=>{r.setRequestHeader(t,e[t])})}r.send(i.body)})).then(e=>{const t=e.getResponseHeader("content-type"),{status:r,responseText:n}=e;return s(n,r,t),{data:n,status:r,contentType:t,response:e}}).then(e=>(o.resume(a),e),t=>{throw o.log(`Error encountered in CD.get for ${e}: ${t}`),o.resume(a),s(null),t});var u,i},getImage(e,t={},r){"function"==typeof t&&(r=t,t={});const a=function(){if(r&&"function"==typeof r)return o.log(n),r(...arguments)},s=`getImage: ${e}`;return new Promise(function(r,n){const u=new Image;u.onload=function(){o.resume(s),a(u),r(u)},u.onerror=function(e){o.resume(s),a(null),n(e)},o.pause(t.maxSuspension,s),u.src=e})},getImages(e,t={},r,a){const s="getImages:";o.pause(t.maxSuspension,s),"function"==typeof t&&(a=r,r=t,t={});const u=e.map(e=>this.getImage(e,t.maxSuspension).then(e=>(r&&r(e),e)));return Promise.all(u).then(e=>(a&&(o.log(n),a(e)),o.resume(s),e),e=>{throw o.resume(s),new Error("Not all images loaded successfully")})},waitForAsset(e){o.miCaptureFallback(()=>{MICapture.waitForAsset(e)},()=>{o.log(`Wait for asset: ${e}`)})},log(e){console.log(e)},miCaptureFallback(e,t){const r=!!window.MICapture&&"object"==typeof window.MICapture;return r?e():t()},_hashForRequest(e,t){const r=`${e}${JSON.stringify(t)}`;let n=0;if(0===r.length)return n;for(let o=0;o<r.length;o++)n=(n<<5)-n+r.charCodeAt(o)&4294967295;return n.toString()}};t.default=o}])});
//# sourceMappingURL=cropduster.js.map
{
"name": "cropduster",
"version": "5.5.0",
"version": "6.0.0",
"description": "Library for building web pages for use with Movable Ink Web Crops",

@@ -14,3 +14,2 @@ "main": "dist/cropduster.js",

"babel-preset-env": "^1.6.1",
"fetch-mock": "^6.0.0-beta.7",
"karma": "^1.7.1",

@@ -23,2 +22,3 @@ "karma-babel-preprocessor": "^6.0.1",

"karma-webpack": "^2.0.5",
"pretender": "^2.0.0",
"qunitjs": "^2.4.0",

@@ -25,0 +25,0 @@ "release-it": "^6.1.1",

@@ -242,2 +242,8 @@ # Cropduster

### 6.0.0
* Remove use of `fetch` (major bump as exposure to `response` object is a breaking change)
### 5.5.0
* Support non `utf-8` response encoding for `CD.get`
### 5.4.0

@@ -244,0 +250,0 @@ * Expose `response` in resolved CD.get Promise

@@ -186,26 +186,2 @@ const DEPRECATION_MSG = 'callbacks are deprecated in cropduster, prefer using promises for asynchronous operations';

_textForResponse(response, contentType) {
const charsetRegex = /charset\=(.+)$/;
const utf8 = /^utf\-8$/i;
return Promise.resolve().then(() => {
if (contentType && charsetRegex.test(contentType)) {
const [, encoding] = charsetRegex.exec(contentType);
if (!utf8.test(encoding)) {
return new TextDecoder(encoding);
}
}
}).then((decoder) => {
if (decoder) {
return response
.arrayBuffer()
.then((buffer) => decoder.decode(buffer));
} else {
return response.text();
}
}, () => {
return response.text();
});
},
get(url, options = {}, callback) {

@@ -227,37 +203,25 @@ if (typeof options === 'function') {

const requestOptions = CD._optionsForFetch(options);
return ajaxPromise(url, options).then(response => {
const contentType = response.getResponseHeader('content-type');
const { status, responseText: data } = response;
return fetch(url, requestOptions).then(response => {
if (!response.ok) {
throw new Error(response.statusText); // A non-200 range status was returned
}
deprecatedCallback(data, status, contentType);
const contentType = response.headers.get('Content-Type');
return {
data,
status,
contentType,
response
};
}).then(response => {
CD.resume(msg);
return response;
}, (error) => {
CD.log(`Error encountered in CD.get for ${url}: ${error}`);
CD.resume(msg);
return this._textForResponse(response, contentType).then(data => {
const status = response.status;
deprecatedCallback(null);
deprecatedCallback(data, status, contentType);
return {
data,
status,
contentType,
response
};
});
}).then(
(response) => {
CD.resume(msg);
return response;
},
(error) => {
CD.log(`Error encountered in CD.get for ${url}: ${error}`);
CD.resume(msg);
deprecatedCallback(null);
throw error;
}
);
throw error;
});
},

@@ -379,21 +343,34 @@

return hash.toString();
},
}
};
_optionsForFetch(options) {
const requestOptions = {
redirect: 'follow',
headers: new Headers(options.headers || {}),
method: options.method || 'GET',
body: options.body,
mode: 'cors'
function ajaxPromise(url, options) {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest();
req.onerror = function() {
reject(this.status);
};
req.onload = function() {
resolve(this);
};
req.open(options.method || 'GET', url, true);
if (!options.withoutCredentials) {
requestOptions.credentials = 'include';
req.withCredentials = true;
}
return requestOptions;
}
};
if (options.headers) {
const { headers } = options;
Object.keys(headers).forEach((header) => {
req.setRequestHeader(header, headers[header]);
});
}
req.send(options.body);
});
}
export default CD;
import CD from '../src/cropduster';
import { spy } from 'sinon';
import fetchMock from 'fetch-mock';
import Pretender from 'pretender';

@@ -13,7 +13,6 @@ const { module, test } = QUnit;

beforeEach() {
this.fakeServer = fetchMock.mock('*', {
body: 'ok',
headers: {
'Content-Type': 'text/html'
}
this.fakeServer = new Pretender(function() {
this.get('http://callback.com', () => {
return [200, { 'Content-Type': 'text/html' }, 'ok'];
});
});

@@ -31,3 +30,3 @@

afterEach() {
this.fakeServer.restore();
this.fakeServer.shutdown();
}

@@ -78,4 +77,2 @@ });

// can't test CD.param returning query params from here, unfortunately...
test("CD.autofill", function(assert) {

@@ -278,64 +275,11 @@ container.innerHTML = '';

test("CD.get handles alternate charsets", function(assert) {
this.fakeServer.restore();
fetchMock.mock('*', {
// \xec is euc-jp for: 狸
body: '\xec',
headers: {
'Content-Type': `text/html; charset=euc-jp`
}
});
const done = assert.async();
CD.get("http://callback.com", {
headers: {
'Accept': 'application/json'
}
}).then(({ data, status, contentType }) => {
assert.equal(data, '狸', 'resolves with a correctly decoded response');
assert.ok(contentType === 'text/html; charset=euc-jp', 'resolves with a content type');
done();
});
});
test("CD.get has sensible fallback for incorrect charsets", function(assert) {
this.fakeServer.restore();
fetchMock.mock('*', {
body: 'ok',
headers: {
'Content-Type': 'text/html; charset=not-valid'
}
});
const done = assert.async();
CD.get("http://callback.com", {
headers: {
'Accept': 'application/json'
}
}).then(({ data, status, contentType }) => {
assert.ok(data === 'ok', 'resolves with a response');
assert.ok(status === 200, 'resolves with a status');
assert.ok(contentType === 'text/html; charset=not-valid', 'resolves with a content type');
assert.ok(true, 'the promise resolves successfully');
done();
});
});
test("CD.get yields the response object to the resolved promise", function(assert) {
const done = assert.async();
this.fakeServer.restore();
this.fakeServer = fetchMock.mock('*', {
body: 'ok',
headers: {
'Content-Type': 'text/html',
'Every-Thing-Is': 'awesome'
}
this.fakeServer.get('http://callback.com', () => {
return [200, { 'Content-Type': 'text/html', 'Every-Thing-Is': 'awesome' }, 'ok'];
});
CD.get("http://callback.com").then(({ response }) => {
assert.equal(response.headers.get('every-thing-is'), 'awesome', 'the response headers are available');
assert.equal(response.getResponseHeader('every-thing-is'), 'awesome', 'the response headers are available');
done();

@@ -346,6 +290,6 @@ });

test("DEPRECATED - CD.get with callbacks and a failing response", function(assert) {
this.fakeServer.restore();
this.fakeServer.mock('*', 500);
const done = assert.async();
this.fakeServer.get('*', () => [500, {}, '']);
CD.get("http://google.com", {

@@ -365,5 +309,4 @@ headers: {

test("CD.get with promises and a failing response", function(assert) {
this.fakeServer.restore();
this.fakeServer.mock('*', 500);
const done = assert.async();
this.fakeServer.get('*', () => [500, {}, '']);

@@ -387,2 +330,11 @@ CD.get("http://google.com", {

test("CD.get - request options", function(assert) {
const done = assert.async();
this.fakeServer.get('http://google.com', req => {
assert.equal(req.requestHeaders['Accept'], 'application/json');
assert.equal(req.withCredentials, true);
done();
return [200, {}, ''];
});
CD.get("http://google.com", {

@@ -394,14 +346,13 @@ corsCacheTime: 5000,

});
});
const lastRequest = this.fakeServer.lastOptions();
test("CD.get - withoutCredentials option", function(assert) {
const done = assert.async();
assert.equal(this.fakeServer.calls.length, 1);
assert.equal(this.fakeServer.lastUrl(), "http://google.com");
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), null); // not automatically added
assert.equal(lastRequest.headers.get('Accept'), 'application/json');
assert.equal(lastRequest.method, 'GET');
assert.equal(lastRequest.credentials, 'include');
});
this.fakeServer.get('http://google.com', req => {
assert.equal(req.withCredentials, false, 'credentials are not included in request');
done();
return [200, {}, ''];
});
test("CD.get - withoutCredentials option", function(assert) {
CD.get("http://google.com", {

@@ -414,15 +365,14 @@ corsCacheTime: 5000,

});
});
const lastRequest = this.fakeServer.lastOptions();
test("CD.getCORS - request options", function(assert) {
const done = assert.async();
assert.equal(this.fakeServer.calls.length, 1);
assert.equal(this.fakeServer.lastUrl(), "http://google.com");
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), null); // not automatically added
assert.equal(lastRequest.headers.get('Accept'), 'application/json');
assert.equal(lastRequest.method, 'GET');
this.fakeServer.get('http://cors.movableink.com/google.com/', ({ requestHeaders }) => {
assert.equal(requestHeaders['x-reverse-proxy-ttl'], 5);
assert.equal(requestHeaders['x-mi-cbe'], '-2134781906');
done();
return [200, {}, ''];
});
assert.notOk('credentials' in lastRequest, 'the request does not have a "credentials" option set');
});
test("CD.getCORS - request options", function(assert) {
CD.getCORS("http://google.com", {

@@ -434,26 +384,28 @@ corsCacheTime: 5000,

});
const lastRequest = this.fakeServer.lastOptions();
assert.equal(this.fakeServer.calls.length, 1);
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/");
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 5); // not automatically added
assert.equal(lastRequest.headers.get('x-mi-cbe'), '-2134781906');
assert.equal(lastRequest.headers.get('Accept'), 'application/json');
assert.equal(lastRequest.method, 'GET');
assert.equal(lastRequest.credentials, 'include');
});
test("CD.getCORS without options", function(assert) {
CD.getCORS("http://google.com");
const done = assert.async();
const lastRequest = this.fakeServer.lastOptions();
this.fakeServer.get('http://cors.movableink.com/google.com/', ({ requestHeaders }) => {
assert.equal(requestHeaders['x-reverse-proxy-ttl'], 10);
assert.equal(requestHeaders['x-mi-cbe'], '2084411041');
done();
return [200, {}, ''];
});
assert.equal(this.fakeServer.calls.length, 1);
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/");
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 10);
assert.equal(lastRequest.headers.get('x-mi-cbe'), '2084411041');
CD.getCORS("http://google.com");
});
test("CD.getCORS with POST", function(assert) {
const done = assert.async();
this.fakeServer.post('http://cors.movableink.com/google.com/', ({ requestHeaders, requestBody }) => {
assert.equal(requestHeaders['x-reverse-proxy-ttl'], 5);
assert.equal(requestHeaders['x-mi-cbe'], '-1217831332');
assert.equal(requestBody, 'foobar');
done();
return [200, {}, ''];
});
CD.getCORS("http://google.com", {

@@ -467,12 +419,2 @@ corsCacheTime: 5000,

});
const lastRequest = this.fakeServer.lastOptions();
assert.equal(this.fakeServer.calls.length, 1);
assert.equal(this.fakeServer.lastUrl(), "http://cors.movableink.com/google.com/");
assert.equal(lastRequest.headers.get('x-reverse-proxy-ttl'), 5); // not automatically added
assert.equal(lastRequest.headers.get('x-mi-cbe'), '-1217831332');
assert.equal(lastRequest.headers.get('Accept'), 'application/json');
assert.equal(lastRequest.method, 'POST');
assert.equal(lastRequest.body, 'foobar');
});

@@ -479,0 +421,0 @@

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

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