mirror of
https://github.com/valitydev/cross-origin-communicator.git
synced 2024-11-06 02:25:18 +00:00
Add prettier, add skipLibCheck, bump typescript (#7)
This commit is contained in:
parent
9ae9e9b855
commit
5aa251c8b7
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@ -0,0 +1,4 @@
|
||||
package-lock.json
|
||||
package.json
|
||||
node_modules
|
||||
dist
|
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true,
|
||||
"arrowParens": "always"
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
# cross-origin-communicator
|
||||
|
||||
Cross-origin communication between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
|
||||
|
67
package-lock.json
generated
67
package-lock.json
generated
@ -7,105 +7,92 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||
"dev": true
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"balanced-match": "1.0.0",
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
}
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
|
||||
"dev": true
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"dev": true,
|
||||
"version": "7.1.3",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
|
||||
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
|
||||
"requires": {
|
||||
"fs.realpath": "1.0.0",
|
||||
"inflight": "1.0.6",
|
||||
"inherits": "2.0.3",
|
||||
"minimatch": "3.0.4",
|
||||
"once": "1.4.0",
|
||||
"path-is-absolute": "1.0.1"
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "1.4.0",
|
||||
"wrappy": "1.0.2"
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
|
||||
"dev": true
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"brace-expansion": "1.1.11"
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1.0.2"
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||
"dev": true
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
|
||||
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
|
||||
"dev": true,
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
|
||||
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
|
||||
"requires": {
|
||||
"glob": "7.1.2"
|
||||
"glob": "^7.1.3"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
|
||||
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
|
||||
"dev": true
|
||||
"version": "3.3.4000",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.4000.tgz",
|
||||
"integrity": "sha512-jjOcCZvpkl2+z7JFn0yBOoLQyLoIkNZAs/fYJkUG6VKy6zLPHJGfQJYFHzibB6GJaF/8QrcECtlQ5cpvRHSMEA=="
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
package.json
10
package.json
@ -3,10 +3,12 @@
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"postinstall": "npm run build",
|
||||
"prepare": "npm run build",
|
||||
"prebuild": "npm run clean",
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"clean": "rimraf dist"
|
||||
"clean": "rimraf dist",
|
||||
"check": "prettier \"**/*.{ts,md,json,prettierrc}\" --list-different",
|
||||
"prettier": "prettier \"**/*.{ts,md,json,prettierrc}\" --write"
|
||||
},
|
||||
"private": true,
|
||||
"main": "dist/index.js",
|
||||
@ -18,7 +20,7 @@
|
||||
"author": "Ildar Galeev",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"rimraf": "^2.6.2",
|
||||
"typescript": "^2.7.1"
|
||||
"rimraf": "~2.6.3",
|
||||
"typescript": "~3.3.4000"
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,12 @@ import { Transport } from './transport';
|
||||
import { log } from './log';
|
||||
import { Constants } from './constants';
|
||||
|
||||
export const initialize = (target: Window, origin: string, transportName: string, isLog: boolean = false): Promise<Transport> => {
|
||||
export const initialize = (
|
||||
target: Window,
|
||||
origin: string,
|
||||
transportName: string,
|
||||
isLog: boolean = false
|
||||
): Promise<Transport> => {
|
||||
let interval: number;
|
||||
return new Promise((resolve, reject) => {
|
||||
const reply = (e: any) => {
|
||||
|
@ -15,7 +15,7 @@ const handleHandshake = (transportName: string, isLog: boolean = false): Promise
|
||||
new Promise((resolve) => {
|
||||
const shake = (e: MessageEvent) => {
|
||||
if (e && e.data === Constants.initializerHandName) {
|
||||
const target = e.source;
|
||||
const target = e.source as WindowProxy;
|
||||
target.postMessage(Constants.listenerHandName, e.origin);
|
||||
if (isLog) {
|
||||
log('listener receive initializer hand');
|
||||
@ -28,10 +28,7 @@ const handleHandshake = (transportName: string, isLog: boolean = false): Promise
|
||||
});
|
||||
|
||||
const handleHandshakeWithTimeout = (transportName: string, ms: number, isLog: boolean = false): Promise<Transport> =>
|
||||
Promise.race<Transport>([
|
||||
timeout(ms),
|
||||
handleHandshake(transportName, isLog)
|
||||
]);
|
||||
Promise.race<Transport>([timeout(ms), handleHandshake(transportName, isLog)]);
|
||||
|
||||
export const listen = (transportName: string, ms: number = null, isLog: boolean = false): Promise<Transport> => {
|
||||
return ms === null || ms === undefined
|
||||
|
@ -10,7 +10,7 @@ const parse = (data: any): any => {
|
||||
|
||||
const transportListener = (transportName: string, events: any, e: MessageEvent) => {
|
||||
const parsed = parse(e.data);
|
||||
if (parsed && (parsed.name in events)) {
|
||||
if (parsed && parsed.name in events) {
|
||||
if (parsed.transport === transportName) {
|
||||
events[parsed.name].call(this, parsed.data);
|
||||
}
|
||||
@ -18,7 +18,6 @@ const transportListener = (transportName: string, events: any, e: MessageEvent)
|
||||
};
|
||||
|
||||
export class RealTransport implements Transport {
|
||||
|
||||
private readonly events: any = {};
|
||||
private readonly transportListener: any;
|
||||
|
||||
|
@ -1,18 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"lib": ["es2015", "dom"]
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"lib": ["es2015", "dom"],
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user