@moderntribe/wme-utils
Version:
Common utilities used in the WME ecosystem
3 lines (2 loc) • 1.11 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Wme={})}(this,(function(e){"use strict";e.beforeUnloadListener=e=>(e.preventDefault(),e.returnValue="Changes you made may not be saved.",e),e.handleActionRequest=e=>new Promise(((t,o)=>{window.wp.ajax.post(e).done((e=>{t(e||"success")})).catch((e=>{e&&o(e?.responseJSON?e.responseJSON.data:e.responseText),o()}))})),e.isValidUrl=e=>{try{new URL(e);return!0}catch(e){return!1}},e.objToFormData=e=>{const t=new FormData;return Object.keys(e).forEach((o=>{t.append(o,e[o])})),t},e.pxToRem=(e,t=16)=>"number"==typeof e&&"number"==typeof t?`${parseFloat((e/t).toFixed(4))}rem`:null,e.randomInt=(e,t)=>{const o=Math.ceil(e),n=Math.floor(t);return Math.floor(Math.random()*(n-o)+o)},e.removeNulls=function(e){const t=e;return"object"!=typeof t||null===t||Array.isArray(t)||Object.keys(t).forEach((e=>{null===t[e]&&delete t[e]})),t},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map