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