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

@cicada/message

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cicada/message - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

lib/bundle.js

40

lib/index.js

@@ -7,18 +7,8 @@ 'use strict';

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
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; };
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
exports.isIframe = isIframe;
exports.default = createMessage;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -40,3 +30,19 @@ function isIframe() {

var CICADA_PROMISE_EVENT = '__CICADA_PROMISE_EVENT__';
var CICADA_CIRCULAR_STRINGIFY = exports.CICADA_CIRCULAR_STRINGIFY = '[CICADA_CIRCULAR_STRINGIFY]';
function safeStringify(data) {
var cache = [];
return JSON.stringify(data, function (key, value) {
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return CICADA_CIRCULAR_STRINGIFY;
}
// Store value in our collection
cache.push(value);
}
return value;
});
}
function createMessage() {

@@ -63,3 +69,3 @@ var messagePrefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '__CICADA_MESSAGE__';

try {
message = (0, _stringify2.default)({ event: event, data: data });
message = safeStringify({ event: event, data: data });
} catch (e) {

@@ -82,7 +88,7 @@ throw new Error('Post message "' + event + '" stringify error.');

return new _promise2.default(function (resolve, reject) {
return new Promise(function (resolve, reject) {
var _dispatch;
var uuid = generateUUID();
dispatch(event, (_dispatch = { payload: data }, (0, _defineProperty3.default)(_dispatch, CICADA_UUID, uuid), (0, _defineProperty3.default)(_dispatch, 'toParent', toParent), _dispatch), toParent);
dispatch(event, (_dispatch = { payload: data }, _defineProperty(_dispatch, CICADA_UUID, uuid), _defineProperty(_dispatch, 'toParent', toParent), _dispatch), toParent);
promiseCache[uuid] = { resolve: resolve, reject: reject };

@@ -130,6 +136,6 @@ setTimeout(function () {

} else {
_promise2.default.resolve(callback(message.data.payload)).then(function (result) {
Promise.resolve(callback(message.data.payload)).then(function (result) {
var toParent = message.data.toParent;
dispatch(CICADA_PROMISE_EVENT, (0, _defineProperty3.default)({ payload: result }, CICADA_UUID, uuid), toParent === undefined ? toParent : !toParent);
dispatch(CICADA_PROMISE_EVENT, _defineProperty({ payload: result }, CICADA_UUID, uuid), toParent === undefined ? toParent : !toParent);
});

@@ -136,0 +142,0 @@ }

{
"name": "@cicada/message",
"version": "0.2.1",
"version": "0.2.2",
"description": "cicada message",
"main": "lib/index.js",
"scripts": {
"rollup": "rollup -c rollup.config.js",
"build": "make build",

@@ -24,14 +25,14 @@ "test": "make test",

"devDependencies": {
"autod": "^2.9.0",
"babel-cli": "^6.26.0",
"babel-eslint": "^7.1.0",
"babel-istanbul": "^0.12.1",
"babel-cli": "^6.26.0",
"babel-plugin-import": "^1.1.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-runtime": "^6.26.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.26.0",
"coveralls": "^3.0.0",
"expect": "^21.2.1",
"babel-eslint": "^7.1.0",
"eslint": "^4.8.0",

@@ -43,5 +44,8 @@ "eslint-config-airbnb": "^15.1.0",

"eslint-plugin-react": "^7.x",
"expect": "^21.2.1",
"mocha": "^2.5.3",
"autod": "^2.9.0",
"pre-commit": "^1.1.2"
"pre-commit": "^1.1.2",
"rollup": "^0.62.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-uglify": "^4.0.0"
},

@@ -48,0 +52,0 @@ "pre-commit": [

@@ -16,3 +16,19 @@ export function isIframe() {

const CICADA_PROMISE_EVENT = '__CICADA_PROMISE_EVENT__'
export const CICADA_CIRCULAR_STRINGIFY = '[CICADA_CIRCULAR_STRINGIFY]'
function safeStringify(data) {
const cache = []
return JSON.stringify(data, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return CICADA_CIRCULAR_STRINGIFY
}
// Store value in our collection
cache.push(value)
}
return value
})
}
export default function createMessage(messagePrefix = '__CICADA_MESSAGE__') {

@@ -37,3 +53,3 @@ const listeners = []

try {
message = JSON.stringify({ event, data })
message = safeStringify({ event, data })
} catch (e) {

@@ -40,0 +56,0 @@ throw new Error(`Post message "${event}" stringify error.`)

Sorry, the diff of this file is not supported yet

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