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

kitsu-core

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kitsu-core - npm Package Compare versions

Comparing version 5.2.2 to 6.0.0

27

CHANGELOG.md

@@ -0,1 +1,28 @@

## 6.0.0 (2018-08-10)
##### Breaking Changes
* **kitsu-core:** support nested parameters (closes #148) [breaking] (14b7747f)
##### Build System / Dependencies
* update dependency rollup to ~0.64.0 (#193) (279f85a7)
* update dependency eslint to ~5.3.0 (#192) (64c36c20)
* update dependency documentation to ~8.1.0 (#191) (80d2aade)
* update dependency size-limit to ~0.19.0 (#189) (032c98c2)
##### Chores
* lock file maintenance (#190) (aa43d781)
##### Documentation Changes
* **kitsu-core:** update README (037d8423)
* **kitsu:** update README (20b72f2b)
##### Refactors
* **kitsu:** set aliases in constructor, avoid class properties (3bd6de57)
* upgrade to babel 7 (6372acfa)
#### 5.2.2 (2018-07-23)

@@ -2,0 +29,0 @@

45

legacy/index.js

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

(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports,require('babel-runtime/regenerator'),require('babel-runtime/helpers/typeof'),require('babel-runtime/helpers/asyncToGenerator')):'function'==typeof define&&define.amd?define(['exports','babel-runtime/regenerator','babel-runtime/helpers/typeof','babel-runtime/helpers/asyncToGenerator'],b):b(a.Kitsu={},a._regeneratorRuntime,a._typeof,a._asyncToGenerator)})(this,function(a,b,c,d){'use strict';function e(a){if(a.response){var b=a.response.data;b&&b.errors&&(a.errors=b.errors)}throw a}function f(a,b){var d='';for(var e in a){var g=a[e];b&&(d+='&'+b),d+='object'===('undefined'==typeof g?'undefined':c(g))?'['+e+']'+f(g):'['+e+']='+g}return d}function g(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],d='';for(var e in a){var g=a[e];d+='object'===('undefined'==typeof g?'undefined':c(g))?f(g,e):'&'+e+'='+g}return d=encodeURI(d.slice(1)),a?b?'?'+d:d:''}b=b&&b.hasOwnProperty('default')?b['default']:b,c=c&&c.hasOwnProperty('default')?c['default']:c,d=d&&d.hasOwnProperty('default')?d['default']:d;var h=function(){var a=d(b.mark(function a(e){var f=this;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if('object'!==('undefined'==typeof e?'undefined':c(e))||null===e){a.next=7;break}if(!Array.isArray(e)){a.next=6;break}return a.next=4,e.map(function(){var a=d(b.mark(function a(c){return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.abrupt('return',h(c));case 1:case'end':return a.stop();}},a,f)}));return function(){return a.apply(this,arguments)}}());case 4:a.next=7;break;case 6:e.attributes&&e.attributes.constructor===Object&&(Object.keys(e.attributes).forEach(function(a){e[a]=e.attributes[a]}),delete e.attributes);case 7:return a.abrupt('return',e);case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),i=function(){var a=d(b.mark(function a(c,d){var f,g=d.id,h=d.type;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,f=c.filter(function(a){return a.id===g&&a.type===h})[0]||{id:g,type:h},a.abrupt('return',Object.assign({},f));case 5:a.prev=5,a.t0=a['catch'](0),e(a.t0);case 8:case'end':return a.stop();}},a,this,[[0,5]])}));return function(){return a.apply(this,arguments)}}(),j=function(){var a=d(b.mark(function a(c,d){var e,f=c.id,g=c.type,j=c.meta;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,i(d,{id:f,type:g});case 2:if(e=a.sent,!e.relationships){a.next=6;break}return a.next=6,m(e,d);case 6:return j&&(e.meta=j),a.abrupt('return',h(e));case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),k=function(){var a=d(b.mark(function a(c,d,e){var f,g,h,i,k,l;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c[e]=[],f=!0,g=!1,h=void 0,a.prev=4,a.next=7,c.relationships[e].data;case 7:a.t0=Symbol.iterator,i=a.sent[a.t0]();case 9:if(f=(k=i.next()).done){a.next=19;break}return l=k.value,a.t1=c[e],a.next=14,j(l,d);case 14:a.t2=a.sent,a.t1.push.call(a.t1,a.t2);case 16:f=!0,a.next=9;break;case 19:a.next=25;break;case 21:a.prev=21,a.t3=a['catch'](4),g=!0,h=a.t3;case 25:a.prev=25,a.prev=26,!f&&i.return&&i.return();case 28:if(a.prev=28,!g){a.next=31;break}throw h;case 31:return a.finish(28);case 32:return a.finish(25);case 33:case'end':return a.stop();}},a,this,[[4,21,25,33],[26,,28,32]])}));return function(){return a.apply(this,arguments)}}(),l=function(){var a=d(b.mark(function a(c,d,e){return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,j(c.relationships[e].data,d);case 2:c[e]=a.sent,delete c[e].relationships;case 4:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),m=function(){var a=d(b.mark(function a(c,d){var e,f,g;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return e=c.relationships,f=!1,a.next=4,e;case 4:a.t0=b.keys(a.sent);case 5:if((a.t1=a.t0()).done){a.next=19;break}if(g=a.t1.value,!(e[g].data&&Array.isArray(e[g].data))){a.next=13;break}return a.next=10,k(c,d,g);case 10:f=!0,a.next=17;break;case 13:if(!e[g].data){a.next=17;break}return a.next=16,l(c,d,g);case 16:f=!0;case 17:a.next=5;break;case 19:return f&&delete c.relationships,a.abrupt('return',c);case 21:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),n=function(){var a=d(b.mark(function a(c){var d,e,f,g,i,j;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=!0,e=!1,f=void 0,a.prev=3,a.next=6,c.data;case 6:a.t0=Symbol.iterator,g=a.sent[a.t0]();case 8:if(d=(i=g.next()).done){a.next=22;break}if(j=i.value,!c.included){a.next=14;break}return a.next=13,m(j,c.included);case 13:j=a.sent;case 14:if(!j.attributes){a.next=18;break}return a.next=17,h(j);case 17:j=a.sent;case 18:c.data[c.data.indexOf(j)]=j;case 19:d=!0,a.next=8;break;case 22:a.next=28;break;case 24:a.prev=24,a.t1=a['catch'](3),e=!0,f=a.t1;case 28:a.prev=28,a.prev=29,!d&&g.return&&g.return();case 31:if(a.prev=31,!e){a.next=34;break}throw f;case 34:return a.finish(31);case 35:return a.finish(28);case 36:return a.abrupt('return',c);case 37:case'end':return a.stop();}},a,this,[[3,24,28,36],[29,,31,35]])}));return function(){return a.apply(this,arguments)}}(),o=function(){var a=d(b.mark(function a(c){return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(c.data&&c.data.constructor===Array)){a.next=6;break}return a.next=3,n(c);case 3:c=a.sent,a.next=10;break;case 6:if(!c.included){a.next=10;break}return a.next=9,m(c.data,c.included);case 9:c.data=a.sent;case 10:if(delete c.included,!(c.data&&c.data.attributes)){a.next=15;break}return a.next=14,h(c.data);case 14:c.data=a.sent;case 15:return a.abrupt('return',c);case 16:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),p=function(a,b){return a+' requires an ID for the '+b+' relationships'},q=function(){var a=d(b.mark(function a(c){var d,f,g,h,i=this,j=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},k=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(a.prev=0,j.constructor===Object&&0!==Object.keys(j).length){a.next=3;break}throw new Error(k+' requires a JSON object body');case 3:if(d=this.plural(this.camel(c)),f={type:d},'POST'===k||j.id){a.next=7;break}throw new Error(k+' requires an ID for the '+d+' type');case 7:for(h in'POST'!==k&&(f.id=j.id.toString()),g=function(a){if(null!==j[a]&&j[a].constructor===Object){if('string'==typeof j[a].id)f.relationships||(f.relationships={}),j[a].type||(j[a].type=i.plural(i.camel(a))),f.relationships[a]={data:Object.assign(j[a])};else throw new Error(p(k,a));}else if(null!==j[a]&&Array.isArray(j[a])){var b=i.plural(i.camel(a));f.relationships||(f.relationships={}),f.relationships[a]={data:j[a].map(function(c){if(!c.id)throw new Error(p(k,a));return{id:c.id,type:c.type||b}})}}else'id'!==a&&'type'!==a&&(f.attributes||(f.attributes={}),f.attributes[a]=j[a])},j)g(h);return a.abrupt('return',{data:f});case 13:throw a.prev=13,a.t0=a['catch'](0),e(a.t0);case 16:case'end':return a.stop();}},a,this,[[0,13]])}));return function(){return a.apply(this,arguments)}}();a.camel=function(a){return a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(a){return a.slice(1).toUpperCase()})},a.kebab=function(a){return a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(a){return'-'+a.toLowerCase()})},a.snake=function(a){return a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(a){return'_'+a.toLowerCase()})},a.deattribute=h,a.deserialise=o,a.error=e,a.filterIncludes=i,a.linkRelationships=m,a.query=g,a.serialise=q,Object.defineProperty(a,'__esModule',{value:!0})});
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/regenerator'), require('@babel/runtime/helpers/typeof'), require('@babel/runtime/helpers/asyncToGenerator')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/regenerator', '@babel/runtime/helpers/typeof', '@babel/runtime/helpers/asyncToGenerator'], factory) :
(factory((global.KitsuCore = {}),global._regeneratorRuntime,global._typeof,global._asyncToGenerator));
}(this, (function (exports,_regeneratorRuntime,_typeof,_asyncToGenerator) { 'use strict';
_regeneratorRuntime = _regeneratorRuntime && _regeneratorRuntime.hasOwnProperty('default') ? _regeneratorRuntime['default'] : _regeneratorRuntime;
_typeof = _typeof && _typeof.hasOwnProperty('default') ? _typeof['default'] : _typeof;
_asyncToGenerator = _asyncToGenerator && _asyncToGenerator.hasOwnProperty('default') ? _asyncToGenerator['default'] : _asyncToGenerator;
function deattribute(){return _deattribute.apply(this,arguments)}function _deattribute(){return _deattribute=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if("object"!==_typeof(b)||null===b){a.next=7;break}if(!Array.isArray(b)){a.next=6;break}return a.next=4,b.map(function(){var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.abrupt("return",deattribute(b));case 1:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}());case 4:a.next=7;break;case 6:b.attributes&&b.attributes.constructor===Object&&(Object.keys(b.attributes).forEach(function(a){b[a]=b.attributes[a];}),delete b.attributes);case 7:return a.abrupt("return",b);case 8:case"end":return a.stop();}},a,this)})),_deattribute.apply(this,arguments)}
function error(a){if(a.response){var b=a.response.data;b&&b.errors&&(a.errors=b.errors);}throw a}
function filterIncludes(){return _filterIncludes.apply(this,arguments)}function _filterIncludes(){return _filterIncludes=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=c.id,e=c.type,a.prev=1,f=b.filter(function(a){return a.id===d&&a.type===e})[0]||{id:d,type:e},a.abrupt("return",Object.assign({},f));case 6:a.prev=6,a.t0=a["catch"](1),error(a.t0);case 9:case"end":return a.stop();}},a,this,[[1,6]])})),_filterIncludes.apply(this,arguments)}
function link(){return _link.apply(this,arguments)}function _link(){return _link=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f,g;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=b.id,e=b.type,f=b.meta,a.next=3,filterIncludes(c,{id:d,type:e});case 3:if(g=a.sent,!g.relationships){a.next=7;break}return a.next=7,linkRelationships(g,c);case 7:return f&&(g.meta=f),a.abrupt("return",deattribute(g));case 9:case"end":return a.stop();}},a,this)})),_link.apply(this,arguments)}function linkArray(){return _linkArray.apply(this,arguments)}function _linkArray(){return _linkArray=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){var e,f,g,h,i,j;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b[d]=[],e=!0,f=!1,g=void 0,a.prev=4,a.next=7,b.relationships[d].data;case 7:a.t0=Symbol.iterator,h=a.sent[a.t0]();case 9:if(e=(i=h.next()).done){a.next=19;break}return j=i.value,a.t1=b[d],a.next=14,link(j,c);case 14:a.t2=a.sent,a.t1.push.call(a.t1,a.t2);case 16:e=!0,a.next=9;break;case 19:a.next=25;break;case 21:a.prev=21,a.t3=a["catch"](4),f=!0,g=a.t3;case 25:a.prev=25,a.prev=26,e||null==h.return||h.return();case 28:if(a.prev=28,!f){a.next=31;break}throw g;case 31:return a.finish(28);case 32:return a.finish(25);case 33:case"end":return a.stop();}},a,this,[[4,21,25,33],[26,,28,32]])})),_linkArray.apply(this,arguments)}function linkObject(){return _linkObject.apply(this,arguments)}function _linkObject(){return _linkObject=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,link(b.relationships[d].data,c);case 2:b[d]=a.sent,delete b[d].relationships;case 4:case"end":return a.stop();}},a,this)})),_linkObject.apply(this,arguments)}function linkRelationships(){return _linkRelationships.apply(this,arguments)}function _linkRelationships(){return _linkRelationships=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=b.relationships,e=!1,a.next=4,d;case 4:a.t0=_regeneratorRuntime.keys(a.sent);case 5:if((a.t1=a.t0()).done){a.next=19;break}if(f=a.t1.value,!(d[f].data&&Array.isArray(d[f].data))){a.next=13;break}return a.next=10,linkArray(b,c,f);case 10:e=!0,a.next=17;break;case 13:if(!d[f].data){a.next=17;break}return a.next=16,linkObject(b,c,f);case 16:e=!0;case 17:a.next=5;break;case 19:return e&&delete b.relationships,a.abrupt("return",b);case 21:case"end":return a.stop();}},a,this)})),_linkRelationships.apply(this,arguments)}
function deserialiseArray(){return _deserialiseArray.apply(this,arguments)}function _deserialiseArray(){return _deserialiseArray=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g,h;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=!0,d=!1,e=void 0,a.prev=3,a.next=6,b.data;case 6:a.t0=Symbol.iterator,f=a.sent[a.t0]();case 8:if(c=(g=f.next()).done){a.next=22;break}if(h=g.value,!b.included){a.next=14;break}return a.next=13,linkRelationships(h,b.included);case 13:h=a.sent;case 14:if(!h.attributes){a.next=18;break}return a.next=17,deattribute(h);case 17:h=a.sent;case 18:b.data[b.data.indexOf(h)]=h;case 19:c=!0,a.next=8;break;case 22:a.next=28;break;case 24:a.prev=24,a.t1=a["catch"](3),d=!0,e=a.t1;case 28:a.prev=28,a.prev=29,c||null==f.return||f.return();case 31:if(a.prev=31,!d){a.next=34;break}throw e;case 34:return a.finish(31);case 35:return a.finish(28);case 36:return a.abrupt("return",b);case 37:case"end":return a.stop();}},a,this,[[3,24,28,36],[29,,31,35]])})),_deserialiseArray.apply(this,arguments)}function deserialise(){return _deserialise.apply(this,arguments)}function _deserialise(){return _deserialise=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(b.data&&b.data.constructor===Array)){a.next=6;break}return a.next=3,deserialiseArray(b);case 3:b=a.sent,a.next=10;break;case 6:if(!b.included){a.next=10;break}return a.next=9,linkRelationships(b.data,b.included);case 9:b.data=a.sent;case 10:if(delete b.included,!(b.data&&b.data.attributes)){a.next=15;break}return a.next=14,deattribute(b.data);case 14:b.data=a.sent;case 15:return a.abrupt("return",b);case 16:case"end":return a.stop();}},a,this)})),_deserialise.apply(this,arguments)}
function query(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null,c=[];for(var d in a)if(a.hasOwnProperty(d)){var e=b?"".concat(b,"[").concat(d,"]"):d,f=a[d];c.push(null!==f&&"object"===_typeof(f)?query(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f));}return c.join("&")}
var requiresID=function(a,b){return "".concat(a," requires an ID for the ").concat(b," relationships")};function serialise(){return _serialise.apply(this,arguments)}function _serialise(){return _serialise=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g,h,i=this,j=arguments;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=1<j.length&&void 0!==j[1]?j[1]:{},d=2<j.length&&void 0!==j[2]?j[2]:"POST",a.prev=2,c.constructor===Object&&0!==Object.keys(c).length){a.next=5;break}throw new Error("".concat(d," requires a JSON object body"));case 5:if(e=this.plural(this.camel(b)),f={type:e},"POST"===d||c.id){a.next=9;break}throw new Error("".concat(d," requires an ID for the ").concat(e," type"));case 9:for(h in"POST"!==d&&(f.id=c.id.toString()),g=function(a){if(null!==c[a]&&c[a].constructor===Object){if("string"==typeof c[a].id)f.relationships||(f.relationships={}),c[a].type||(c[a].type=i.plural(i.camel(a))),f.relationships[a]={data:Object.assign(c[a])};else throw new Error(requiresID(d,a));}else if(null!==c[a]&&Array.isArray(c[a])){var b=i.plural(i.camel(a));f.relationships||(f.relationships={}),f.relationships[a]={data:c[a].map(function(c){if(!c.id)throw new Error(requiresID(d,a));return {id:c.id,type:c.type||b}})};}else"id"!==a&&"type"!==a&&(f.attributes||(f.attributes={}),f.attributes[a]=c[a]);},c)g(h);return a.abrupt("return",{data:f});case 15:throw a.prev=15,a.t0=a["catch"](2),error(a.t0);case 18:case"end":return a.stop();}},a,this,[[2,15]])})),_serialise.apply(this,arguments)}
var index = (function(a){return a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(a){return a.slice(1).toUpperCase()})});
var index$1 = (function(a){return a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(a){return "-"+a.toLowerCase()})});
var index$2 = (function(a){return a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(a){return "_"+a.toLowerCase()})});
exports.camel = index;
exports.kebab = index$1;
exports.snake = index$2;
exports.deattribute = deattribute;
exports.deserialise = deserialise;
exports.error = error;
exports.filterIncludes = filterIncludes;
exports.linkRelationships = linkRelationships;
exports.query = query;
exports.serialise = serialise;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=index.js.map

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

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});function _interopDefault(a){return a&&'object'==typeof a&&'default'in a?a['default']:a}var _regeneratorRuntime=_interopDefault(require('babel-runtime/regenerator')),_asyncToGenerator=_interopDefault(require('babel-runtime/helpers/asyncToGenerator')),deattribute=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d=this;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if('object'!=typeof b||null===b){a.next=7;break}if(!Array.isArray(b)){a.next=6;break}return a.next=4,b.map((()=>(c=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.abrupt('return',deattribute(b));case 1:case'end':return a.stop();}},a,d)})),function(){return c.apply(this,arguments)}))());case 4:a.next=7;break;case 6:b.attributes&&b.attributes.constructor===Object&&(Object.keys(b.attributes).forEach(function(a){b[a]=b.attributes[a]}),delete b.attributes);case 7:return a.abrupt('return',b);case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}})();function error(a){if(a.response){var b=a.response.data;b&&b.errors&&(a.errors=b.errors)}throw a}var filterIncludes=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e=c.id,f=c.type;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,d=b.filter(function(a){return a.id===e&&a.type===f})[0]||{id:e,type:f},a.abrupt('return',Object.assign({},d));case 5:a.prev=5,a.t0=a['catch'](0),error(a.t0);case 8:case'end':return a.stop();}},a,this,[[0,5]])}));return function(){return a.apply(this,arguments)}})(),link=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e=b.id,f=b.type,g=b.meta;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,filterIncludes(c,{id:e,type:f});case 2:if(d=a.sent,!d.relationships){a.next=6;break}return a.next=6,linkRelationships(d,c);case 6:return g&&(d.meta=g),a.abrupt('return',deattribute(d));case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}})(),linkArray=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){var e,f,g,h,i,j;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b[d]=[],e=!0,f=!1,g=void 0,a.prev=4,a.next=7,b.relationships[d].data;case 7:a.t0=Symbol.iterator,h=a.sent[a.t0]();case 9:if(e=(i=h.next()).done){a.next=19;break}return j=i.value,a.t1=b[d],a.next=14,link(j,c);case 14:a.t2=a.sent,a.t1.push.call(a.t1,a.t2);case 16:e=!0,a.next=9;break;case 19:a.next=25;break;case 21:a.prev=21,a.t3=a['catch'](4),f=!0,g=a.t3;case 25:a.prev=25,a.prev=26,!e&&h.return&&h.return();case 28:if(a.prev=28,!f){a.next=31;break}throw g;case 31:return a.finish(28);case 32:return a.finish(25);case 33:case'end':return a.stop();}},a,this,[[4,21,25,33],[26,,28,32]])}));return function(){return a.apply(this,arguments)}})(),linkObject=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,link(b.relationships[d].data,c);case 2:b[d]=a.sent,delete b[d].relationships;case 4:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}})(),linkRelationships=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=b.relationships,e=!1,a.next=4,d;case 4:a.t0=_regeneratorRuntime.keys(a.sent);case 5:if((a.t1=a.t0()).done){a.next=19;break}if(f=a.t1.value,!(d[f].data&&Array.isArray(d[f].data))){a.next=13;break}return a.next=10,linkArray(b,c,f);case 10:e=!0,a.next=17;break;case 13:if(!d[f].data){a.next=17;break}return a.next=16,linkObject(b,c,f);case 16:e=!0;case 17:a.next=5;break;case 19:return e&&delete b.relationships,a.abrupt('return',b);case 21:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}})(),deserialiseArray=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g,h;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=!0,d=!1,e=void 0,a.prev=3,a.next=6,b.data;case 6:a.t0=Symbol.iterator,f=a.sent[a.t0]();case 8:if(c=(g=f.next()).done){a.next=22;break}if(h=g.value,!b.included){a.next=14;break}return a.next=13,linkRelationships(h,b.included);case 13:h=a.sent;case 14:if(!h.attributes){a.next=18;break}return a.next=17,deattribute(h);case 17:h=a.sent;case 18:b.data[b.data.indexOf(h)]=h;case 19:c=!0,a.next=8;break;case 22:a.next=28;break;case 24:a.prev=24,a.t1=a['catch'](3),d=!0,e=a.t1;case 28:a.prev=28,a.prev=29,!c&&f.return&&f.return();case 31:if(a.prev=31,!d){a.next=34;break}throw e;case 34:return a.finish(31);case 35:return a.finish(28);case 36:return a.abrupt('return',b);case 37:case'end':return a.stop();}},a,this,[[3,24,28,36],[29,,31,35]])}));return function(){return a.apply(this,arguments)}})(),deserialise=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(b.data&&b.data.constructor===Array)){a.next=6;break}return a.next=3,deserialiseArray(b);case 3:b=a.sent,a.next=10;break;case 6:if(!b.included){a.next=10;break}return a.next=9,linkRelationships(b.data,b.included);case 9:b.data=a.sent;case 10:if(delete b.included,!(b.data&&b.data.attributes)){a.next=15;break}return a.next=14,deattribute(b.data);case 14:b.data=a.sent;case 15:return a.abrupt('return',b);case 16:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}})();function deObject(a,b){var c='';for(var d in a){var e=a[d];b&&(c+=`&${b}`),c+='object'==typeof e?`[${d}]${deObject(e)}`:`[${d}]=${e}`}return c}function query(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],c='';for(var d in a){var e=a[d];c+='object'==typeof e?deObject(e,d):`&${d}=${e}`}return c=encodeURI(c.slice(1)),a?b?`?${c}`:c:''}var requiresID=(a,b)=>`${a} requires an ID for the ${b} relationships`,serialise=(()=>{var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g=this,h=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},i=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(a.prev=0,h.constructor===Object&&0!==Object.keys(h).length){a.next=3;break}throw new Error(`${i} requires a JSON object body`);case 3:if(c=this.plural(this.camel(b)),d={type:c},'POST'===i||h.id){a.next=7;break}throw new Error(`${i} requires an ID for the ${c} type`);case 7:for(f in'POST'!==i&&(d.id=h.id.toString()),e=function(a){if(null!==h[a]&&h[a].constructor===Object){if('string'==typeof h[a].id)d.relationships||(d.relationships={}),h[a].type||(h[a].type=g.plural(g.camel(a))),d.relationships[a]={data:Object.assign(h[a])};else throw new Error(requiresID(i,a));}else if(null!==h[a]&&Array.isArray(h[a])){var b=g.plural(g.camel(a));d.relationships||(d.relationships={}),d.relationships[a]={data:h[a].map(function(c){if(!c.id)throw new Error(requiresID(i,a));return{id:c.id,type:c.type||b}})}}else'id'!==a&&'type'!==a&&(d.attributes||(d.attributes={}),d.attributes[a]=h[a])},h)e(f);return a.abrupt('return',{data:d});case 13:throw a.prev=13,a.t0=a['catch'](0),error(a.t0);case 16:case'end':return a.stop();}},a,this,[[0,13]])}));return function(){return a.apply(this,arguments)}})(),index=a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase()),index$1=a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>'-'+a.toLowerCase()),index$2=a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>'_'+a.toLowerCase());exports.camel=index,exports.kebab=index$1,exports.snake=index$2,exports.deattribute=deattribute,exports.deserialise=deserialise,exports.error=error,exports.filterIncludes=filterIncludes,exports.linkRelationships=linkRelationships,exports.query=query,exports.serialise=serialise;
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
function deattribute(){return _deattribute.apply(this,arguments)}function _deattribute(){return _deattribute=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if("object"!=typeof b||null===b){a.next=7;break}if(!Array.isArray(b)){a.next=6;break}return a.next=4,b.map(function(){var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.abrupt("return",deattribute(b));case 1:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}());case 4:a.next=7;break;case 6:b.attributes&&b.attributes.constructor===Object&&(Object.keys(b.attributes).forEach(a=>{b[a]=b.attributes[a];}),delete b.attributes);case 7:return a.abrupt("return",b);case 8:case"end":return a.stop();}},a,this)})),_deattribute.apply(this,arguments)}
function error(a){if(a.response){const b=a.response.data;b&&b.errors&&(a.errors=b.errors);}throw a}
function filterIncludes(){return _filterIncludes.apply(this,arguments)}function _filterIncludes(){return _filterIncludes=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=c.id,e=c.type,a.prev=1,f=b.filter(a=>a.id===d&&a.type===e)[0]||{id:d,type:e},a.abrupt("return",Object.assign({},f));case 6:a.prev=6,a.t0=a["catch"](1),error(a.t0);case 9:case"end":return a.stop();}},a,this,[[1,6]])})),_filterIncludes.apply(this,arguments)}
function link(){return _link.apply(this,arguments)}function _link(){return _link=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f,g;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=b.id,e=b.type,f=b.meta,a.next=3,filterIncludes(c,{id:d,type:e});case 3:if(g=a.sent,!g.relationships){a.next=7;break}return a.next=7,linkRelationships(g,c);case 7:return f&&(g.meta=f),a.abrupt("return",deattribute(g));case 9:case"end":return a.stop();}},a,this)})),_link.apply(this,arguments)}function linkArray(){return _linkArray.apply(this,arguments)}function _linkArray(){return _linkArray=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){var e,f,g,h,i,j;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b[d]=[],e=!0,f=!1,g=void 0,a.prev=4,a.next=7,b.relationships[d].data;case 7:a.t0=Symbol.iterator,h=a.sent[a.t0]();case 9:if(e=(i=h.next()).done){a.next=19;break}return j=i.value,a.t1=b[d],a.next=14,link(j,c);case 14:a.t2=a.sent,a.t1.push.call(a.t1,a.t2);case 16:e=!0,a.next=9;break;case 19:a.next=25;break;case 21:a.prev=21,a.t3=a["catch"](4),f=!0,g=a.t3;case 25:a.prev=25,a.prev=26,e||null==h.return||h.return();case 28:if(a.prev=28,!f){a.next=31;break}throw g;case 31:return a.finish(28);case 32:return a.finish(25);case 33:case"end":return a.stop();}},a,this,[[4,21,25,33],[26,,28,32]])})),_linkArray.apply(this,arguments)}function linkObject(){return _linkObject.apply(this,arguments)}function _linkObject(){return _linkObject=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c,d){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,link(b.relationships[d].data,c);case 2:b[d]=a.sent,delete b[d].relationships;case 4:case"end":return a.stop();}},a,this)})),_linkObject.apply(this,arguments)}function linkRelationships(){return _linkRelationships.apply(this,arguments)}function _linkRelationships(){return _linkRelationships=_asyncToGenerator(_regeneratorRuntime.mark(function a(b,c){var d,e,f;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=b.relationships,e=!1,a.next=4,d;case 4:a.t0=_regeneratorRuntime.keys(a.sent);case 5:if((a.t1=a.t0()).done){a.next=19;break}if(f=a.t1.value,!(d[f].data&&Array.isArray(d[f].data))){a.next=13;break}return a.next=10,linkArray(b,c,f);case 10:e=!0,a.next=17;break;case 13:if(!d[f].data){a.next=17;break}return a.next=16,linkObject(b,c,f);case 16:e=!0;case 17:a.next=5;break;case 19:return e&&delete b.relationships,a.abrupt("return",b);case 21:case"end":return a.stop();}},a,this)})),_linkRelationships.apply(this,arguments)}
function deserialiseArray(){return _deserialiseArray.apply(this,arguments)}function _deserialiseArray(){return _deserialiseArray=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g,h;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=!0,d=!1,e=void 0,a.prev=3,a.next=6,b.data;case 6:a.t0=Symbol.iterator,f=a.sent[a.t0]();case 8:if(c=(g=f.next()).done){a.next=22;break}if(h=g.value,!b.included){a.next=14;break}return a.next=13,linkRelationships(h,b.included);case 13:h=a.sent;case 14:if(!h.attributes){a.next=18;break}return a.next=17,deattribute(h);case 17:h=a.sent;case 18:b.data[b.data.indexOf(h)]=h;case 19:c=!0,a.next=8;break;case 22:a.next=28;break;case 24:a.prev=24,a.t1=a["catch"](3),d=!0,e=a.t1;case 28:a.prev=28,a.prev=29,c||null==f.return||f.return();case 31:if(a.prev=31,!d){a.next=34;break}throw e;case 34:return a.finish(31);case 35:return a.finish(28);case 36:return a.abrupt("return",b);case 37:case"end":return a.stop();}},a,this,[[3,24,28,36],[29,,31,35]])})),_deserialiseArray.apply(this,arguments)}function deserialise(){return _deserialise.apply(this,arguments)}function _deserialise(){return _deserialise=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!(b.data&&b.data.constructor===Array)){a.next=6;break}return a.next=3,deserialiseArray(b);case 3:b=a.sent,a.next=10;break;case 6:if(!b.included){a.next=10;break}return a.next=9,linkRelationships(b.data,b.included);case 9:b.data=a.sent;case 10:if(delete b.included,!(b.data&&b.data.attributes)){a.next=15;break}return a.next=14,deattribute(b.data);case 14:b.data=a.sent;case 15:return a.abrupt("return",b);case 16:case"end":return a.stop();}},a,this)})),_deserialise.apply(this,arguments)}
function query(a){let b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null;const c=[];for(const d in a)if(a.hasOwnProperty(d)){const e=b?`${b}[${d}]`:d,f=a[d];c.push(null!==f&&"object"==typeof f?query(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f));}return c.join("&")}
const requiresID=(a,b)=>`${a} requires an ID for the ${b} relationships`;function serialise(){return _serialise.apply(this,arguments)}function _serialise(){return _serialise=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c,d,e,f,g,h,i=arguments;return _regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=1<i.length&&void 0!==i[1]?i[1]:{},d=2<i.length&&void 0!==i[2]?i[2]:"POST",a.prev=2,c.constructor===Object&&0!==Object.keys(c).length){a.next=5;break}throw new Error(`${d} requires a JSON object body`);case 5:if(e=this.plural(this.camel(b)),f={type:e},"POST"===d||c.id){a.next=9;break}throw new Error(`${d} requires an ID for the ${e} type`);case 9:"POST"!==d&&(f.id=c.id.toString()),a.t0=_regeneratorRuntime.keys(c);case 11:if((a.t1=a.t0()).done){a.next=26;break}if(g=a.t1.value,null===c[g]||c[g].constructor!==Object){a.next=23;break}if("string"!=typeof c[g].id){a.next=20;break}f.relationships||(f.relationships={}),c[g].type||(c[g].type=this.plural(this.camel(g))),f.relationships[g]={data:Object.assign(c[g])},a.next=21;break;case 20:throw new Error(requiresID(d,g));case 21:a.next=24;break;case 23:null!==c[g]&&Array.isArray(c[g])?(h=this.plural(this.camel(g)),!f.relationships&&(f.relationships={}),f.relationships[g]={data:c[g].map(a=>{if(!a.id)throw new Error(requiresID(d,g));return {id:a.id,type:a.type||h}})}):"id"!==g&&"type"!==g&&(!f.attributes&&(f.attributes={}),f.attributes[g]=c[g]);case 24:a.next=11;break;case 26:return a.abrupt("return",{data:f});case 29:throw a.prev=29,a.t2=a["catch"](2),error(a.t2);case 32:case"end":return a.stop();}},a,this,[[2,29]])})),_serialise.apply(this,arguments)}
var index = (a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase()));
var index$1 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"-"+a.toLowerCase()));
var index$2 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"_"+a.toLowerCase()));
exports.camel = index;
exports.kebab = index$1;
exports.snake = index$2;
exports.deattribute = deattribute;
exports.deserialise = deserialise;
exports.error = error;
exports.filterIncludes = filterIncludes;
exports.linkRelationships = linkRelationships;
exports.query = query;
exports.serialise = serialise;
//# sourceMappingURL=index.js.map

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

