UNPKG

web-components

Version:

Build and Test React Components in real time

52 lines (43 loc) 1.73 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; exports.default = stringifyI18nObject; // Recusively looks for object key that contains 'id' // and perform stringification in order to work with joi-validation-strategy and react-intl together function stringifyI18nObject() { var messages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var updatedMessages = messages; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = Object.keys(messages)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var key = _step.value; // Stringify current object message and end current node if (key === 'id') { return JSON.stringify(messages); } // Go one deeper level and perform the same logic for nested object if (_typeof(messages[key]) === 'object') { updatedMessages[key] = stringifyI18nObject(messages[key]); } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return updatedMessages; } //# sourceMappingURL=stringifyI18nObject.js.map