UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

31 lines (28 loc) 888 B
// stringify with no circular error function stringify(object) { if (object && typeof object === 'object') { object = _copyWithoutCircularReferences([object], object); } return JSON.stringify(object); function _copyWithoutCircularReferences(references, object) { const cleanObject = {}; Object.keys(object).forEach(key => { const value = object[key]; if (value && typeof value === 'object') { // TODO: do we need the 'value &&'? if (references.indexOf(value) < 0) { references.push(value); cleanObject[key] = _copyWithoutCircularReferences(references, value); references.pop(); } else { cleanObject[key] = '###_Circular_###'; } } else if (typeof value !== 'function') { cleanObject[key] = value; } }); return cleanObject; } } module.exports = { stringify };