kitsu-core
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -0,1 +1,31 @@ | ||
### 6.2.0 (2018-08-14) | ||
##### Build System / Dependencies | ||
* update devdependency lerna to ~3.0.0 (#195) (6d599022) | ||
* update devdependency jest to ~23.5.0 (#194) (292345fd) | ||
##### Chores | ||
* remove todos in rollup configs (410b20b5) | ||
* remove legacy @babel/runtime dependencies (03056f80) | ||
* remove redundent package.json script (7e182d77) | ||
* update npmignore (6afa4d09) | ||
* remove need for sourcemaps No longer minifies lib/node files to 1-line. (1b37fbd3) | ||
* remove legacy bundles They haven't seen any usage and are causing unneccessary package size bloat. (df084d21) | ||
##### Documentation Changes | ||
* link to coverage, maintainability & debt pages in codeclimate badges (f267c03e) | ||
* format READMEs (d4b23845) | ||
* restore itallic text for migration guide notices (e9a764eb) | ||
* fix links in READMEs (ef629c92) | ||
* use source order for API documentation (8e3d2bb9) | ||
* update README to 6.x (436644d1) | ||
* switch codeclimate and contributor badges to badgen (ef56b765) | ||
##### Refactors | ||
* **kitsu-core:** reduce query's cognitive complexity (fb167b2e) | ||
### 6.1.0 (2018-08-10) | ||
@@ -2,0 +32,0 @@ |
525
lib/index.js
@@ -10,22 +10,526 @@ 'use strict'; | ||
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 deattribute() { | ||
return _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 _deattribute() { | ||
return _deattribute = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data) { | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (_context2.t0 = 'object' === typeof data && null !== data, !_context2.t0) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
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)} | ||
if (!Array.isArray(data)) { | ||
_context2.next = 7; | ||
break; | ||
} | ||
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)} | ||
return _context2.next = 5, data.map(function () { | ||
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(el) { | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", deattribute(el)); | ||
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)} | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})); | ||
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("&")} | ||
return function () { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
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)} | ||
case 5: | ||
_context2.next = 8; | ||
break; | ||
var index = (a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase())); | ||
case 7: | ||
data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes); | ||
var index$1 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"-"+a.toLowerCase())); | ||
case 8: | ||
return _context2.abrupt("return", data); | ||
var index$2 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"_"+a.toLowerCase())); | ||
case 9: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})), _deattribute.apply(this, arguments); | ||
} | ||
function error(E) { | ||
if (E.response) { | ||
const e = E.response.data; | ||
e && e.errors && (E.errors = e.errors); | ||
} | ||
throw E; | ||
} | ||
function filterIncludes() { | ||
return _filterIncludes.apply(this, arguments); | ||
} | ||
function _filterIncludes() { | ||
return _filterIncludes = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(included, _ref) { | ||
var id, type, filtered; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, _context.prev = 1, filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}, _context.abrupt("return", Object.assign({}, filtered)); | ||
case 6: | ||
_context.prev = 6, _context.t0 = _context["catch"](1), error(_context.t0); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[1, 6]]); | ||
})), _filterIncludes.apply(this, arguments); | ||
} | ||
function link() { | ||
return _link.apply(this, arguments); | ||
} | ||
function _link() { | ||
return _link = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref, included) { | ||
var id, type, meta, filtered; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, meta = _ref.meta, _context.next = 3, filterIncludes(included, { | ||
id, | ||
type | ||
}); | ||
case 3: | ||
if (filtered = _context.sent, _context.t0 = filtered.relationships, !_context.t0) { | ||
_context.next = 8; | ||
break; | ||
} | ||
return _context.next = 8, linkRelationships(filtered, included); | ||
case 8: | ||
return meta && (filtered.meta = meta), _context.abrupt("return", deattribute(filtered)); | ||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})), _link.apply(this, arguments); | ||
} | ||
function linkArray() { | ||
return _linkArray.apply(this, arguments); | ||
} | ||
function _linkArray() { | ||
return _linkArray = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data, included, key) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, resource; | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return data[key] = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context2.prev = 2, _context2.next = 5, data.relationships[key].data; | ||
case 5: | ||
_context2.t0 = Symbol.iterator, _iterator = _context2.sent[_context2.t0](); | ||
case 7: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
return resource = _step.value, _context2.t1 = data[key], _context2.next = 12, link(resource, included); | ||
case 12: | ||
_context2.t2 = _context2.sent, _context2.t1.push.call(_context2.t1, _context2.t2); | ||
case 14: | ||
_iteratorNormalCompletion = !0, _context2.next = 7; | ||
break; | ||
case 17: | ||
_context2.next = 22; | ||
break; | ||
case 19: | ||
_context2.prev = 19, _context2.t3 = _context2["catch"](2), _didIteratorError = !0, _iteratorError = _context2.t3; | ||
case 22: | ||
_context2.prev = 22, _context2.prev = 23, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 25: | ||
if (_context2.prev = 25, !_didIteratorError) { | ||
_context2.next = 28; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 28: | ||
return _context2.finish(25); | ||
case 29: | ||
return _context2.finish(22); | ||
case 30: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[2, 19, 22, 30], [23,, 25, 29]]); | ||
})), _linkArray.apply(this, arguments); | ||
} | ||
function linkObject() { | ||
return _linkObject.apply(this, arguments); | ||
} | ||
function _linkObject() { | ||
return _linkObject = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(data, included, key) { | ||
return _regeneratorRuntime.wrap(function (_context3) { | ||
for (;;) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.next = 2, link(data.relationships[key].data, included); | ||
case 2: | ||
data[key] = _context3.sent, delete data[key].relationships; | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3, this); | ||
})), _linkObject.apply(this, arguments); | ||
} | ||
function linkRelationships() { | ||
return _linkRelationships.apply(this, arguments); | ||
} | ||
function _linkRelationships() { | ||
return _linkRelationships = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(data, included) { | ||
var relationships, removeRelationships, key; | ||
return _regeneratorRuntime.wrap(function (_context4) { | ||
for (;;) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return relationships = data.relationships, removeRelationships = !1, _context4.next = 4, relationships; | ||
case 4: | ||
_context4.t0 = _regeneratorRuntime.keys(_context4.sent); | ||
case 5: | ||
if ((_context4.t1 = _context4.t0()).done) { | ||
_context4.next = 20; | ||
break; | ||
} | ||
if (key = _context4.t1.value, !(relationships[key].data && Array.isArray(relationships[key].data))) { | ||
_context4.next = 13; | ||
break; | ||
} | ||
return _context4.next = 10, linkArray(data, included, key); | ||
case 10: | ||
removeRelationships = !0, _context4.next = 18; | ||
break; | ||
case 13: | ||
if (_context4.t2 = relationships[key].data, !_context4.t2) { | ||
_context4.next = 18; | ||
break; | ||
} | ||
return _context4.next = 17, linkObject(data, included, key); | ||
case 17: | ||
removeRelationships = !0; | ||
case 18: | ||
_context4.next = 5; | ||
break; | ||
case 20: | ||
return _context4.abrupt("return", (removeRelationships && delete data.relationships, data)); | ||
case 21: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4, this); | ||
})), _linkRelationships.apply(this, arguments); | ||
} | ||
function deserialiseArray() { | ||
return _deserialiseArray.apply(this, arguments); | ||
} | ||
function _deserialiseArray() { | ||
return _deserialiseArray = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, value; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context.prev = 1, _context.next = 4, obj.data; | ||
case 4: | ||
_context.t0 = Symbol.iterator, _iterator = _context.sent[_context.t0](); | ||
case 6: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 22; | ||
break; | ||
} | ||
if (value = _step.value, _context.t1 = obj.included, !_context.t1) { | ||
_context.next = 13; | ||
break; | ||
} | ||
return _context.next = 12, linkRelationships(value, obj.included); | ||
case 12: | ||
value = _context.sent; | ||
case 13: | ||
if (_context.t2 = value.attributes, !_context.t2) { | ||
_context.next = 18; | ||
break; | ||
} | ||
return _context.next = 17, deattribute(value); | ||
case 17: | ||
value = _context.sent; | ||
case 18: | ||
obj.data[obj.data.indexOf(value)] = value; | ||
case 19: | ||
_iteratorNormalCompletion = !0, _context.next = 6; | ||
break; | ||
case 22: | ||
_context.next = 27; | ||
break; | ||
case 24: | ||
_context.prev = 24, _context.t3 = _context["catch"](1), _didIteratorError = !0, _iteratorError = _context.t3; | ||
case 27: | ||
_context.prev = 27, _context.prev = 28, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 30: | ||
if (_context.prev = 30, !_didIteratorError) { | ||
_context.next = 33; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 33: | ||
return _context.finish(30); | ||
case 34: | ||
return _context.finish(27); | ||
case 35: | ||
return _context.abrupt("return", obj); | ||
case 36: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[1, 24, 27, 35], [28,, 30, 34]]); | ||
})), _deserialiseArray.apply(this, arguments); | ||
} | ||
function deserialise() { | ||
return _deserialise.apply(this, arguments); | ||
} | ||
function _deserialise() { | ||
return _deserialise = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj) { | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(obj.data && obj.data.constructor === Array)) { | ||
_context2.next = 6; | ||
break; | ||
} | ||
return _context2.next = 3, deserialiseArray(obj); | ||
case 3: | ||
obj = _context2.sent, _context2.next = 11; | ||
break; | ||
case 6: | ||
if (_context2.t0 = obj.included, !_context2.t0) { | ||
_context2.next = 11; | ||
break; | ||
} | ||
return _context2.next = 10, linkRelationships(obj.data, obj.included); | ||
case 10: | ||
obj.data = _context2.sent; | ||
case 11: | ||
if (delete obj.included, _context2.t1 = obj.data && obj.data.attributes, !_context2.t1) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
return _context2.next = 16, deattribute(obj.data); | ||
case 16: | ||
obj.data = _context2.sent; | ||
case 17: | ||
return _context2.abrupt("return", obj); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})), _deserialise.apply(this, arguments); | ||
} | ||
function queryFormat(value, key) { | ||
return null !== value && 'object' === typeof value ? query(value, key) : encodeURIComponent(key) + '=' + encodeURIComponent(value); | ||
} | ||
function query(params) { | ||
let prefix = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : null; | ||
const str = []; | ||
for (const param in params) params.hasOwnProperty(param) && str.push(queryFormat(params[param], prefix ? `${prefix}[${param}]` : param)); | ||
return str.join('&'); | ||
} | ||
const requiresID = (method, key) => `${method} requires an ID for the ${key} relationships`; | ||
function serialise() { | ||
return _serialise.apply(this, arguments); | ||
} | ||
function _serialise() { | ||
return _serialise = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(model) { | ||
var obj, | ||
method, | ||
type, | ||
data, | ||
key, | ||
keytype, | ||
_args = arguments; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (obj = 1 < _args.length && void 0 !== _args[1] ? _args[1] : {}, method = 2 < _args.length && void 0 !== _args[2] ? _args[2] : 'POST', _context.prev = 1, obj.constructor === Object && 0 !== Object.keys(obj).length) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw new Error(`${method} requires a JSON object body`); | ||
case 4: | ||
if (type = this.plural(this.camel(model)), data = { | ||
type | ||
}, 'POST' === method || obj.id) { | ||
_context.next = 7; | ||
break; | ||
} | ||
throw new Error(`${method} requires an ID for the ${type} type`); | ||
case 7: | ||
_context.t0 = _regeneratorRuntime.keys(('POST' !== method && (data.id = obj.id.toString()), obj)); | ||
case 8: | ||
if ((_context.t1 = _context.t0()).done) { | ||
_context.next = 21; | ||
break; | ||
} | ||
if (key = _context.t1.value, null === obj[key] || obj[key].constructor !== Object) { | ||
_context.next = 18; | ||
break; | ||
} | ||
if ('string' !== typeof obj[key].id) { | ||
_context.next = 15; | ||
break; | ||
} | ||
data.relationships || (data.relationships = {}), obj[key].type || (obj[key].type = this.plural(this.camel(key))), data.relationships[key] = { | ||
data: Object.assign(obj[key]) | ||
}, _context.next = 16; | ||
break; | ||
case 15: | ||
throw new Error(requiresID(method, key)); | ||
case 16: | ||
_context.next = 19; | ||
break; | ||
case 18: | ||
null !== obj[key] && Array.isArray(obj[key]) ? (keytype = this.plural(this.camel(key)), data.relationships || (data.relationships = {}), data.relationships[key] = { | ||
data: obj[key].map(elem => { | ||
if (!elem.id) throw new Error(requiresID(method, key)); | ||
return { | ||
id: elem.id, | ||
type: elem.type || keytype | ||
}; | ||
}) | ||
}) : 'id' !== key && 'type' !== key && (data.attributes || (data.attributes = {}), data.attributes[key] = obj[key]); | ||
case 19: | ||
_context.next = 8; | ||
break; | ||
case 21: | ||
return _context.abrupt("return", { | ||
data | ||
}); | ||
case 24: | ||
throw _context.prev = 24, _context.t2 = _context["catch"](1), error(_context.t2); | ||
case 27: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[1, 24]]); | ||
})), _serialise.apply(this, arguments); | ||
} | ||
var index = (s => s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g, match => match.slice(1).toUpperCase())); | ||
var index$1 = (s => s.charAt(0).toLowerCase() + s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase())); | ||
var index$2 = (s => s.charAt(0).toLowerCase() + s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '_' + match.toLowerCase())); | ||
exports.camel = index; | ||
@@ -41,2 +545,1 @@ exports.kebab = index$1; | ||
exports.serialise = serialise; | ||
//# sourceMappingURL=index.js.map |
@@ -9,22 +9,223 @@ 'use strict'; | ||
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 deattribute() { | ||
return _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 _deattribute() { | ||
return _deattribute = _asyncToGenerator(function* (data) { | ||
return 'object' === typeof data && null !== data && (Array.isArray(data) ? yield data.map(function () { | ||
var _ref = _asyncToGenerator(function* (el) { | ||
return deattribute(el); | ||
}); | ||
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)} | ||
return function () { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()) : data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes)), data; | ||
}), _deattribute.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 error(E) { | ||
if (E.response) { | ||
const e = E.response.data; | ||
e && e.errors && (E.errors = e.errors); | ||
} | ||
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)} | ||
throw E; | ||
} | ||
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("&")} | ||
function filterIncludes() { | ||
return _filterIncludes.apply(this, arguments); | ||
} | ||
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)} | ||
function _filterIncludes() { | ||
return _filterIncludes = _asyncToGenerator(function* (included, { | ||
id, | ||
type | ||
}) { | ||
try { | ||
const filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}; | ||
return Object.assign({}, filtered); | ||
} catch (E) { | ||
error(E); | ||
} | ||
}), _filterIncludes.apply(this, arguments); | ||
} | ||
var index = (a=>a.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,a=>a.slice(1).toUpperCase())); | ||
function link() { | ||
return _link.apply(this, arguments); | ||
} | ||
var index$1 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"-"+a.toLowerCase())); | ||
function _link() { | ||
return _link = _asyncToGenerator(function* ({ | ||
id, | ||
type, | ||
meta | ||
}, included) { | ||
const filtered = yield filterIncludes(included, { | ||
id, | ||
type | ||
}); | ||
return filtered.relationships && (yield linkRelationships(filtered, included)), meta && (filtered.meta = meta), deattribute(filtered); | ||
}), _link.apply(this, arguments); | ||
} | ||
var index$2 = (a=>a.charAt(0).toLowerCase()+a.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,a=>"_"+a.toLowerCase())); | ||
function linkArray() { | ||
return _linkArray.apply(this, arguments); | ||
} | ||
function _linkArray() { | ||
return _linkArray = _asyncToGenerator(function* (data, included, key) { | ||
data[key] = []; | ||
var _iteratorNormalCompletion = !0, | ||
_didIteratorError = !1, | ||
_iteratorError = void 0; | ||
try { | ||
for (var _step, _iterator = (yield data.relationships[key].data)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { | ||
let resource = _step.value; | ||
data[key].push((yield link(resource, included))); | ||
} | ||
} catch (err) { | ||
_didIteratorError = !0, _iteratorError = err; | ||
} finally { | ||
try { | ||
_iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
} finally { | ||
if (_didIteratorError) throw _iteratorError; | ||
} | ||
} | ||
}), _linkArray.apply(this, arguments); | ||
} | ||
function linkObject() { | ||
return _linkObject.apply(this, arguments); | ||
} | ||
function _linkObject() { | ||
return _linkObject = _asyncToGenerator(function* (data, included, key) { | ||
data[key] = yield link(data.relationships[key].data, included), delete data[key].relationships; | ||
}), _linkObject.apply(this, arguments); | ||
} | ||
function linkRelationships() { | ||
return _linkRelationships.apply(this, arguments); | ||
} | ||
function _linkRelationships() { | ||
return _linkRelationships = _asyncToGenerator(function* (data, included) { | ||
const relationships = data.relationships; | ||
let removeRelationships = !1; | ||
for (let key in yield relationships) relationships[key].data && Array.isArray(relationships[key].data) ? (yield linkArray(data, included, key), removeRelationships = !0) : relationships[key].data && (yield linkObject(data, included, key), removeRelationships = !0); | ||
return removeRelationships && delete data.relationships, data; | ||
}), _linkRelationships.apply(this, arguments); | ||
} | ||
function deserialiseArray() { | ||
return _deserialiseArray.apply(this, arguments); | ||
} | ||
function _deserialiseArray() { | ||
return _deserialiseArray = _asyncToGenerator(function* (obj) { | ||
var _iteratorNormalCompletion = !0, | ||
_didIteratorError = !1, | ||
_iteratorError = void 0; | ||
try { | ||
for (var _step, _iterator = (yield obj.data)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { | ||
let value = _step.value; | ||
obj.included && (value = yield linkRelationships(value, obj.included)), value.attributes && (value = yield deattribute(value)), obj.data[obj.data.indexOf(value)] = value; | ||
} | ||
} catch (err) { | ||
_didIteratorError = !0, _iteratorError = err; | ||
} finally { | ||
try { | ||
_iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
} finally { | ||
if (_didIteratorError) throw _iteratorError; | ||
} | ||
} | ||
return obj; | ||
}), _deserialiseArray.apply(this, arguments); | ||
} | ||
function deserialise() { | ||
return _deserialise.apply(this, arguments); | ||
} | ||
function _deserialise() { | ||
return _deserialise = _asyncToGenerator(function* (obj) { | ||
return obj.data && obj.data.constructor === Array ? obj = yield deserialiseArray(obj) : obj.included && (obj.data = yield linkRelationships(obj.data, obj.included)), delete obj.included, obj.data && obj.data.attributes && (obj.data = yield deattribute(obj.data)), obj; | ||
}), _deserialise.apply(this, arguments); | ||
} | ||
function queryFormat(value, key) { | ||
return null !== value && 'object' === typeof value ? query(value, key) : encodeURIComponent(key) + '=' + encodeURIComponent(value); | ||
} | ||
function query(params, prefix = null) { | ||
const str = []; | ||
for (const param in params) params.hasOwnProperty(param) && str.push(queryFormat(params[param], prefix ? `${prefix}[${param}]` : param)); | ||
return str.join('&'); | ||
} | ||
const requiresID = (method, key) => `${method} requires an ID for the ${key} relationships`; | ||
function serialise() { | ||
return _serialise.apply(this, arguments); | ||
} | ||
function _serialise() { | ||
return _serialise = _asyncToGenerator(function* (model, obj = {}, method = 'POST') { | ||
try { | ||
if (obj.constructor !== Object || 0 === Object.keys(obj).length) throw new Error(`${method} requires a JSON object body`); | ||
const type = this.plural(this.camel(model)), | ||
data = { | ||
type | ||
}; | ||
if ('POST' !== method && !obj.id) throw new Error(`${method} requires an ID for the ${type} type`); | ||
for (let key in 'POST' !== method && (data.id = obj.id.toString()), obj) if (null !== obj[key] && obj[key].constructor === Object) { | ||
if ('string' === typeof obj[key].id) data.relationships || (data.relationships = {}), obj[key].type || (obj[key].type = this.plural(this.camel(key))), data.relationships[key] = { | ||
data: Object.assign(obj[key]) | ||
};else throw new Error(requiresID(method, key)); | ||
} else if (null !== obj[key] && Array.isArray(obj[key])) { | ||
const keytype = this.plural(this.camel(key)); | ||
data.relationships || (data.relationships = {}), data.relationships[key] = { | ||
data: obj[key].map(elem => { | ||
if (!elem.id) throw new Error(requiresID(method, key)); | ||
return { | ||
id: elem.id, | ||
type: elem.type || keytype | ||
}; | ||
}) | ||
}; | ||
} else 'id' !== key && 'type' !== key && (data.attributes || (data.attributes = {}), data.attributes[key] = obj[key]); | ||
return { | ||
data | ||
}; | ||
} catch (E) { | ||
throw error(E); | ||
} | ||
}), _serialise.apply(this, arguments); | ||
} | ||
var index = (s => s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g, match => match.slice(1).toUpperCase())); | ||
var index$1 = (s => s.charAt(0).toLowerCase() + s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '-' + match.toLowerCase())); | ||
var index$2 = (s => s.charAt(0).toLowerCase() + s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g, match => '_' + match.toLowerCase())); | ||
exports.camel = index; | ||
@@ -40,2 +241,1 @@ exports.kebab = index$1; | ||
exports.serialise = serialise; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"name": "kitsu-core", | ||
@@ -33,3 +33,3 @@ "description": "Core serialisation and deserialsation functions for the kitsu JSON:API client", | ||
"docs:lint": "documentation lint src/index.js", | ||
"docs:build": "documentation readme src/index.js --section=API --sort-order alpha", | ||
"docs:build": "documentation readme src/index.js --section=API -g true --sort-order source", | ||
"rollup": "cross-env NODE_ENV=production rollup -c --environment BUILD:production", | ||
@@ -52,6 +52,2 @@ "build": "yarn rollup" | ||
{ | ||
"path": "./legacy/index.js", | ||
"limit": "4.63 kb" | ||
}, | ||
{ | ||
"path": "./node/index.js", | ||
@@ -58,0 +54,0 @@ "limit": "1.75 kb" |
249
README.md
@@ -1,21 +0,34 @@ | ||
# Kitsu Core | ||
<h1 align=center>Kitsu Core</h1> | ||
[![npm badge]][npm] | ||
[![bundlephobia badge]][bundlephobia] | ||
[![npm install badge]][npm] | ||
[![david badge]][david] | ||
[![contributors badge]][contributors] | ||
[![donate badge]][donate] | ||
<p align=center> | ||
<a href=https://www.npmjs.com/package/kitsu-core><img alt=npm src=https://flat.badgen.net/npm/v/kitsu-core></a> | ||
<a href=https://www.npmjs.com/package/kitsu-core><img alt=npm src=https://flat.badgen.net/npm/dt/kitsu-core></a> | ||
<a href="https://bundlephobia.com/result?p=kitsu-core"><img alt=bundlephobia src=https://flat.badgen.net/bundlephobia/minzip/kitsu-core></a> | ||
<a href="https://david-dm.org/wopian/kitsu?path=packages/kitsu-core"><img alt=deps src="https://david-dm.org/wopian/kitsu/status.svg?path=packages/kitsu-core&style=flat-square"></a> | ||
</p> | ||
[![travis badge]][travis] | ||
[![appveyor badge]][appveyor] | ||
[![david dev badge]][david dev] | ||
[![cc maintainability badge]][cc maintainability] | ||
[![cc coverage badge]][cc coverage] | ||
[![packagephobia badge]][packagephobia] | ||
<p align=center> | ||
<a href=https://travis-ci.org/wopian/kitsu><img alt=travis src=https://flat.badgen.net/travis/wopian/kitsu></a> | ||
<a href=https://ci.appveyor.com/project/wopian/kitsu><img alt=appveyor src=https://flat.badgen.net/appveyor/ci/wopian/kitsu></a> | ||
<a href="https://packagephobia.now.sh/result?p=kitsu-core"><img alt=packagephobia src=https://flat.badgen.net/packagephobia/install/kitsu-core></a> | ||
<a href=https://github.com/wopian/kitsu/graphs/contributors><img alt=contributors src=https://flat.badgen.net/github/contributors/wopian/kitsu></a> | ||
</p> | ||
Core [JSON:API] serialisation and deserialisation components for [kitsu] | ||
<p align=center> | ||
<a href=https://codeclimate.com/github/wopian/kitsu/code?sort=test_coverage><img alt=coverage src=https://flat.badgen.net/codeclimate/coverage/wopian/kitsu></a> | ||
<a href=https://codeclimate.com/github/wopian/kitsu/code?sort=maintainability><img alt=maintainability src=https://flat.badgen.net/codeclimate/maintainability/wopian/kitsu></a> | ||
<a href=https://codeclimate.com/github/wopian/kitsu/trends/technical_debt><img alt="technical debt"src=https://flat.badgen.net/codeclimate/tech-debt/wopian/kitsu></a> | ||
<a href=https://codeclimate.com/github/wopian/kitsu/issues><img alt=issues src=https://flat.badgen.net/codeclimate/issues/wopian/kitsu></a> | ||
</p> | ||
_Check out the [Migration Guide] for breaking changes and new features in `6.x`_ | ||
<p align=center> | ||
<a href=https://paypal.me/wopian><img alt="support me on paypal.me"src=https://flat.badgen.net/badge/support%20me%20on/paypal.me/pink></a> | ||
</p> | ||
<p align=center>Core <a href=http://jsonapi.org>JSON:API</a> serialisation and deserialisation components</p> | ||
<p align=center><em>Check out the <a href=https://github.com/wopian/kitsu/blob/master/packages/kitsu-core/MIGRATING.md>Migration Guide</a> for breaking changes in <code>6.x</code></em></p> | ||
# | ||
## Features | ||
@@ -30,9 +43,8 @@ | ||
| Package | Package<br> Size\* | Node | Chrome | Firefox | Safari | Edge | IE | | ||
| ------------------: | :----------------: | :--: | :----: | :-----: | :----: | :--: | :-: | | ||
| `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+ | | | | | | | ||
| Package | Package<br> Size\* | Node | Chrome | Firefox | Safari | Edge | IE | | ||
| ----------------: | :----------------: | :--: | :----: | :-----: | :----: | :--: | :-: | | ||
| `kitsu-core` | ≤ 4.3 kb | 6+ | 54+ | 51+ | 10+ | 15+ | | | ||
| `kitsu-core/node` | ≤ 1.5 kb | 6+ | | | | | | | ||
\* Including all dependencies, minified & gzipped | ||
\* Including all dependencies, minified & gzipped<br> | ||
@@ -49,6 +61,5 @@ ## Install | ||
```js | ||
import { camel } from 'kitsu-core' // ES Modules and Babel | ||
const { camel } = require('kitsu-core') // CommonJS and Browserify | ||
const { camel } = require('kitsu-core/legacy') // Legacy IE8+ support | ||
const { camel } = require('kitsu-core/node') // Lighter node-only package | ||
import { camel } from 'kitsu-core' // ES Modules and Babel | ||
import { camel } from 'kitsu-core/node' // Lighter node-only package | ||
const { camel } = require('kitsu-core') // CommonJS and Browserify | ||
@@ -58,9 +69,6 @@ camel(...) | ||
[Try it on RunKit](https://npm.runkit.com/kitsu-core) | ||
### Packd CDN | ||
```html | ||
<script src='https://bundle.run/kitsu-core@5?name=kitsuCore'></script> | ||
<script src='https://bundle.run/kitsu@5/legacy/index.js?name=kitsuCore'></script> | ||
<script src='https://bundle.run/kitsu-core@6?name=kitsuCore'></script> | ||
``` | ||
@@ -72,4 +80,2 @@ | ||
[Try it on CodePen](https://codepen.io/wopian/pen/KQZwzq?editors=0010) | ||
## API | ||
@@ -81,55 +87,35 @@ | ||
- [camel](#camel) | ||
- [deattribute](#deattribute) | ||
- [Parameters](#parameters) | ||
- [Examples](#examples) | ||
- [deattribute](#deattribute) | ||
- [deserialise](#deserialise) | ||
- [Parameters](#parameters-1) | ||
- [Examples](#examples-1) | ||
- [deserialise](#deserialise) | ||
- [error](#error) | ||
- [Parameters](#parameters-2) | ||
- [Examples](#examples-2) | ||
- [error](#error) | ||
- [filterIncludes](#filterincludes) | ||
- [Parameters](#parameters-3) | ||
- [filterIncludes](#filterincludes) | ||
- [linkRelationships](#linkrelationships) | ||
- [Parameters](#parameters-4) | ||
- [kebab](#kebab) | ||
- [queryFormat](#queryformat) | ||
- [Parameters](#parameters-5) | ||
- [Examples](#examples-3) | ||
- [linkRelationships](#linkrelationships) | ||
- [query](#query) | ||
- [Parameters](#parameters-6) | ||
- [query](#query) | ||
- [serialise](#serialise) | ||
- [Parameters](#parameters-7) | ||
- [serialise](#serialise) | ||
- [Examples](#examples-2) | ||
- [camel](#camel) | ||
- [Parameters](#parameters-8) | ||
- [Examples](#examples-3) | ||
- [kebab](#kebab) | ||
- [Parameters](#parameters-9) | ||
- [Examples](#examples-4) | ||
- [snake](#snake) | ||
- [Parameters](#parameters-9) | ||
- [Parameters](#parameters-10) | ||
- [Examples](#examples-5) | ||
### camel | ||
### deattribute | ||
Converts kebab-case and snake_case into camelCase | ||
[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub") | ||
#### Parameters | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** String to convert | ||
#### 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 | ||
### deattribute | ||
Hoists attributes to be top-level | ||
@@ -175,2 +161,4 @@ | ||
[packages/kitsu-core/src/deserialise/index.js:56-70](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/deserialise/index.js#L56-L70 "Source code on GitHub") | ||
Deserialises a JSON-API response | ||
@@ -224,2 +212,4 @@ | ||
[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub") | ||
Mutates an error and rethrows it | ||
@@ -236,2 +226,4 @@ | ||
[packages/kitsu-core/src/filterIncludes/index.js:12-21](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/filterIncludes/index.js#L12-L21 "Source code on GitHub") | ||
Filters includes for the specific relationship | ||
@@ -248,29 +240,30 @@ | ||
### kebab | ||
### linkRelationships | ||
Converts camelCase into kebab-case | ||
[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub") | ||
Links relationships to included data | ||
#### Parameters | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase string | ||
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response data object | ||
- `included` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response included object | ||
#### Examples | ||
### queryFormat | ||
```javascript | ||
kebab('helloWorld') // 'hello-world' | ||
``` | ||
[packages/kitsu-core/src/query/index.js:8-11](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/query/index.js#L8-L11 "Source code on GitHub") | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** kekab-case formatted string | ||
Formats a single URL query | ||
### linkRelationships | ||
#### Parameters | ||
Links relationships to included data | ||
- `value` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Right-hand side of the query | ||
- `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Left-hand side of the query | ||
#### Parameters | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** URL query string | ||
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response data object | ||
- `included` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The response included object | ||
### query | ||
[packages/kitsu-core/src/query/index.js:20-31](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/query/index.js#L20-L31 "Source code on GitHub") | ||
Constructs a URL query string for JSON:API parameters | ||
@@ -287,2 +280,4 @@ | ||
[packages/kitsu-core/src/serialise/index.js:19-69](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/serialise/index.js#L19-L69 "Source code on GitHub") | ||
Serialises an object into a JSON-API structure | ||
@@ -309,88 +304,84 @@ | ||
### snake | ||
### camel | ||
Converts camelCase into snake_case | ||
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub") | ||
Converts kebab-case and snake_case into camelCase | ||
#### Parameters | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase string | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** String to convert | ||
#### Examples | ||
_Convert kebab-case_ | ||
```javascript | ||
snake('helloWorld') // 'hello_world' | ||
camel('hello-world') // 'helloWorld' | ||
``` | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** snake_case formatted string | ||
_Convert snake_case_ | ||
## Contributing | ||
```javascript | ||
camel('hello_world') // 'helloWorld' | ||
``` | ||
See [CONTRIBUTING] | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase formatted string | ||
## Releases | ||
### kebab | ||
See [CHANGELOG] | ||
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub") | ||
## License | ||
Converts camelCase into kebab-case | ||
All code released under [MIT] | ||
#### Parameters | ||
[kitsu]: https://github.com/wopian/kitsu#readme | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase string | ||
[json:api]: http://jsonapi.org | ||
#### Examples | ||
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises | ||
```javascript | ||
kebab('helloWorld') // 'hello-world' | ||
``` | ||
[migration guide]: https://github.com/wopian/kitsu/blob/master/packages/kitsu-core/MIGRATING.md | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** kekab-case formatted string | ||
[changelog]: https://github.com/wopian/kitsu/blob/master/packages/kitsu-core/CHANGELOG.md | ||
### snake | ||
[contributing]: https://github.com/wopian/kitsu/blob/master/CONTRIBUTING.md | ||
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/f267c03e6bed0cd128d66a366bef5fef6616f23c/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub") | ||
[mit]: https://github.com/wopian/kitsu/blob/master/LICENSE.md | ||
Converts camelCase into snake_case | ||
[npm]: https://www.npmjs.com/package/kitsu-core | ||
#### Parameters | ||
[npm badge]: https://flat.badgen.net/npm/v/kitsu-core | ||
- `s` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** camelCase string | ||
[npm install badge]: https://flat.badgen.net/npm/dt/kitsu-core | ||
#### Examples | ||
[travis]: https://travis-ci.org/wopian/kitsu | ||
```javascript | ||
snake('helloWorld') // 'hello_world' | ||
``` | ||
[travis badge]: https://flat.badgen.net/travis/wopian/kitsu | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** snake_case formatted string | ||
[appveyor]: https://ci.appveyor.com/project/wopian/kitsu | ||
## Contributing | ||
[appveyor badge]: https://flat.badgen.net/appveyor/ci/wopian/kitsu | ||
See [CONTRIBUTING] | ||
[cc coverage]: https://codeclimate.com/github/wopian/kitsu/code | ||
## Releases | ||
[cc coverage badge]: https://img.shields.io/codeclimate/c/wopian/kitsu.svg?style=flat-square | ||
See [CHANGELOG] | ||
[cc maintainability]: https://codeclimate.com/github/wopian/kitsu | ||
## License | ||
[cc maintainability badge]: https://img.shields.io/codeclimate/maintainability/wopian/kitsu.svg?style=flat-square | ||
All code released under [MIT] | ||
[david]: https://david-dm.org/wopian/kitsu?path=packages/kitsu-core | ||
[json:api]: http://jsonapi.org | ||
[david badge]: https://david-dm.org/wopian/kitsu/status.svg?path=packages/kitsu-core&style=flat-square | ||
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises | ||
[david dev]: https://david-dm.org/wopian/kitsu?type=dev | ||
[changelog]: https://github.com/wopian/kitsu/blob/master/packages/kitsu-core/CHANGELOG.md | ||
[david dev badge]: https://flat.badgen.net/david/dev/wopian/kitsu | ||
[contributing]: https://github.com/wopian/kitsu/blob/master/CONTRIBUTING.md | ||
[contributors]: https://github.com/wopian/kitsu/graphs/contributors | ||
[contributors badge]: https://img.shields.io/github/contributors/wopian/kitsu.svg?style=flat-square | ||
[donate]: https://paypal.me/wopian | ||
[donate badge]: https://flat.badgen.net/badge/support%20me%20on/paypal.me/pink | ||
[bundlephobia]: https://bundlephobia.com/result?p=kitsu-core | ||
[bundlephobia badge]: https://flat.badgen.net/bundlephobia/minzip/kitsu-core | ||
[packagephobia]: https://packagephobia.now.sh/result?p=kitsu-core | ||
[packagephobia badge]: https://flat.badgen.net/packagephobia/install/kitsu-core | ||
[mit]: https://github.com/wopian/kitsu/blob/master/LICENSE.md |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
1222
0
74634
7
377
1