isJSON.js 911 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isJSON;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  9. function isJSON(str) {
  10. (0, _assertString.default)(str);
  11. try {
  12. var obj = JSON.parse(str);
  13. return !!obj && _typeof(obj) === 'object';
  14. } catch (e) {
  15. /* ignore */
  16. }
  17. return false;
  18. }
  19. module.exports = exports.default;
  20. module.exports.default = exports.default;