0.1.0-7 • Published 3 years ago
domsday v0.1.0-7
domsday
Lightweight DOM-like nodes that don't try to be too clever.
- Lightweight
- Ignores unopened close tags, autocloses unclosed start tags
- Preserves original original chars (including newlines)
- Doesn't cleanup outdated
.children
references .nodeType
uses (standard values)https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
import Node from 'domsday'
Node.fromString('<div>qwe</div>')
/* =>
Node { nodeType: DOCUMENT_NODE, children: [
Node { nodeType: ELEMENT_NODE children: [
Node { nodeType: TEXT_NODE, text: 'qwe' },
]},
], type: DOCUMENT_NODE }
*/
Get node types with:
import { ELEMENT_NODE } from 'domsday/src/node-types'
Features in depth
Preserves original chars
domsday
mixed line endings, mixed tabs and spaces, original newlines
and whatever other freaky stuff you're into.
For example:
Node.fromString('<!DOCTYPE html>\n\they')
/* => Node { type: DOCUMENT_NODE, children: [
Node { type: DOCUMENT_TYPE_NODE, contents: ' html' },
Node { type: TEXT_NODE, text: '\n\they' },
]}
*/
The objective of this is to keep builds as closest to originals as possible.
Doesn't cleanup outdated .children
references
A Node
instance .children
is an array with no protection.
When a child Node
changes parent, references to it in previous parent are still kept.
For our purposes we usually don't care about this, and we save doing unnecessary things.