Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yields/dom
Create a dom like structure from html string.
https://github.com/yields/dom
Last synced: 5 days ago
JSON representation
Create a dom like structure from html string.
- Host: GitHub
- URL: https://github.com/yields/dom
- Owner: yields
- Created: 2013-05-11T18:20:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-05-11T18:23:30.000Z (over 11 years ago)
- Last Synced: 2024-12-11T21:05:39.892Z (about 1 month ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# dom
Create a dom like structure from html.
## Installation
$ component install yields/dom
## Example
```html
dom
var el = document.querySelector('html')
, dom = require('dom')
, html = el.outerHTML
, refs = [];console.log(JSON.stringify(dom(html), stringify, 2));
function stringify(key, val){
if (key && 'object' == typeof val){
if (~refs.indexOf(val)) {
return val && val.name;
}
refs.push(val);
}
return val;
}
```
```json
[
{
"attrs": {},
"name": "html",
"text": "\n ",
"els": [
{
"parent": "Circular(html)",
"next": "Circular(body)",
"attrs": {},
"name": "head",
"text": "\n ",
"els": [
{
"parent": "Circular(head)",
"next": "Circular(script)",
"attrs": {},
"name": "title",
"text": "dom",
"els": []
},
{
"parent": "Circular(head)",
"prev": "Circular(title)",
"attrs": {
"src": "build/build.js"
},
"name": "script",
"text": "",
"els": []
}
]
},
{
"parent": "Circular(html)",
"prev": "Circular(head)",
"attrs": {},
"name": "body",
"text": "\n ",
"els": [
{
"parent": "Circular(body)",
"attrs": {},
"name": "script",
"text": "\n var el = document.querySelector('html')\n , dom = require('dom')\n , html = el.outerHTML\n , refs = [];\n\n console.log(JSON.stringify(dom(html), stringify, 2));\n\n function stringify(key, val){\n if (key && 'object' == typeof val){\n if (!val) return;\n if ('next' == key) return circular(val.name);\n if ('prev' == key) return circular(val.name);\n if ('parent' == key) return circular(val.name);\n refs.push(val);\n }\n return val;\n }\n\n function circular(name){\n return 'Circular(' + name + ')';\n }\n ",
"els": []
}
]
}
]
}
]
```## License
MIT