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.0.3 to 5.0.4

48

CHANGELOG.md

@@ -0,1 +1,49 @@

#### 5.0.4 (2018-03-03)
##### Build System / Dependencies
* **kitsu:** fix size-limit errors (closes #138) (#141) (3b730f7a)
##### Chores
* **deps:**
* update documentation to ~6.0.0 (#142) (9faef85f)
* update documentation to ~5.5.0 (#140) (d2792aa3)
* lock file maintenance (#139) (56d69d9d)
* update axios to ^0.18.0 (#135) (ed426417)
* update jest to ~22.4.0 (#136) (7c6909c9)
* update axios-mock-adapter to ~1.14.0 (#134) (4790c559)
* update eslint to ~4.18.0 (#131) (4f2ac2fe)
* remove empty object in package.json (cde44b38)
* move test json:api cases to monorepo root (576a9d87)
* **kitsu-core:** build documentation (d642353a)
##### Documentation Changes
* **kitsu-core:**
* add examples for deserialise function (4d9197a7)
* add example for snake function (560196bd)
* add example for kebab function (eec0fecf)
* add example for deattribute function (89d9a401)
* add examples for camel function (05bf2d60)
* add serialise example with 5.0.x 'this' limitiation (8384c16e)
##### New Features
* **kitsu-core:** add prefix option to query function (c91e1f72)
##### Bug Fixes
* **kitsu-core:**
* slice first character of query before adding prefix (756748b3)
* check data object exists before deattributing it (8b5f7615)
##### Refactors
* **kitsu-core:** remove circular imports (f733d729)
##### Tests
* namespace package tests (8c22d35c)
#### 5.0.3 (2018-02-16)

@@ -2,0 +50,0 @@

2

legacy/index.js

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

(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){var b='',d=function(d){'object'===c(a[d])?Object.keys(a[d]).forEach(function(c){b+='&'+d+'['+c+']='+a[d][c]}):b+='&'+d+'='+a[d]};for(var e in a)d(e);return a?b.slice(1):''}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 g=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',g(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)}}(),h=function(){var a=d(b.mark(function a(c){var d,e,f,h,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,h=a.sent[a.t0]();case 8:if(d=(i=h.next()).done){a.next=22;break}if(j=i.value,!c.included){a.next=14;break}return a.next=13,n(j,c.included);case 13:j=a.sent;case 14:if(!j.attributes){a.next=18;break}return a.next=17,g(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&&h.return&&h.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)}}(),i=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,h(c);case 3:c=a.sent,a.next=10;break;case 6:if(!c.included){a.next=10;break}return a.next=9,n(c.data,c.included);case 9:c.data=a.sent;case 10:if(delete c.included,!c.data.attributes){a.next=15;break}return a.next=14,g(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)}}(),j=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)}}(),k=function(){var a=d(b.mark(function a(c,d){var e,f=c.id,h=c.type,i=c.meta;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,j(d,{id:f,type:h});case 2:if(e=a.sent,!e.relationships){a.next=6;break}return a.next=6,n(e,d);case 6:return i&&(e.meta=i),a.abrupt('return',g(e));case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),l=function(){var a=d(b.mark(function a(c,d,e){var f,g,h,i,j,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=(j=i.next()).done){a.next=19;break}return l=j.value,a.t1=c[e],a.next=14,k(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)}}(),m=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,k(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)}}(),n=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,l(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,m(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)}}(),o=function(a,b){return a+' requires an ID for the '+b+' relationships'},p=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(o(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(o(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=g,a.deserialise=i,a.error=e,a.filterIncludes=j,a.linkRelationships=n,a.query=f,a.serialise=p,Object.defineProperty(a,'__esModule',{value:!0})});
(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){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],d='',e=function(b){'object'===c(a[b])?Object.keys(a[b]).forEach(function(c){d+='&'+b+'['+c+']='+a[b][c]}):d+='&'+b+'='+a[b]};for(var f in a)e(f);return d=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 g=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',g(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)}}(),h=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)}}(),i=function(){var a=d(b.mark(function a(c,d){var e,f=c.id,i=c.type,j=c.meta;return b.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,h(d,{id:f,type:i});case 2:if(e=a.sent,!e.relationships){a.next=6;break}return a.next=6,l(e,d);case 6:return j&&(e.meta=j),a.abrupt('return',g(e));case 8:case'end':return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),j=function(){var a=d(b.mark(function a(c,d,e){var f,g,h,j,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,j=a.sent[a.t0]();case 9:if(f=(k=j.next()).done){a.next=19;break}return l=k.value,a.t1=c[e],a.next=14,i(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&&j.return&&j.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)}}(),k=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,i(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)}}(),l=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,j(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,k(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)}}(),m=function(){var a=d(b.mark(function a(c){var d,e,f,h,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,h=a.sent[a.t0]();case 8:if(d=(i=h.next()).done){a.next=22;break}if(j=i.value,!c.included){a.next=14;break}return a.next=13,l(j,c.included);case 13:j=a.sent;case 14:if(!j.attributes){a.next=18;break}return a.next=17,g(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&&h.return&&h.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)}}(),n=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,m(c);case 3:c=a.sent,a.next=10;break;case 6:if(!c.included){a.next=10;break}return a.next=9,l(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,g(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)}}(),o=function(a,b){return a+' requires an ID for the '+b+' relationships'},p=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(o(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(o(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=g,a.deserialise=n,a.error=e,a.filterIncludes=h,a.linkRelationships=l,a.query=f,a.serialise=p,Object.defineProperty(a,'__esModule',{value:!0})});
//# sourceMappingURL=index.js.map

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

'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=function(){var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c=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(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,c)}));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)}));return function(){return a.apply(this,arguments)}}(),deserialiseArray=function(){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$$1(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$$1=function(){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$$1(b.data,b.included);case 9:b.data=a.sent;case 10:if(delete b.included,!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 error(a){if(a.response){var b=a.response.data;b&&b.errors&&(a.errors=b.errors)}throw a}var filterIncludes$$1=function(){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=function(){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$$1(c,{id:e,type:f});case 2:if(d=a.sent,!d.relationships){a.next=6;break}return a.next=6,linkRelationships$$1(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=function(){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=function(){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$$1=function(){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)}}();function query(a){var b='',c=function(c){'object'==typeof a[c]?Object.keys(a[c]).forEach(function(d){b+=`&${c}[${d}]=${a[c][d]}`}):b+=`&${c}=${a[c]}`};for(var d in a)c(d);return a?b.slice(1):''}var requiresID=function(a,b){return`${a} requires an ID for the ${b} relationships`},serialise$$1=function(){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=function(a){return a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(a){return a.slice(1).toUpperCase()})},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()})},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$$1,exports.error=error,exports.filterIncludes=filterIncludes$$1,exports.linkRelationships=linkRelationships$$1,exports.query=query,exports.serialise=serialise$$1;
'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=function(){var a=_asyncToGenerator(_regeneratorRuntime.mark(function a(b){var c=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(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,c)}));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)}));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=function(){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=function(){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=function(){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=function(){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=function(){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=function(){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=function(){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 query(a){var b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1],c='',d=function(b){'object'==typeof a[b]?Object.keys(a[b]).forEach(function(d){c+=`&${b}[${d}]=${a[b][d]}`}):c+=`&${b}=${a[b]}`};for(var e in a)d(e);return c=c.slice(1),a?b?`?${c}`:c:''}var requiresID=function(a,b){return`${a} requires an ID for the ${b} relationships`},serialise=function(){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=function(a){return a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(a){return a.slice(1).toUpperCase()})},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()})},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;
//# sourceMappingURL=index.js.map

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

'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)}})(),deserialiseArray=(()=>{var a=_asyncToGenerator(function*(a){var b,c=!0,d=!1;try{for(var e,f=(yield a.data)[Symbol.iterator]();!(c=(e=f.next()).done);c=!0){let b=e.value;a.included&&(b=yield linkRelationships$$1(b,a.included)),b.attributes&&(b=yield deattribute(b)),a.data[a.data.indexOf(b)]=b}}catch(a){d=!0,b=a}finally{try{!c&&f.return&&f.return()}finally{if(d)throw b}}return a});return function(){return a.apply(this,arguments)}})(),deserialise$$1=(()=>{var a=_asyncToGenerator(function*(a){return a.data&&a.data.constructor===Array?a=yield deserialiseArray(a):a.included&&(a.data=yield linkRelationships$$1(a.data,a.included)),delete a.included,a.data.attributes&&(a.data=yield deattribute(a.data)),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$$1=(()=>{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$$1(d,{id:a,type:b});return e.relationships&&(yield linkRelationships$$1(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,e=!0,f=!1;try{for(var g,h=(yield a.relationships[c].data)[Symbol.iterator]();!(e=(g=h.next()).done);e=!0){let d=g.value;a[c].push((yield link(d,b)))}}catch(a){f=!0,d=a}finally{try{!e&&h.return&&h.return()}finally{if(f)throw d}}});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$$1=(()=>{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)}})();function query(a){let b='';for(let c in a)'object'==typeof a[c]?Object.keys(a[c]).forEach((d)=>{b+=`&${c}[${d}]=${a[c][d]}`}):b+=`&${c}=${a[c]}`;return a?b.slice(1):''}const requiresID=(a,b)=>`${a} requires an ID for the ${b} relationships`;let serialise$$1=(()=>{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$$1,exports.error=error,exports.filterIncludes=filterIncludes$$1,exports.linkRelationships=linkRelationships$$1,exports.query=query,exports.serialise=serialise$$1;
'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,e=!0,f=!1;try{for(var g,h=(yield a.relationships[c].data)[Symbol.iterator]();!(e=(g=h.next()).done);e=!0){let d=g.value;a[c].push((yield link(d,b)))}}catch(a){f=!0,d=a}finally{try{!e&&h.return&&h.return()}finally{if(f)throw d}}});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,c=!0,d=!1;try{for(var e,f=(yield a.data)[Symbol.iterator]();!(c=(e=f.next()).done);c=!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){d=!0,b=a}finally{try{!c&&f.return&&f.return()}finally{if(d)throw b}}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 query(a,b=!1){let c='';for(let d in a)'object'==typeof a[d]?Object.keys(a[d]).forEach((b)=>{c+=`&${d}[${b}]=${a[d][b]}`}):c+=`&${d}=${a[d]}`;return c=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;
//# sourceMappingURL=index.js.map
{
"version": "5.0.3",
"version": "5.0.4",
"name": "kitsu-core",

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

@@ -28,4 +28,4 @@ # Kitsu Core

| ------------------: | :----------------: | :--: | :----: | :-----: | :----: | :--: | :-: |
| `kitsu-core` | 9.9 kb | 6+ | 49+ | 47+ | 9.1+ | 14+ | |
| `kitsu-core/legacy` | 11.9 kb | 6+ | 4+ | 3+ | 3.1+ | 12+ | 8+ |
| `kitsu-core` | 9.9 kb | 6+ | 51+ | 47+ | 9.1+ | 14+ | |
| `kitsu-core/legacy` | 11.8 kb | 6+ | 4+ | 3+ | 3.1+ | 12+ | 8+ |
| `kitsu-core/node` | 7.2 kb | 6+ | | | | | |

@@ -97,2 +97,16 @@

**Examples**
_Convert kebab-case_
```javascript
camel('hello-world') // 'helloWorld'
```
_Convert snake_case_
```javascript
camel('hello_world') // 'helloWorld'
```
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase formatted string

@@ -108,2 +122,32 @@

**Examples**
_Deattribute an array of resources_
```javascript
// JSON:API 'data' field
const data = [
{
id: '1',
type: 'users',
attributes: { slug: 'wopian' }
}
]
const output = await deattribute(data) // [ { id: '1', type: 'users', slug: 'wopian' } ]
```
_Deattribute a resource_
```javascript
// JSON:API 'data' field
const data = {
id: '1',
type: 'users',
attributes: { slug: 'wopian' }
}
const output = await deattribute(data) // { id: '1', type: 'users', slug: 'wopian' }
```
Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** Deattributed resource data

@@ -113,3 +157,3 @@

Deserialises an object from a JSON-API structure
Deserialises a JSON-API response

@@ -120,2 +164,40 @@ **Parameters**

**Examples**
_Deserialise with a basic data object_
```javascript
await deserialise({
data: {
id: '1',
attributes: { liked: true }
},
meta: { hello: 'world' }
}) // { data: { id: '1', liked: true }, meta: { hello: 'world' } }
```
_Deserialise with relationships_
```javascript
await deserialise({
data: {
id: '1',
relationships: {
user: {
data: {
type: 'users',
id: '2' }
}
}
},
included: [
{
type: 'users',
id: '2',
attributes: { slug: 'wopian' }
}
]
}) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } }
```
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The deserialised response

@@ -155,2 +237,8 @@

**Examples**
```javascript
kebab('helloWorld') // 'hello-world'
```
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** kekab-case formatted string

@@ -174,2 +262,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`)

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

**Examples**
_Due to its usage in kitsu, it **MUST** be called with **this** set in 5.0.x_
```javascript
import { serialise, camel, kebab } from 'kitsu-core'
import plural from 'pluralize'
const output = await serialise.apply({ camel, resCase: kebab, plural }, [ model, obj, 'PATCH' ])
```
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The serialised data

@@ -199,2 +299,8 @@

**Examples**
```javascript
snake('helloWorld') // 'hello_world'
```
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** snake_case formatted string

@@ -220,3 +326,3 @@

[changelog]: https://github.com/wopian/kitsu/blob/lerna/packages/kitsu-core/CHANGELOG.md
[changelog]: https://github.com/wopian/kitsu/blob/master/packages/kitsu-core/CHANGELOG.md

@@ -223,0 +329,0 @@ [contributing]: https://github.com/wopian/kitsu/blob/master/CONTRIBUTING.md

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

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

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