shopify-gid
Version:
Universal encoder/decoder for ID values returned from the Shopify Storefront GraphQL API.
3 lines (2 loc) • 805 B
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.shopifyGid={})}(this,function(e){e.decode=function(e){var t=("undefined"==typeof window?Buffer.from(e,"base64").toString("utf-8"):atob(e)).split("shopify/")[1].split("/"),i=t[0],n=t[1],o=(n.split("?").slice(1)[0]||"").split("&").reduce(function(e,t){var i=t.split("=");return e[i[0]]=i[1],e},{});return{type:i,id:n.split("?")[0],params:o,raw:e}},e.encode=function(e,t,i){void 0===i&&(i={});var n="gid://shopify/"+e+"/"+t,o=[],f=Object.keys(i);if(f.length>0){for(var r=0;r<f.length;r++)o.push(f[r]+"="+i[f[r]]);n+=o="?"+o.join("&")}return"undefined"==typeof window?Buffer.from(n,"utf-8").toString("base64"):btoa(n)}});
//# sourceMappingURL=shopify-gid.umd.js.map