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

contentful-parsers

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-parsers - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

36

es/parsers/fieldsParser.js

@@ -8,3 +8,9 @@ /**

*/
export default function (data) {
export default function (data, props) {
if (props === void 0) {
props = {
include: 10
};
}
/**

@@ -18,3 +24,3 @@ * Check to see if the object passed is an object that contains only a `sys`

function emptyModel(object) {
return !!(typeof object === 'object' && object.sys && Object.keys(object).length === 1);
return !!(typeof object === 'object' && object.hasOwnProperty('sys') && Object.keys(object).length === 1);
}

@@ -31,9 +37,9 @@ /**

function parseValue(value) {
if (!value) {
return null;
} // If value is an object and only contains a sys property, just return null
function parseValue(value, depth) {
if (depth === void 0) {
depth = 0;
}
// If value is an object and only contains a sys property, just return null
// since it’s either an empty or unpublished entry
if (emptyModel(value)) {

@@ -47,3 +53,3 @@ return null;

}).map(function (item) {
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys) : parseValue(item);
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys, {}, depth + 1) : parseValue(item, depth + 1);
});

@@ -64,3 +70,3 @@ }

function parseFields(fieldsObject, sys, objectRef) {
function parseFields(fieldsObject, sys, objectRef, depth) {
if (objectRef === void 0) {

@@ -70,2 +76,6 @@ objectRef = {};

if (depth === void 0) {
depth = 0;
}
if (!fieldsObject || typeof fieldsObject !== 'object') {

@@ -75,2 +85,6 @@ return objectRef;

if (depth >= props.include) {
return objectRef;
}
var objectRefClone = Object.assign({}, objectRef); // Iterate over fieldObject keys, rercursively parsing child objects that

@@ -80,3 +94,3 @@ // contain fields, or parsing non-fields-child objects/entries

Object.keys(fieldsObject).forEach(function (key) {
objectRefClone[key] = fieldsObject[key].fields ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key]) : parseValue(fieldsObject[key]);
objectRefClone[key] = fieldsObject[key].fields ? 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

@@ -83,0 +97,0 @@

{
"name": "contentful-parsers",
"version": "0.1.4",
"version": "0.2.0",
"description": "Library of useful parsers to use when working with Contentful API responses.",

@@ -5,0 +5,0 @@ "repository": "ryanhefner/contentful-parsers.git",

@@ -13,3 +13,9 @@ "use strict";

*/
function _default(data) {
function _default(data, props) {
if (props === void 0) {
props = {
include: 10
};
}
/**

@@ -23,3 +29,3 @@ * Check to see if the object passed is an object that contains only a `sys`

function emptyModel(object) {
return !!(typeof object === 'object' && object.sys && Object.keys(object).length === 1);
return !!(typeof object === 'object' && object.hasOwnProperty('sys') && Object.keys(object).length === 1);
}

@@ -36,9 +42,9 @@ /**

function parseValue(value) {
if (!value) {
return null;
} // If value is an object and only contains a sys property, just return null
function parseValue(value, depth) {
if (depth === void 0) {
depth = 0;
}
// If value is an object and only contains a sys property, just return null
// since it’s either an empty or unpublished entry
if (emptyModel(value)) {

@@ -52,3 +58,3 @@ return null;

}).map(function (item) {
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys) : parseValue(item);
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys, {}, depth + 1) : parseValue(item, depth + 1);
});

@@ -69,3 +75,3 @@ }

function parseFields(fieldsObject, sys, objectRef) {
function parseFields(fieldsObject, sys, objectRef, depth) {
if (objectRef === void 0) {

@@ -75,2 +81,6 @@ objectRef = {};

if (depth === void 0) {
depth = 0;
}
if (!fieldsObject || typeof fieldsObject !== 'object') {

@@ -80,2 +90,6 @@ return objectRef;

if (depth >= props.include) {
return objectRef;
}
var objectRefClone = Object.assign({}, objectRef); // Iterate over fieldObject keys, rercursively parsing child objects that

@@ -85,3 +99,3 @@ // contain fields, or parsing non-fields-child objects/entries

Object.keys(fieldsObject).forEach(function (key) {
objectRefClone[key] = fieldsObject[key].fields ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key]) : parseValue(fieldsObject[key]);
objectRefClone[key] = fieldsObject[key].fields ? 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

@@ -88,0 +102,0 @@

@@ -8,3 +8,3 @@ /**

*/
export default function (data) {
export default function (data, props = { include: 10 }) {
/**

@@ -20,3 +20,3 @@ * Check to see if the object passed is an object that contains only a `sys`

typeof object === 'object'
&& object.sys
&& object.hasOwnProperty('sys')
&& Object.keys(object).length === 1

@@ -34,7 +34,3 @@ );

*/
function parseValue(value) {
if (!value) {
return null;
}
function parseValue(value, depth = 0) {
// If value is an object and only contains a sys property, just return null

@@ -52,4 +48,4 @@ // since it’s either an empty or unpublished entry

return item && typeof item === 'object' && item.fields
? parseFields(item.fields, item.sys)
: parseValue(item);
? parseFields(item.fields, item.sys, {}, depth + 1)
: parseValue(item, depth + 1);
});

@@ -69,3 +65,3 @@ }

*/
function parseFields(fieldsObject, sys, objectRef = {}) {
function parseFields(fieldsObject, sys, objectRef = {}, depth = 0) {
if (!fieldsObject || typeof fieldsObject !== 'object') {

@@ -75,2 +71,6 @@ return objectRef;

if (depth >= props.include) {
return objectRef;
}
const objectRefClone = Object.assign({}, objectRef);

@@ -82,4 +82,4 @@

objectRefClone[key] = fieldsObject[key].fields
? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key])
: parseValue(fieldsObject[key]);
? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key], depth + 1)
: parseValue(fieldsObject[key], depth + 1);
});

@@ -86,0 +86,0 @@

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

/*! contentful-parsers v0.1.4 | (c) 2019 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/
/*! contentful-parsers v0.2.0 | (c) 2019 Ryan Hefner | MIT License | https://github.com/ryanhefner/contentful-parsers.git !*/
(function (global, factory) {

@@ -15,3 +15,9 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

*/
function fieldsParser (data) {
function fieldsParser (data, props) {
if (props === void 0) {
props = {
include: 10
};
}
/**

@@ -25,3 +31,3 @@ * Check to see if the object passed is an object that contains only a `sys`

function emptyModel(object) {
return !!(typeof object === 'object' && object.sys && Object.keys(object).length === 1);
return !!(typeof object === 'object' && object.hasOwnProperty('sys') && Object.keys(object).length === 1);
}

@@ -38,9 +44,9 @@ /**

function parseValue(value) {
if (!value) {
return null;
} // If value is an object and only contains a sys property, just return null
function parseValue(value, depth) {
if (depth === void 0) {
depth = 0;
}
// If value is an object and only contains a sys property, just return null
// since it’s either an empty or unpublished entry
if (emptyModel(value)) {

@@ -54,3 +60,3 @@ return null;

}).map(function (item) {
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys) : parseValue(item);
return item && typeof item === 'object' && item.fields ? parseFields(item.fields, item.sys, {}, depth + 1) : parseValue(item, depth + 1);
});

@@ -71,3 +77,3 @@ }

function parseFields(fieldsObject, sys, objectRef) {
function parseFields(fieldsObject, sys, objectRef, depth) {
if (objectRef === void 0) {

@@ -77,2 +83,6 @@ objectRef = {};

if (depth === void 0) {
depth = 0;
}
if (!fieldsObject || typeof fieldsObject !== 'object') {

@@ -82,2 +92,6 @@ return objectRef;

if (depth >= props.include) {
return objectRef;
}
var objectRefClone = Object.assign({}, objectRef); // Iterate over fieldObject keys, rercursively parsing child objects that

@@ -87,3 +101,3 @@ // contain fields, or parsing non-fields-child objects/entries

Object.keys(fieldsObject).forEach(function (key) {
objectRefClone[key] = fieldsObject[key].fields ? parseFields(fieldsObject[key].fields, fieldsObject[key].sys, objectRefClone[key]) : parseValue(fieldsObject[key]);
objectRefClone[key] = fieldsObject[key].fields ? 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

@@ -90,0 +104,0 @@

@@ -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=e||self)["contentful-parsers"]={})}(this,function(e){"use strict";e.fieldsParser=function(e){function o(e){return!("object"!=typeof e||!e.sys||1!==Object.keys(e).length)}function f(t,e,n){if(void 0===n&&(n={}),!t||"object"!=typeof t)return n;var s=Object.assign({},n);return Object.keys(t).forEach(function(e){s[e]=t[e].fields?f(t[e].fields,t[e].sys,s[e]):function t(e){return e?o(e)?null:Array.isArray(e)?e.filter(function(e){return!o(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?f(e.fields,e.sys):t(e)}):e:null}(t[e])}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(s.id=e.id,s.__typename=e.contentType.sys.id),s}return f(e.fields,e.sys)},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=e||self)["contentful-parsers"]={})}(this,function(e){"use strict";e.fieldsParser=function(e,s){function r(e){return!("object"!=typeof e||!e.hasOwnProperty("sys")||1!==Object.keys(e).length)}function f(t,e,n,i){if(void 0===n&&(n={}),void 0===i&&(i=0),!t||"object"!=typeof t)return n;if(i>=s.include)return n;var o=Object.assign({},n);return Object.keys(t).forEach(function(e){o[e]=t[e].fields?f(t[e].fields,t[e].sys,o[e],i+1):function t(e,n){return void 0===n&&(n=0),r(e)?null:Array.isArray(e)?e.filter(function(e){return!r(e)}).map(function(e){return e&&"object"==typeof e&&e.fields?f(e.fields,e.sys,{},n+1):t(e,n+1)}):e}(t[e],i+1)}),e&&e.contentType&&e.contentType.sys&&e.contentType.sys.id&&(o.id=e.id,o.__typename=e.contentType.sys.id),o}return void 0===s&&(s={include:10}),f(e.fields,e.sys)},Object.defineProperty(e,"__esModule",{value:!0})});
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