'use strict';Object.defineProperty(exports,'__esModule',{value:!0});function _interopDefault(a){return a&&'object'==typeof a&&'default'in a?a['default']:a}var _asyncToGenerator=_interopDefault(require('babel-runtime/helpers/asyncToGenerator'));let deattribute=(()=>{var a=_asyncToGenerator(function*(a){return'object'==typeof a&&null!==a&&(Array.isArray(a)?yield a.map((()=>{var a=_asyncToGenerator(function*(a){return deattribute(a)});return function(){return a.apply(this,arguments)}})()):a.attributes&&a.attributes.constructor===Object&&(Object.keys(a.attributes).forEach(function(b){a[b]=a.attributes[b]}),delete a.attributes)),a});return function(){return a.apply(this,arguments)}})();function error(a){if(a.response){const b=a.response.data;b&&b.errors&&(a.errors=b.errors)}throw a}let filterIncludes=(()=>{var a=_asyncToGenerator(function*(a,{id:b,type:c}){try{const d=a.filter(function(a){return a.id===b&&a.type===c})[0]||{id:b,type:c};return Object.assign({},d)}catch(a){error(a)}});return function(){return a.apply(this,arguments)}})(),link=(()=>{var a=_asyncToGenerator(function*({id:a,type:b,meta:c},d){const e=yield filterIncludes(d,{id:a,type:b});return e.relationships&&(yield linkRelationships(e,d)),c&&(e.meta=c),deattribute(e)});return function(){return a.apply(this,arguments)}})(),linkArray=(()=>{var a=_asyncToGenerator(function*(a,b,c){a[c]=[];var d=!0,e=!1,f=void 0;try{for(var g,h=(yield a.relationships[c].data)[Symbol.iterator]();!(d=(g=h.next()).done);d=!0){let d=g.value;a[c].push((yield link(d,b)))}}catch(a){e=!0,f=a}finally{try{!d&&h.return&&h.return()}finally{if(e)throw f}}});return function(){return a.apply(this,arguments)}})(),linkObject=(()=>{var a=_asyncToGenerator(function*(a,b,c){a[c]=yield link(a.relationships[c].data,b),delete a[c].relationships});return function(){return a.apply(this,arguments)}})(),linkRelationships=(()=>{var a=_asyncToGenerator(function*(a,b){const c=a.relationships;let d=!1;for(let e in yield c)c[e].data&&Array.isArray(c[e].data)?(yield linkArray(a,b,e),d=!0):c[e].data&&(yield linkObject(a,b,e),d=!0);return d&&delete a.relationships,a});return function(){return a.apply(this,arguments)}})(),deserialiseArray=(()=>{var a=_asyncToGenerator(function*(a){var b=!0,c=!1,d=void 0;try{for(var e,f=(yield a.data)[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){let b=e.value;a.included&&(b=yield linkRelationships(b,a.included)),b.attributes&&(b=yield deattribute(b)),a.data[a.data.indexOf(b)]=b}}catch(a){c=!0,d=a}finally{try{!b&&f.return&&f.return()}finally{if(c)throw d}}return a});return function(){return a.apply(this,arguments)}})(),deserialise=(()=>{var a=_asyncToGenerator(function*(a){return a.data&&a.data.constructor===Array?a=yield deserialiseArray(a):a.included&&(a.data=yield linkRelationships(a.data,a.included)),delete a.included,a.data&&a.data.attributes&&(a.data=yield deattribute(a.data)),a});return function(){return a.apply(this,arguments)}})();function deObject(a,b){let c='';for(let d in a){let e=a[d];b&&(c+=`&${b}`),c+='object'==typeof e?`[${d}]${deObject(e)}`:`[${d}]=${e}`}return c}function query(a,b=!1){let c='';for(let d in a){let b=a[d];c+='object'==typeof b?deObject(b,d):`&${d}=${b}`}return c=encodeURI(c.slice(1)),a?b?`?${c}`:c:''}const requiresID=(a,b)=>`${a} requires an ID for the ${b} relationships`;let serialise=(()=>{var a=_asyncToGenerator(function*(a,b={},c='POST'){try{if(b.constructor!==Object||0===Object.keys(b).length)throw new Error(`${c} requires a JSON object body`);const d=this.plural(this.camel(a)),e={type:d};if('POST'!==c&&!b.id)throw new Error(`${c} requires an ID for the ${d} type`);for(let a in'POST'!==c&&(e.id=b.id.toString()),b)if(null!==b[a]&&b[a].constructor===Object){if('string'==typeof b[a].id)e.relationships||(e.relationships={}),b[a].type||(b[a].type=this.plural(this.camel(a))),e.relationships[a]={data:Object.assign(b[a])};else throw new Error(requiresID(c,a));}else if(null!==b[a]&&Array.isArray(b[a])){const d=this.plural(this.camel(a));e.relationships||(e.relationships={}),e.relationships[a]={data:b[a].map(function(b){if(!b.id)throw new Error(requiresID(c,a));return{id:b.id,type:b.type||d}})}}else'id'!==a&&'type'!==a&&(e.attributes||(e.attributes={}),e.attributes[a]=b[a]);return{data:e}}catch(a){throw error(a)}});return function(){return a.apply(this,arguments)}})();var index=a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase()),index$1=a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>'-'+a.toLowerCase()),index$2=a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>'_'+a.toLowerCase());exports.camel=index,exports.kebab=index$1,exports.snake=index$2,exports.deattribute=deattribute,exports.deserialise=deserialise,exports.error=error,exports.filterIncludes=filterIncludes,exports.linkRelationships=linkRelationships,exports.query=query,exports.serialise=serialise;
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator'));
function deattribute(){return _deattribute.apply(this,arguments)}function _deattribute(){return _deattribute=_asyncToGenerator(function*(a){return "object"==typeof a&&null!==a&&(Array.isArray(a)?yield a.map(function(){var a=_asyncToGenerator(function*(a){return deattribute(a)});return function(){return a.apply(this,arguments)}}()):a.attributes&&a.attributes.constructor===Object&&(Object.keys(a.attributes).forEach(b=>{a[b]=a.attributes[b];}),delete a.attributes)),a}),_deattribute.apply(this,arguments)}
function error(a){if(a.response){const b=a.response.data;b&&b.errors&&(a.errors=b.errors);}throw a}
function filterIncludes(){return _filterIncludes.apply(this,arguments)}function _filterIncludes(){return _filterIncludes=_asyncToGenerator(function*(a,{id:b,type:c}){try{const d=a.filter(a=>a.id===b&&a.type===c)[0]||{id:b,type:c};return Object.assign({},d)}catch(a){error(a);}}),_filterIncludes.apply(this,arguments)}
function link(){return _link.apply(this,arguments)}function _link(){return _link=_asyncToGenerator(function*({id:a,type:b,meta:c},d){const e=yield filterIncludes(d,{id:a,type:b});return e.relationships&&(yield linkRelationships(e,d)),c&&(e.meta=c),deattribute(e)}),_link.apply(this,arguments)}function linkArray(){return _linkArray.apply(this,arguments)}function _linkArray(){return _linkArray=_asyncToGenerator(function*(a,b,c){a[c]=[];var d=!0,e=!1,f=void 0;try{for(var g,h=(yield a.relationships[c].data)[Symbol.iterator]();!(d=(g=h.next()).done);d=!0){let d=g.value;a[c].push((yield link(d,b)));}}catch(a){e=!0,f=a;}finally{try{d||null==h.return||h.return();}finally{if(e)throw f}}}),_linkArray.apply(this,arguments)}function linkObject(){return _linkObject.apply(this,arguments)}function _linkObject(){return _linkObject=_asyncToGenerator(function*(a,b,c){a[c]=yield link(a.relationships[c].data,b),delete a[c].relationships;}),_linkObject.apply(this,arguments)}function linkRelationships(){return _linkRelationships.apply(this,arguments)}function _linkRelationships(){return _linkRelationships=_asyncToGenerator(function*(a,b){const c=a.relationships;let d=!1;for(let e in yield c)c[e].data&&Array.isArray(c[e].data)?(yield linkArray(a,b,e),d=!0):c[e].data&&(yield linkObject(a,b,e),d=!0);return d&&delete a.relationships,a}),_linkRelationships.apply(this,arguments)}
function deserialiseArray(){return _deserialiseArray.apply(this,arguments)}function _deserialiseArray(){return _deserialiseArray=_asyncToGenerator(function*(a){var b=!0,c=!1,d=void 0;try{for(var e,f=(yield a.data)[Symbol.iterator]();!(b=(e=f.next()).done);b=!0){let b=e.value;a.included&&(b=yield linkRelationships(b,a.included)),b.attributes&&(b=yield deattribute(b)),a.data[a.data.indexOf(b)]=b;}}catch(a){c=!0,d=a;}finally{try{b||null==f.return||f.return();}finally{if(c)throw d}}return a}),_deserialiseArray.apply(this,arguments)}function deserialise(){return _deserialise.apply(this,arguments)}function _deserialise(){return _deserialise=_asyncToGenerator(function*(a){return a.data&&a.data.constructor===Array?a=yield deserialiseArray(a):a.included&&(a.data=yield linkRelationships(a.data,a.included)),delete a.included,a.data&&a.data.attributes&&(a.data=yield deattribute(a.data)),a}),_deserialise.apply(this,arguments)}
function query(a,b=null){const c=[];for(const d in a)if(a.hasOwnProperty(d)){const e=b?`${b}[${d}]`:d,f=a[d];c.push(null!==f&&"object"==typeof f?query(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f));}return c.join("&")}
const requiresID=(a,b)=>`${a} requires an ID for the ${b} relationships`;function serialise(){return _serialise.apply(this,arguments)}function _serialise(){return _serialise=_asyncToGenerator(function*(a,b={},c="POST"){try{if(b.constructor!==Object||0===Object.keys(b).length)throw new Error(`${c} requires a JSON object body`);const d=this.plural(this.camel(a)),e={type:d};if("POST"!==c&&!b.id)throw new Error(`${c} requires an ID for the ${d} type`);for(let a in"POST"!==c&&(e.id=b.id.toString()),b)if(null!==b[a]&&b[a].constructor===Object){if("string"==typeof b[a].id)e.relationships||(e.relationships={}),b[a].type||(b[a].type=this.plural(this.camel(a))),e.relationships[a]={data:Object.assign(b[a])};else throw new Error(requiresID(c,a));}else if(null!==b[a]&&Array.isArray(b[a])){const d=this.plural(this.camel(a));e.relationships||(e.relationships={}),e.relationships[a]={data:b[a].map(b=>{if(!b.id)throw new Error(requiresID(c,a));return {id:b.id,type:b.type||d}})};}else"id"!=a&&"type"!=a&&(e.attributes||(e.attributes={}),e.attributes[a]=b[a]);return {data:e}}catch(a){throw error(a)}}),_serialise.apply(this,arguments)}
var index = (a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase()));
var index$1 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"-"+a.toLowerCase()));
var index$2 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"_"+a.toLowerCase()));
exports.camel = index;
exports.kebab = index$1;
exports.snake = index$2;
exports.deattribute = deattribute;
exports.deserialise = deserialise;
exports.error = error;
exports.filterIncludes = filterIncludes;
exports.linkRelationships = linkRelationships;
exports.query = query;
exports.serialise = serialise;
//# sourceMappingURL=index.js.map

