{ "_args": [ [ { "raw": "event-target-shim@^1.0.5", "scope": null, "escapedName": "event-target-shim", "name": "event-target-shim", "rawSpec": "^1.0.5", "spec": ">=1.0.5 <2.0.0", "type": "range" }, "/home/jdaugherty/work/GT2/GT2-Android/node_modules/react-native" ] ], "_from": "event-target-shim@>=1.0.5 <2.0.0", "_id": "event-target-shim@1.1.1", "_inCache": true, "_location": "/event-target-shim", "_nodeVersion": "4.2.3", "_npmUser": { "name": "mysticatea", "email": "star.ctor@gmail.com" }, "_npmVersion": "3.5.0", "_phantomChildren": {}, "_requested": { "raw": "event-target-shim@^1.0.5", "scope": null, "escapedName": "event-target-shim", "name": "event-target-shim", "rawSpec": "^1.0.5", "spec": ">=1.0.5 <2.0.0", "type": "range" }, "_requiredBy": [ "/react-native" ], "_resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-1.1.1.tgz", "_shasum": "a86e5ee6bdaa16054475da797ccddf0c55698491", "_shrinkwrap": null, "_spec": "event-target-shim@^1.0.5", "_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/react-native", "author": { "name": "Toru Nagashima" }, "bugs": { "url": "https://github.com/mysticatea/event-target-shim/issues" }, "dependencies": {}, "description": "An implementation of W3C EventTarget interface.", "devDependencies": { "browserify": "^12.0.1", "browserify-istanbul": "^0.2.1", "coveralls": "^2.11.4", "eslint": "^1.10.2", "eslint-config-mysticatea": "^1.9.0", "eslint-plugin-mysticatea": "^1.0.3", "eslint-plugin-node": "^0.2.0", "espower-loader": "^1.0.0", "espowerify": "^1.0.0", "istanbul": "^0.4.1", "karma": "^0.13.15", "karma-browserify": "^4.2.1", "karma-chrome-launcher": "^0.2.1", "karma-coverage": "^0.5.3", "karma-firefox-launcher": "^0.1.6", "karma-growl-reporter": "^0.1.1", "karma-ie-launcher": "^0.2.0", "karma-mocha": "^0.2.1", "mkdirp": "^0.5.1", "mocha": "^2.2.5", "npm-run-all": "^1.2.5", "power-assert": "^1.2.0", "rimraf": "^2.3.4", "spy": "^0.1.3", "uglify-js": "^2.6.1" }, "directories": {}, "dist": { "shasum": "a86e5ee6bdaa16054475da797ccddf0c55698491", "tarball": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-1.1.1.tgz" }, "files": [ "dist", "lib" ], "gitHead": "a42f0a2b99fcea18856cbc64ab3b5f0aceaecb7b", "homepage": "https://github.com/mysticatea/event-target-shim", "keywords": [ "w3c", "eventtarget", "event", "events", "shim" ], "license": "MIT", "main": "lib/event-target.js", "maintainers": [ { "name": "mysticatea", "email": "star.ctor@gmail.com" } ], "name": "event-target-shim", "optionalDependencies": {}, "readme": "# event-target-shim\n\n[![Build Status](https://travis-ci.org/mysticatea/event-target-shim.svg?branch=master)](https://travis-ci.org/mysticatea/event-target-shim)\n[![Coverage Status](https://coveralls.io/repos/mysticatea/event-target-shim/badge.svg?branch=master&service=github)](https://coveralls.io/github/mysticatea/event-target-shim?branch=master)\n[![Dependency Status](https://david-dm.org/mysticatea/event-target-shim.svg)](https://david-dm.org/mysticatea/event-target-shim)\n[![devDependency Status](https://david-dm.org/mysticatea/event-target-shim/dev-status.svg)](https://david-dm.org/mysticatea/event-target-shim#info=devDependencies)
\n[![npm version](https://img.shields.io/npm/v/event-target-shim.svg)](https://www.npmjs.com/package/event-target-shim)\n[![Downloads/month](https://img.shields.io/npm/dm/event-target-shim.svg)](https://www.npmjs.com/package/event-target-shim)\n\nAn implementation of [W3C EventTarget interface](http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-EventTarget), plus few extensions.\n\n- This provides `EventTarget` constructor that can inherit for your custom object.\n- This provides an utility that defines properties of attribute listeners (e.g. `obj.onclick`).\n\n```js\n// The prototype of this class has getters and setters of `onmessage` and `onerror`.\nclass Foo extends EventTarget(\"message\", \"error\") {\n //...\n}\n```\n\n## Installation\n\n```\nnpm install --save event-target-shim\n```\n\nOr download from `dist` directory.\n\n## Usage\n\n### Basic\n\n```js\n//-----------------------------------------------------------------------------\n// import (with browserify, webpack, etc...).\nconst EventTarget = require(\"event-target-shim\");\n\n//-----------------------------------------------------------------------------\n// define a custom type.\nclass Foo extends EventTarget {\n}\n\n//-----------------------------------------------------------------------------\n// add event listeners.\nlet foo = new Foo();\nfoo.addEventListener(\"foo\", event => {\n console.log(event.hello);\n});\nfoo.addEventListener(\"foo\", event => {\n if (event.hello !== \"hello\") {\n // event implements Event interface.\n event.preventDefault();\n }\n});\n\n//-----------------------------------------------------------------------------\n// dispatch an event.\nlet event = document.createEvent(\"CustomEvent\");\nevent.initCustomEvent(\"foo\", /*bubbles*/ false, /*cancelable*/ false, /*detail*/ null);\nevent.hello = \"hello\";\nfoo.dispatchEvent(event);\n\n//-----------------------------------------------------------------------------\n// dispatch an event simply (non standard).\nfoo.dispatchEvent({type: \"foo\", hello: \"hello\"});\n\n//-----------------------------------------------------------------------------\n// dispatch a cancelable event.\nif (!foo.dispatchEvent({type: \"foo\", cancelable: true, hello: \"hey\"})) {\n console.log(\"defaultPrevented\");\n}\n\n//-----------------------------------------------------------------------------\n// If `window.EventTarget` exists, `EventTarget` inherits from `window.EventTarget`.\nif (foo instanceof window.EventTarget) {\n console.log(\"yay!\");\n}\n```\n\n### The Extension for Attribute Listeners\n\n```js\n//-----------------------------------------------------------------------------\n// import (with browserify, webpack, etc...).\nconst EventTarget = require(\"event-target-shim\");\n\n//-----------------------------------------------------------------------------\n// define a custom type with attribute listeners.\nclass Foo extends EventTarget(\"message\", \"error\") {\n}\n// or non-variadic\nclass Foo extends EventTarget([\"message\", \"error\"]) {\n}\n\n//-----------------------------------------------------------------------------\n// add event listeners.\nlet foo = new Foo();\nfoo.onmessage = event => {\n console.log(event.data);\n};\nfoo.onerror = event => {\n console.log(event.message);\n};\nfoo.addEventListener(\"message\", event => {\n console.log(event.data);\n});\n\n//-----------------------------------------------------------------------------\n// dispatch a event simply (non standard).\nfoo.dispatchEvent({type: \"message\", data: \"hello\"});\nfoo.dispatchEvent({type: \"error\", message: \"an error\"});\n```\n\n### Use in ES5\n\n- Basic.\n\n ```js\n function Foo() {\n EventTarget.call(this);\n }\n\n Foo.prototype = Object.create(EventTarget.prototype, {\n constructor: {\n value: Foo,\n configurable: true,\n writable: true\n },\n\n //....\n });\n ```\n\n- With attribute listeners.\n\n ```js\n function Foo() {\n EventTarget.call(this);\n }\n\n Foo.prototype = Object.create(EventTarget(\"message\", \"error\").prototype, {\n // or\n // Foo.prototype = Object.create(EventTarget([\"message\", \"error\"]).prototype, {\n constructor: {\n value: Foo,\n configurable: true,\n writable: true\n },\n\n //....\n });\n ```\n\n### Use with RequireJS\n\n```js\nrequire([\"https://cdn.rawgit.com/mysticatea/event-target-shim/v1.1.0/dist/event-target-shim.min.js\"], function(EventTarget) {\n //...\n});\n```\n\n## API\n\n```ts\ndeclare class EventTarget {\n constructor();\n addEventListener(type: string, listener?: (event: Event) => void, capture: boolean = false): void;\n removeEventListener(type: string, listener?: (event: Event) => void, capture: boolean = false): void;\n dispatchEvent(event: Event | {type: string, cancelable?: boolean}): void;\n}\n\n// Define EventTarget type with attribute listeners.\ndeclare function EventTarget(...types: string[]): EventTarget;\ndeclare function EventTarget(types: string[]): EventTarget;\n```\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/mysticatea/event-target-shim.git" }, "scripts": { "build": "npm-run-all clean lint test build:*", "build:dist": "mkdirp dist && browserify lib/event-target.js --standalone event-target-shim > dist/event-target-shim.js", "build:dist-min": "uglifyjs dist/event-target-shim.js --compress --mangle > dist/event-target-shim.min.js", "clean": "rimraf coverage dist", "coveralls": "cat ./coverage/lcov.info | coveralls", "lint": "eslint lib test", "postversion": "git push && git push --tags", "preversion": "npm run build", "test": "npm-run-all clean lint && karma start karma.conf.js --single-run", "travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- test/**/*.js --require scripts/power-assert", "watch": "karma start karma.conf.js --watch" }, "version": "1.1.1" }