isJSON.js 835 B

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