jsonapi-parse
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "jsonapi-parse", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"main": "dist/jsonapi.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
@@ -51,6 +51,6 @@ (function(global, undefined) { | ||
var includedMap = {} | ||
var includedMap = {}; | ||
each(json.included, function(value) { | ||
var key = value.type + '-' + value.id; | ||
includedMap[key] = value | ||
includedMap[key] = value; | ||
}); | ||
@@ -85,2 +85,6 @@ | ||
if (json.links) { | ||
deserialized.links = json.links; | ||
} | ||
return deserialized; | ||
@@ -158,3 +162,3 @@ } | ||
function flatten(record) { | ||
return extend({}, { links: record.links }, record.attributes, { id: record.id }); | ||
return extend({}, { links: record.links }, record.attributes, { id: record.id, type: record.type }); | ||
} | ||
@@ -161,0 +165,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,n){function r(t){var n,r,o={};return p(t.included,function(t){var n=t.type+"-"+t.id;o[n]=t}),i(t.data)?n=s(t.data,function(t){return e(t,o),a(t)}):c(t.data)&&(e(t.data,o),n=a(t.data)),r={data:n,jsonapi:t.jsonapi||{}},t.meta&&(r.meta=t.meta),t.errors&&(r.errors=t.errors),r}function e(t,n,r){t.relationships&&(r=r?r.concat([t]):[t]),p(t.relationships,function(e,a){e.data&&(i(e.data)?t.attributes[a]=s(e.data,function(t){return o(t,n,r)}):t.attributes[a]=o(e.data,n,r))})}function o(t,n,r){var o,i;if(o=l(r,{id:t.id,type:t.type}))return t;var u=t.type+"-"+t.id;return(i=n[u])?(e(i,n,r),a(i)):t}function a(t){return j({},{links:t.links},t.attributes,{id:t.id})}function i(t){return"[object Array]"===Object.prototype.toString.call(t)}function u(t){return"[object String]"===Object.prototype.toString.call(t)}function c(t){return"[object Object]"===Object.prototype.toString.call(t)}function f(t){return t===n}function p(t,n){var r;if(i(t))for(r=0;r<t.length;r+=1)n(t[r],r);else if(c(t))for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&n(t[r],r)}function s(t,n){var r=[];return p(t,function(t,e){r.push(n(t,e))}),r}function d(t){var n=!0;return p(t,function(t){t!==!0&&(n=!1)}),n}function l(t,n){var r;return p(t,function(t){var e=s(n,function(n,r){return t[r]===n});d(e)&&(r=t)}),r}function j(){var t=Object(null),n=Array.prototype.slice.call(arguments);return p(n,function(n){p(n,function(n,r){t[r]=n})}),t}var y=t.jsonapi||(t.jsonapi={});y.parse=function(n){var e,o;if(u(n))try{e=t.JSON.parse(n)}catch(a){if("SyntaxError"===a.name)return n;throw a}else{if(!c(n))return n;e=n}return f(e.data)&&f(e.errors)&&f(e.meta)?e:e.jsonapi&&e.jsonapi.parsed?e:(o=r(e),o.jsonapi.parsed=!0,o)},"object"==typeof exports?c(module)&&c(module.exports)&&(exports=module.exports=y):t.jsonapi=y}("undefined"==typeof window?this:window); | ||
!function(t,n){function r(t){var n,r,o={};return p(t.included,function(t){var n=t.type+"-"+t.id;o[n]=t}),i(t.data)?n=f(t.data,function(t){return e(t,o),a(t)}):c(t.data)&&(e(t.data,o),n=a(t.data)),r={data:n,jsonapi:t.jsonapi||{}},t.meta&&(r.meta=t.meta),t.errors&&(r.errors=t.errors),t.links&&(r.links=t.links),r}function e(t,n,r){t.relationships&&(r=r?r.concat([t]):[t]),p(t.relationships,function(e,a){e.data&&(i(e.data)?t.attributes[a]=f(e.data,function(t){return o(t,n,r)}):t.attributes[a]=o(e.data,n,r))})}function o(t,n,r){var o,i;if(o=l(r,{id:t.id,type:t.type}))return t;var u=t.type+"-"+t.id;return(i=n[u])?(e(i,n,r),a(i)):t}function a(t){return j({},{links:t.links},t.attributes,{id:t.id,type:t.type})}function i(t){return"[object Array]"===Object.prototype.toString.call(t)}function u(t){return"[object String]"===Object.prototype.toString.call(t)}function c(t){return"[object Object]"===Object.prototype.toString.call(t)}function s(t){return t===n}function p(t,n){var r;if(i(t))for(r=0;r<t.length;r+=1)n(t[r],r);else if(c(t))for(r in t)Object.prototype.hasOwnProperty.call(t,r)&&n(t[r],r)}function f(t,n){var r=[];return p(t,function(t,e){r.push(n(t,e))}),r}function d(t){var n=!0;return p(t,function(t){t!==!0&&(n=!1)}),n}function l(t,n){var r;return p(t,function(t){var e=f(n,function(n,r){return t[r]===n});d(e)&&(r=t)}),r}function j(){var t=Object(null),n=Array.prototype.slice.call(arguments);return p(n,function(n){p(n,function(n,r){t[r]=n})}),t}var y=t.jsonapi||(t.jsonapi={});y.parse=function(n){var e,o;if(u(n))try{e=t.JSON.parse(n)}catch(a){if("SyntaxError"===a.name)return n;throw a}else{if(!c(n))return n;e=n}return s(e.data)&&s(e.errors)&&s(e.meta)?e:e.jsonapi&&e.jsonapi.parsed?e:(o=r(e),o.jsonapi.parsed=!0,o)},"object"==typeof exports?c(module)&&c(module.exports)&&(exports=module.exports=y):t.jsonapi=y}("undefined"==typeof window?this:window); |
{ | ||
"name": "jsonapi-parse", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Parses JSON API style responses into a more 'typical' JSON format", | ||
@@ -5,0 +5,0 @@ "main": "./dist/jsonapi.min.js", |
@@ -49,3 +49,3 @@ # JSONAPI Parse | ||
// data: [ | ||
// { id: '12klj', key: 'value', property: true } | ||
// { id: '12klj', type: 'primary', key: 'value', property: true } | ||
// ], | ||
@@ -52,0 +52,0 @@ // jsonapi: { parsed: true } |
@@ -84,2 +84,6 @@ (function(global, undefined) { | ||
if (json.links) { | ||
deserialized.links = json.links; | ||
} | ||
return deserialized; | ||
@@ -157,3 +161,3 @@ } | ||
function flatten(record) { | ||
return extend({}, { links: record.links }, record.attributes, { id: record.id }); | ||
return extend({}, { links: record.links }, record.attributes, { id: record.id, type: record.type }); | ||
} | ||
@@ -160,0 +164,0 @@ |
@@ -171,2 +171,26 @@ describe( | ||
); | ||
describe( | ||
'it should allow the "links" property to persist', | ||
function() { | ||
it( | ||
'should not modify or remove any existing jsonapi members', | ||
function() { | ||
var input = { meta: {}, links: { self: 'https://example.com/?page=1' } }; | ||
var result = window.jsonapi.parse(input); | ||
assert(result.links.self === input.links.self); | ||
} | ||
); | ||
it( | ||
'should not modify or remove the jsonapi member', | ||
function() { | ||
var input = { meta: {}, links: { self: 'https://example.com/?page=1' } }; | ||
var result = window.jsonapi.parse(input); | ||
assert(result.links === input.links); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
@@ -173,0 +197,0 @@ ); |
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
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
282539
9061