contentful-parsers
Advanced tools
Comparing version 1.2.10 to 1.2.11
@@ -94,3 +94,3 @@ /** | ||
Object.keys(fieldsObject).forEach(function (key) { | ||
objectRefClone[key] = fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
objectRefClone[key] = fieldsObject[key] && fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
}); // Apply typeNameKey/value to each fields object to define the Contentful model type | ||
@@ -97,0 +97,0 @@ |
@@ -188,3 +188,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
objectClone[key] = field.map(function (item, index) { | ||
return cleanClone(item, object === null || object === void 0 ? void 0 : object.fields[key][index]); | ||
return cleanClone(item, object && object.fields && object.fields[key][index]); | ||
}).filter(function (item) { | ||
@@ -191,0 +191,0 @@ return !!item; |
{ | ||
"name": "contentful-parsers", | ||
"version": "1.2.10", | ||
"version": "1.2.11", | ||
"description": "Library of useful parsers to use when working with Contentful API responses.", | ||
@@ -5,0 +5,0 @@ "repository": "ryanhefner/contentful-parsers.git", |
@@ -99,3 +99,3 @@ "use strict"; | ||
Object.keys(fieldsObject).forEach(function (key) { | ||
objectRefClone[key] = fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
objectRefClone[key] = fieldsObject[key] && fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
}); // Apply typeNameKey/value to each fields object to define the Contentful model type | ||
@@ -102,0 +102,0 @@ |
@@ -199,3 +199,3 @@ "use strict"; | ||
objectClone[key] = field.map(function (item, index) { | ||
return cleanClone(item, object === null || object === void 0 ? void 0 : object.fields[key][index]); | ||
return cleanClone(item, object && object.fields && object.fields[key][index]); | ||
}).filter(function (item) { | ||
@@ -202,0 +202,0 @@ return !!item; |
@@ -79,3 +79,3 @@ /** | ||
Object.keys(fieldsObject).forEach((key) => { | ||
objectRefClone[key] = fieldsObject[key].fields && options.parseRefs | ||
objectRefClone[key] = fieldsObject[key] && fieldsObject[key].fields && options.parseRefs | ||
? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) | ||
@@ -82,0 +82,0 @@ : parseValue(fieldsObject[key], depth + 1); |
@@ -171,3 +171,8 @@ import { fieldsParser } from './fieldsParser' | ||
const collectionKey = `${key}Collection` | ||
objectClone[collectionKey] = parseCollection(field, `${typename}${capitalizeFirstLetter(collectionKey)}`, definitionMap?.[collectionKey], depth + 1); | ||
objectClone[collectionKey] = parseCollection( | ||
field, | ||
`${typename}${capitalizeFirstLetter(collectionKey)}`, | ||
definitionMap?.[collectionKey], | ||
depth + 1 | ||
); | ||
@@ -178,3 +183,3 @@ // Delete old flat array field | ||
objectClone[key] = field | ||
.map((item, index) => cleanClone(item, object?.fields[key][index])) | ||
.map((item, index) => cleanClone(item, object && object.fields && object.fields[key][index])) | ||
.filter(item => !!item) | ||
@@ -181,0 +186,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/*! contentful-parsers v1.2.10 | (c) 2020 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/ | ||
/*! contentful-parsers v1.2.11 | (c) 2020 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/ | ||
(function (global, factory) { | ||
@@ -101,3 +101,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
Object.keys(fieldsObject).forEach(function (key) { | ||
objectRefClone[key] = fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
objectRefClone[key] = fieldsObject[key] && fieldsObject[key].fields && options.parseRefs ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1) : parseValue(fieldsObject[key], depth + 1); | ||
}); // Apply typeNameKey/value to each fields object to define the Contentful model type | ||
@@ -331,3 +331,3 @@ | ||
objectClone[key] = field.map(function (item, index) { | ||
return cleanClone(item, object === null || object === void 0 ? void 0 : object.fields[key][index]); | ||
return cleanClone(item, object && object.fields && object.fields[key][index]); | ||
}).filter(function (item) { | ||
@@ -334,0 +334,0 @@ return !!item; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["contentful-parsers"]={})}(this,function(e){"use strict";function R(e,l,o){function s(e){return"object"==typeof e&&e.hasOwnProperty("sys")&&1===Object.keys(e).length}function u(t,e,n,r){if(void 0===n&&(n={}),void 0===r&&(r=0),!t||"object"!=typeof t)return n;if(r>=l.include)return n;var i=Object.assign({},n);return Object.keys(t).forEach(function(e){i[e]=t[e].fields&&o.parseRefs?u(t[e].fields,t[e].sys,i[e],r+1):function t(e,n){return void 0===n&&(n=0),s(e)?null:Array.isArray(e)&&o.parseArrays?e.filter(function(e){return!s(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?u(e.fields,e.sys,{},n+1):t(e,n+1)}):e}(t[e],r+1)}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(i.id=e.id,i.__typename=e.contentType.sys.id),e&&e.updatedAt&&(i.updatedAt=e.updatedAt),e&&e.createdAt&&(i.createdAt=e.createdAt),i}void 0===l&&(l={include:10}),void 0===o&&(o={parseArrays:!0,parseRefs:!0});var t=Object.assign({},e);return u(t.fields,t.sys)}var r=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach(function(e){r(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function S(e){return e.substring(0,1).toUpperCase()+e.substring(1)}e.contentfulResolver=function(e,t){return t&&t.hasOwnProperty(e)?t[e]:null},e.fieldsParser=R,e.graphqlParser=function(e,t,n,E){var r,i;function k(e,t){return e&&(e.hasOwnProperty("__typename")&&e.__typename&&(e.__typename=S(e.__typename)),t&&t.sys?e.sys=l(l({},t.sys),{},{__typename:"Sys"}):t.id&&(e.sys={id:t.id,__typename:"Sys"}),e.id&&delete e.id,e.createdAt&&delete e.createdAt,e.updatedAt&&delete e.updatedAt),e}function C(i,l,o,s){var e;if(void 0===s&&(s=0),!i)return null;if(s>=E.include)return i;var u=Object.assign({},i.hasOwnProperty("sys")&&i.hasOwnProperty("fields")?R(i,E,{parseArrays:!1,parseRefs:!1}):i);Object.keys(u).forEach(function(n){var e=u[n];if(Array.isArray(e)){var t=!1;if(e.filter(function(e){return!!e}).forEach(function(e){(e.hasOwnProperty("sys")&&e.hasOwnProperty("fields")||e.hasOwnProperty("__typename"))&&(t=!0)}),t){var r=n+"Collection";u[r]=D(e,""+l+S(r),null==o?void 0:o[r],s+1),delete u[n]}else u[n]=e.map(function(e,t){return k(e,null==i?void 0:i.fields[n][t])}).filter(function(e){return!!e})}else e&&"object"==typeof e&&(e.hasOwnProperty("__typename")||e.hasOwnProperty("sys")&&e.hasOwnProperty("fields"))?u[n]=C(e,l,null==o?void 0:o[n],s+1):u[n]=e});var t,n,r,a,d,f,c,y,p,v,O,b,h,m,_,j,g,P,w,A=k(u,i),T="Asset"===(null==A||null===(e=A.sys)||void 0===e?void 0:e.type)?(t=A,(w=Object.assign({},t)).__typename="Asset",w.url=null==w||null===(n=w.file)||void 0===n?void 0:n.url,w.contentType=null==w||null===(r=w.file)||void 0===r?void 0:r.contentType,w.size=null==w||null===(a=w.file)||void 0===a||null===(d=a.details)||void 0===d?void 0:d.size,w.width=(null==w||null===(f=w.file)||void 0===f||null===(c=f.details)||void 0===c||null===(y=c.image)||void 0===y?void 0:y.width)||(null==w||null===(p=w.file)||void 0===p||null===(v=p.details)||void 0===v||null===(O=v.video)||void 0===O?void 0:O.width),w.height=(null==w||null===(b=w.file)||void 0===b||null===(h=b.details)||void 0===h||null===(m=h.image)||void 0===m?void 0:m.height)||(null==w||null===(_=w.file)||void 0===_||null===(j=_.details)||void 0===j||null===(g=j.video)||void 0===g?void 0:g.height),w.fileName=null==w||null===(P=w.file)||void 0===P?void 0:P.fileName,delete w.file,w):A;return function r(e,i,l){if(!e||!l)return e;var o=Object.assign({},e||{});return Object.keys(l).forEach(function(e){if(!o.hasOwnProperty(e))if(e.endsWith("Collection")){var t=e.replace("Collection",""),n=o.hasOwnProperty(t)&&o[t];n?(o[e]=D(n,""+i+S(e),l[e]),delete o[t]):o[e]=D([],""+i+S(e),l[e])}else e.startsWith("...")&&o.__typename&&o.__typename===e.replace("...","")?Object.assign(o,r(o,i,l[e])):o[e]=null}),o}(T,T.__typename||l,o)}function D(e,t,n,r){return void 0===e&&(e=[]),void 0===r&&(r=0),{__typename:t,total:(e&&Array.isArray(e)?e:[]).length,items:(e&&Array.isArray(e)?e:[]).map(function(e){return C(e,t,null==n?void 0:n.items,r)}).filter(function(e){return!!e})}}return void 0===E&&(E={include:10}),null!=t&&t.items?((i={})[e]=D(t.items,S(e),null==n?void 0:n[e]),i):((r={})[e]=l({__typename:S(e)},C(t,S(e),null==n?void 0:n[e])),r)},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["contentful-parsers"]={})}(this,function(e){"use strict";function R(e,l,o){function s(e){return"object"==typeof e&&e.hasOwnProperty("sys")&&1===Object.keys(e).length}function u(t,e,n,r){if(void 0===n&&(n={}),void 0===r&&(r=0),!t||"object"!=typeof t)return n;if(r>=l.include)return n;var i=Object.assign({},n);return Object.keys(t).forEach(function(e){i[e]=t[e]&&t[e].fields&&o.parseRefs?u(t[e].fields,t[e].sys,i[e],r+1):function t(e,n){return void 0===n&&(n=0),s(e)?null:Array.isArray(e)&&o.parseArrays?e.filter(function(e){return!s(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?u(e.fields,e.sys,{},n+1):t(e,n+1)}):e}(t[e],r+1)}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(i.id=e.id,i.__typename=e.contentType.sys.id),e&&e.updatedAt&&(i.updatedAt=e.updatedAt),e&&e.createdAt&&(i.createdAt=e.createdAt),i}void 0===l&&(l={include:10}),void 0===o&&(o={parseArrays:!0,parseRefs:!0});var t=Object.assign({},e);return u(t.fields,t.sys)}var r=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach(function(e){r(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function S(e){return e.substring(0,1).toUpperCase()+e.substring(1)}e.contentfulResolver=function(e,t){return t&&t.hasOwnProperty(e)?t[e]:null},e.fieldsParser=R,e.graphqlParser=function(e,t,n,E){var r,i;function k(e,t){return e&&(e.hasOwnProperty("__typename")&&e.__typename&&(e.__typename=S(e.__typename)),t&&t.sys?e.sys=l(l({},t.sys),{},{__typename:"Sys"}):t.id&&(e.sys={id:t.id,__typename:"Sys"}),e.id&&delete e.id,e.createdAt&&delete e.createdAt,e.updatedAt&&delete e.updatedAt),e}function C(i,l,o,s){var e;if(void 0===s&&(s=0),!i)return null;if(s>=E.include)return i;var u=Object.assign({},i.hasOwnProperty("sys")&&i.hasOwnProperty("fields")?R(i,E,{parseArrays:!1,parseRefs:!1}):i);Object.keys(u).forEach(function(n){var e=u[n];if(Array.isArray(e)){var t=!1;if(e.filter(function(e){return!!e}).forEach(function(e){(e.hasOwnProperty("sys")&&e.hasOwnProperty("fields")||e.hasOwnProperty("__typename"))&&(t=!0)}),t){var r=n+"Collection";u[r]=D(e,""+l+S(r),null==o?void 0:o[r],s+1),delete u[n]}else u[n]=e.map(function(e,t){return k(e,i&&i.fields&&i.fields[n][t])}).filter(function(e){return!!e})}else e&&"object"==typeof e&&(e.hasOwnProperty("__typename")||e.hasOwnProperty("sys")&&e.hasOwnProperty("fields"))?u[n]=C(e,l,null==o?void 0:o[n],s+1):u[n]=e});var t,n,r,a,d,f,c,y,p,v,O,b,h,m,_,j,g,P,w,A=k(u,i),T="Asset"===(null==A||null===(e=A.sys)||void 0===e?void 0:e.type)?(t=A,(w=Object.assign({},t)).__typename="Asset",w.url=null==w||null===(n=w.file)||void 0===n?void 0:n.url,w.contentType=null==w||null===(r=w.file)||void 0===r?void 0:r.contentType,w.size=null==w||null===(a=w.file)||void 0===a||null===(d=a.details)||void 0===d?void 0:d.size,w.width=(null==w||null===(f=w.file)||void 0===f||null===(c=f.details)||void 0===c||null===(y=c.image)||void 0===y?void 0:y.width)||(null==w||null===(p=w.file)||void 0===p||null===(v=p.details)||void 0===v||null===(O=v.video)||void 0===O?void 0:O.width),w.height=(null==w||null===(b=w.file)||void 0===b||null===(h=b.details)||void 0===h||null===(m=h.image)||void 0===m?void 0:m.height)||(null==w||null===(_=w.file)||void 0===_||null===(j=_.details)||void 0===j||null===(g=j.video)||void 0===g?void 0:g.height),w.fileName=null==w||null===(P=w.file)||void 0===P?void 0:P.fileName,delete w.file,w):A;return function r(e,i,l){if(!e||!l)return e;var o=Object.assign({},e||{});return Object.keys(l).forEach(function(e){if(!o.hasOwnProperty(e))if(e.endsWith("Collection")){var t=e.replace("Collection",""),n=o.hasOwnProperty(t)&&o[t];n?(o[e]=D(n,""+i+S(e),l[e]),delete o[t]):o[e]=D([],""+i+S(e),l[e])}else e.startsWith("...")&&o.__typename&&o.__typename===e.replace("...","")?Object.assign(o,r(o,i,l[e])):o[e]=null}),o}(T,T.__typename||l,o)}function D(e,t,n,r){return void 0===e&&(e=[]),void 0===r&&(r=0),{__typename:t,total:(e&&Array.isArray(e)?e:[]).length,items:(e&&Array.isArray(e)?e:[]).map(function(e){return C(e,t,null==n?void 0:n.items,r)}).filter(function(e){return!!e})}}return void 0===E&&(E={include:10}),null!=t&&t.items?((i={})[e]=D(t.items,S(e),null==n?void 0:n[e]),i):((r={})[e]=l({__typename:S(e)},C(t,S(e),null==n?void 0:n[e])),r)},Object.defineProperty(e,"__esModule",{value:!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
80144
1746