UNPKG

sush-plugin-spreadsheet

Version:

SUSH Plugin for fetching Google Spreadsheet.

1 lines 3.9 kB
(function(d,e){'object'==typeof exports&&'object'==typeof module?module.exports=e():'function'==typeof define&&define.amd?define([],e):'object'==typeof exports?exports.$spreadsheet=e():(d.SUSH=d.SUSH||{},d.SUSH.$spreadsheet=e())})(this,function(){return function(c){function d(g){if(e[g])return e[g].exports;var h=e[g]={i:g,l:!1,exports:{}};return c[g].call(h.exports,h,h.exports,d),h.l=!0,h.exports}var e={};return d.m=c,d.c=e,d.i=function(g){return g},d.d=function(g,h,j){d.o(g,h)||Object.defineProperty(g,h,{configurable:!1,enumerable:!0,get:j})},d.n=function(g){var h=g&&g.__esModule?function(){return g['default']}:function(){return g};return d.d(h,'a',h),h},d.o=function(g,h){return Object.prototype.hasOwnProperty.call(g,h)},d.p='',d(d.s=5)}([function(c,d,e){'use strict';Object.defineProperty(d,'__esModule',{value:!0});var h=e(4),j=e.n(h),l=e(1),m=/\/spreadsheets\/d\/([a-zA-Z0-9_-]+)\//;d['default']=function(n){var o=n.sheetUrl;return function(p){var q=p.id,r=p.stock,s=new Promise(function(t,u){var w=new URL(o),y=(o.match(m)||[])[1];if(!y)throw new Error('sheetUrl is invalid.');var z=Object.assign(h.parse(w.hash.substr(1)),h.parse(w.search.substr(1)));if(!('gid'in z))throw new Error('sheetUrl must contain gid.');var A=l.a.convertGidToWid(z.gid),C=new XMLHttpRequest;C.open('GET','https://spreadsheets.google.com/feeds/list/'+y+'/'+A+'/public/values?alt=json',!0),C.addEventListener('load',function(){return t(C)}),C.addEventListener('error',function(D){return u(D.error)}),C.send()}).then(function(t){if(200!==t.status)throw new Error(t.status+': '+t.statusText);var u=JSON.parse(t.responseText),w=u.feed.entry.map(l.a.parseSheetEntry);return w.sort(function(y,z){return new Date(z.timestamp).getTime()-new Date(y.timestamp).getTime()}),w.forEach(function(y){r.set(y.id,y.url)}),{id:q,stock:r}});return s}}},function(c,d){'use strict';function g(j,l){if(!(j instanceof l))throw new TypeError('Cannot call a class as a function')}var h=function(){function j(){g(this,j)}return j.parseSheetEntry=function(m){var n={};for(var o in m)if(o.match(/^gsx\$/)){var p=o.replace(/^gsx\$/,'');n[p]=m[o].$t}return n},j.convertGidToWid=function(m){var n=parseInt(m,10),o=31578<n?474:31578,p=31578<n?'o':'',q=(n^o).toString(36);return''+p+q},j}();d.a=h},function(c){'use strict';function g(j,l){return Object.prototype.hasOwnProperty.call(j,l)}c.exports=function(j,l,m,n){l=l||'&',m=m||'=';var o={};if('string'!=typeof j||0===j.length)return o;var p=/\+/g;j=j.split(l);var q=1e3;n&&'number'==typeof n.maxKeys&&(q=n.maxKeys);var r=j.length;0<q&&r>q&&(r=q);for(var s=0;s<r;++s){var w,y,z,A,t=j[s].replace(p,'%20'),u=t.indexOf(m);0<=u?(w=t.substr(0,u),y=t.substr(u+1)):(w=t,y=''),z=decodeURIComponent(w),A=decodeURIComponent(y),g(o,z)?h(o[z])?o[z].push(A):o[z]=[o[z],A]:o[z]=A}return o};var h=Array.isArray||function(j){return'[object Array]'===Object.prototype.toString.call(j)}},function(c){'use strict';function g(m,n){if(m.map)return m.map(n);for(var o=[],p=0;p<m.length;p++)o.push(n(m[p],p));return o}var h=function(m){switch(typeof m){case'string':return m;case'boolean':return m?'true':'false';case'number':return isFinite(m)?m:'';default:return'';}};c.exports=function(m,n,o,p){return n=n||'&',o=o||'=',null===m&&(m=void 0),'object'==typeof m?g(l(m),function(q){var r=encodeURIComponent(h(q))+o;return j(m[q])?g(m[q],function(s){return r+encodeURIComponent(h(s))}).join(n):r+encodeURIComponent(h(m[q]))}).join(n):p?encodeURIComponent(h(p))+o+encodeURIComponent(h(m)):''};var j=Array.isArray||function(m){return'[object Array]'===Object.prototype.toString.call(m)},l=Object.keys||function(m){var n=[];for(var o in m)Object.prototype.hasOwnProperty.call(m,o)&&n.push(o);return n}},function(c,d,e){'use strict';d.decode=d.parse=e(2),d.encode=d.stringify=e(3)},function(c,d,e){c.exports=e(0).default,Object.defineProperties(c.exports,{__esModule:{value:!0},'default':{value:c.exports}})}])});