11

package.json
{
"version": "5.2.2",
"version": "6.0.0",
"name": "kitsu-core",

@@ -36,4 +36,5 @@ "description": "Core serialisation and deserialsation functions for the kitsu JSON:API client",

},
"sideEffects": false,
"dependencies": {
"babel-runtime": "^6.26.0"
"@babel/runtime": "^7.0.0-rc.1"
},

@@ -43,13 +44,13 @@ "size-limit": [

"path": "./lib/index.js",
"limit": "10.2 kb"
"limit": "4.83 kb"
},
{
"path": "./legacy/index.js",
"limit": "12.2 kb"
"limit": "4.88 kb"
},
{
"path": "./node/index.js",
"limit": "7.6 kb"
"limit": "2.01 kb"
}
]
}

@@ -29,12 +29,8 @@ # Kitsu Core

| ------------------: | :----------------: | :--: | :----: | :-----: | :----: | :--: | :-: |
| `kitsu-core` | 10.1 kb | 6+ | 54+ | 48+ | 10+ | 14+ | |
| `kitsu-core/legacy` | 12 kb | 6+ | 4+ | 3.5+ | 3.2+ | 12+ | 8+ |
| `kitsu-core/node` | 7.4 kb | 6+ | | | | | |
| `kitsu-core` | 4.3 kb | 6+ | 54+ | 51+ | 10+ | 15+ | |
| `kitsu-core/legacy` | 4.4 kb | 6+ | 4+ | 3.5+ | 3.2+ | 12+ | 8+ |
| `kitsu-core/node` | 1.5 kb | 6+ | | | | | |
\* Including all dependencies, minified & gzipped
[default]: http://browserl.ist/?q=last+2+years%2C+not+%3C+0.05%25
[legacy]: http://browserl.ist/?q=last+10+years
## Install

@@ -274,3 +270,3 @@

- `params` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Parameters to parse
- `prefix` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Prefix returned string with `?` (default `false`) (optional, default `false`)
- `prefix` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Prefix for nested parameters - used internally (default `null`) (optional, default `null`)

@@ -277,0 +273,0 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** URL query string

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