-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
38 lines (38 loc) · 4.61 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"name": "domnode-dom",
"version": "0.0.2",
"description": "DOMNode streams for HTMLElements",
"main": "index.js",
"directories": {
"example": "example",
"test": "test"
},
"dependencies": {
"domnode": "~0.0.3"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/chrisdickinson/domnode-dom.git"
},
"keywords": [
"domnode",
"htmlelement",
"streams",
"dom"
],
"author": {
"name": "Chris Dickinson"
},
"license": "MIT",
"readme": "# domnode-dom\n\nTurn DOM elements into readable / writable streams.\n\nDesigned for use with [Browserify](https://github.com/substack/browserify)\nand [domnode](https://github.com/maxogden/domnode).\n\n````javascript\n\nvar domstream = require('domstream')\n , input = document.querySelector('input[type=text]')\n , output = document.querySelector('div#output')\n\n// replace the contents entirely with plain text generated\n// by the <input> element!\ndomstream\n .createReadStream(input)\n .pipe(domstream.createWriteStream(output, 'text/plain'))\n\n\n// grab a url and replace the body with its contents!\n\nhttp\n .get('/some/url')\n .pipe(domstream.createAppendStream(output, 'text/html'))\n\n// extend mimetypes:\ndomstream.WriteStream.prototype.constructImagePng = function(data) {\n var img = document.createElement('img')\n img.src = data\n return img\n}\n\n// now anything you type will be used as the source for an image tag!\n// or replace the contents entirely with plain text!\ndomstream\n .createReadStream(input)\n .pipe(domstream.createWriteStream(output, 'image/png'))\n\n````\n\n\nTo view the example:\n\n````shell\n\n$ git clone git://github.com/chrisdickinson/domnode-dom.git\n$ cd domnode-dom.git\n$ browserify example.js > examples/main.bundle.js\n$ python -m SimpleHTTPServer 9090 &; bg;\n$ open http://localhost:9090/\n\n````\n\n## API\n\n#### domstream = require('domstream') -> DOMStream object\n\n### Write API\n\n#### domstream.createWriteStream(el, mimetype) -> DOMStream.WriteStream\n\nCreates a writable stream out of an element. Writing to this stream\nwill replace the contents of `el` with the incoming data (transformed\nby the mimetype.)\n\n#### domstream.createAppendStream(el, mimetype) -> DOMStream.WriteStream\n\nAs above, this will create a writable stream to an element's contents.\n\nHowever, unlike the above, writes to this element will append their data\n(transformed by mimetype) to the element, instead of replacing it.\n\n> ### Mimetypes\n>\n> Currently only two mimetypes are supported: `text/plain`\n> and `text/html`. The writable stream object dispatches based on its\n> mimetype in the following fashion:\n>\n> > `text/html` -> `writeStream.constructTextHtml`\n> > `text/plain` -> `writeStream.constructTextPlain`\n> > `application/json` -> `writeStream.constructApplicationJson` (example only)\n>\n> `text/plain` will properly create text nodes out of incoming data, while\n> `text/html` will create full DOMNodes out of the incoming data.\n\n### Read API\n\n#### domstream.createReadStream(el, eventName[, preventDefault=true]) -> DOMStream.ReadStream\n\nCreates a readable stream out of `eventName` events emitted by `el`.\n\nIn most cases, the emitted event will simply be the DOM event object.\n\nHowever, in the case of `submit`, `change`, `keyup` and `keydown`, the\nemitted data will be the current value of the element.\n\nIn the case of form elements, the current value will be a key-value mapping\nof all of their constituent inputs:\n\n````html\n\n<form id=\"form\">\n <input type=\"text\" id=\"text\" name=\"text\" />\n <input type=\"submit\" name=\"submit\" value=\"submit\" />\n</form>\n<a href=\"#\" id=\"anchor\">anchor</a>\n\n````\n\n````javascript\n\nvar form = document.getElementById('form')\n , text = document.getElementById('text')\n , anchor = document.getElementById('anchor')\n\nvar domstream = require('domstream')\n\n// will emit dom Event objects on click\ndomstream.createReadStream(anchor, 'click')\n .on('data', function(data) { console.log(data) })\n\n// will emit the current value of the input on keyup\ndomstream.createReadStream(text, 'keyup')\n .on('data', function(data) { console.log(data) })\n\n// will emit an object containing { text: <value of text input> }\n// when submitted\ndomstream.createReadStream(form, 'submit')\n .on('data', function(data) { console.log(data) })\n\n````\n\n## LICENSE\n\nMIT. \n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/chrisdickinson/domnode-dom/issues"
},
"_id": "domnode-dom@0.0.2",
"_from": "domnode-dom@~0.0.X"
}