Skip to content

Commit f4ab2a3

Browse files
committed
Restructure README
1 parent b0859b6 commit f4ab2a3

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

README.md

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Fast, tiny, standards-compliant XML DOM implementation for node and the browser.
77

8-
This is a (partial) implementation of the [DOM living standard][domstandard], as last updated 1 March 2019, and the [DOM Parsing and Serialization W3C Editor's Draft][domparsing], as last updated 11 February 2019. See the 'Features' and 'Limitations' sections below for details on what's included and what's not.
8+
This is a (partial) implementation of the [DOM living standard][domstandard], as last updated 1 March 2019, and the [DOM Parsing and Serialization W3C Editor's Draft][domparsing], as last updated 11 February 2019. See the 'Features and Limitations' section below for details on what's included and what's not.
99

1010
[domstandard]: https://dom.spec.whatwg.org/
1111
[domparsing]: https://w3c.github.io/DOM-Parsing/
@@ -24,26 +24,28 @@ or
2424
yarn add slimdom
2525
```
2626

27-
The package includes both a commonJS bundle (`dist/slimdom.js`) and an ES6 module (`dist/slimdom.mjs`).
27+
The package includes both a commonJS-compatible UMD bundle (`dist/slimdom.js`) and an ES6 module (`dist/slimdom.mjs`). This means it should work in most JavaScript environments that support the ES2017 standard or newer.
2828

2929
## Usage
3030

3131
Create documents using the slimdom.Document constructor, and manipulate them using the [standard DOM API][domstandard].
3232

3333
```javascript
3434
import * as slimdom from 'slimdom';
35+
// alternatively, in node and other commonJS environments:
36+
// const slimdom = require('slimdom');
3537

3638
const document = new slimdom.Document();
3739
document.appendChild(document.createElementNS('http://www.example.com', 'root'));
3840
const xml = slimdom.serializeToWellFormedString(document);
3941
// -> '<root xmlns="http://www.example.com"/>'
4042
```
4143

42-
Some DOM API's, such as the `DocumentFragment` constructor, require the presence of a global document. In these cases, slimdom will use the instance exposed through `slimdom.document`. Although you could mutate this document, it is recommended to create your own to avoid conflicts with other code using slimdom in your application.
44+
Some DOM API's, such as the `DocumentFragment` constructor, require the presence of a global document, for instance to set their initial `ownerDocument` property. In these cases, slimdom will use the instance exposed through `slimdom.document`. Although you could mutate this document, it is recommended to always create your own documents (using the `Document` constructor) to avoid conflicts with other code using slimdom in your application.
4345

44-
When using a `Range`, make sure to call `detach` when you don't need it anymore. As JavaScript currently does not have a way to detect when the instance can be garbage collected, we don't have any other way of detecting when we can stop updating the range for mutations to the surrounding nodes.
46+
When using a `Range`, make sure to call `detach` when you don't need it anymore. As we do not have a way to detect when a Range is no longer used, this library needs to be notified when it can stop updating the range for mutations to the surrounding nodes.
4547

46-
## Features
48+
## Features and limitations
4749

4850
This library implements:
4951

@@ -52,34 +54,54 @@ This library implements:
5254
- `MutationObserver`
5355
- `XMLSerializer`, and read-only versions of `innerHTML` / `outerHTML` on `Element`.
5456

55-
## Limitations
57+
This library is currently aimed at providing a lightweight and consistent experience for dealing with XML and XML-like data. For simplicity and efficiency, this implementation deviates from the spec in a few minor ways. Most notably, normal JavaScript arrays are used instead of `HTMLCollection` / `NodeList` and `NamedNodeMap`, HTML documents are treated no different from other documents and a number of features from in the DOM spec are missing. In most cases, this is because alternatives are available that can be used together with slimdom with minimal effort.
5658

57-
For simplicity and efficiency, this implementation deviates from the spec in a few minor ways. Most notably, normal JavaScript arrays are used instead of `HTMLCollection` / `NodeList` and `NamedNodeMap`.
59+
Do not rely on the behavior or presence of any methods and properties not specified in the DOM standard. For example, do not use JavaScript array methods exposed on properties that should expose a NodeList and do not use Element as a constructor. This behavior is _not_ considered public API and may change without warning in a future release.
60+
61+
### Parsing
62+
63+
This library does not implement the `DOMParser` interface, nor `insertAdjacentHTML` on `Element`, nor `createContextualFragment` on `Range`. The `innerHTML` and `outerHTML` properties are read-only,
64+
65+
If you need to parse XML, use [slimdom-sax-parser][slimdom-sax-parser]. See its README for examples.
66+
67+
If you need to parse HTML, see [this example][parse5-example] which shows how to connect the [parse5][parse5] HTML parser with the help of the [dom-treeadapter][dom-treeadapter] library.
68+
69+
### CSS Selectors and XPath
70+
71+
This library does not implement CSS selectors, which means no `querySelector` / `querySelectorAll` on `ParentNode` and no `closest` / `matches` / `webkitMatchesSelector` on `Element`.
72+
73+
To query a slimdom document using XPath or XQuery, use [FontoXPath][fontoxpath].
74+
75+
### HTML & browser-specific features and behavior
5876

59-
The following features have not yet been implemented:
77+
Emulating a full browser environment is not the goal of this library. Consider using [jsdom][jsdom] instead if you need that.
6078

61-
- No XML parsing (no `DOMParser`, `innerHTML` and `outerHTML` are read-only, no `insertAdjacentHTML` on `Element`, no `createContextualFragment` on `Range`). If you need to parse XML, consider using [slimdom-sax-parser][slimdom-sax-parser].
62-
- No CSS selectors, so no `querySelector` / `querySelectorAll` on `ParentNode`, no `closest` / `matches` / `webkitMatchesSelector` on `Element`. The older non-CSS query methods (`getElementById` for interface `NonElementParentNode`, and `getElementsByTagName` / `getElementsByTagNameNS` / `getElementsByClassName` on `Document`) have not yet been implemented either. To query the DOM, consider using [FontoXPath][fontoxpath].
63-
- No HTML parsing / serialization, but see [this example][parse5-example] which shows how to connect the [parse5][parse5] HTML parser with the help of the [dom-treeadapter][dom-treeadapter] library.
64-
- No special treatment of HTML documents, including `HTMLElement` and its subclasses. This also includes HTML casing behavior for attributes and tagNames, as well as the `id` / `className` / `classList` properties on `Element` and `compatMode` / `contentType` on `Document`.
65-
- No events, no `createEvent` on `Document`.
66-
- No support for shadow DOM, `Slotable` / `ShadowRoot`, no `slot` / `attachShadow` / `shadowRoot` on `Element`.
67-
- No support for custom elements or the `is` option on `createElement` / `createElementNS`.
68-
- No iteration helpers (`NodeIterator` / `TreeWalker` / `NodeFilter`, and the `createNodeIterator` / `createTreeWalker` methods on `Document`).
69-
- No DOM modifying methods on Range (`deleteContents` / `extractContents` / `cloneContents` / `insertNode` / `surroundContents`).
70-
- No `attributeFilter` for mutation observers.
71-
- No `isConnected` / `getRootNode` / `isEqualNode` / `isSameNode` / `compareDocumentPosition` on `Node`
72-
- No notion of URLs (`baseURI` on `Node`, and `URL` / `documentURI` / `origin` on `Document`).
73-
- No notion of encodings (`characterSet` / `charset` / `inputEncoding` on `Document`). This library only deals with JavaScript strings, not raw byte streams.
74-
- No properties / methods that exist mainly for web compatibility reasons (`insertAdjacentElement` / `insertAdjacentText` on `Element`, `hasFeature` on `DOMImplementation`, and `specified` on `Attr`).
79+
This implementation offers no special treatment of HTML documents, which means there are no implementations of `HTMLElement` and its subclasses. This also affects HTML-specific casing behavior for attributes and tagNames. The `id` / `className` / `classList` properties on `Element` and `compatMode` / `contentType` on `Document` have not been implemented. HTML-specific query methods (`getElementById` for interface `NonElementParentNode`, `getElementsByClassName` on `Document`) are also missing.
80+
81+
This library also does not currently implement events, including the `Event` / `EventTarget` interfaces. It also currently does not contain an implementation of `AbortController` / `AbortSignal`. As these may have wider applications than browser-specific use cases, please file an issue if you have a use for these in your application and would like support for them to be added.
82+
83+
There is currently no support for shadow DOM, so no `Slotable` / `ShadowRoot` interfaces and no `slot` / `attachShadow` / `shadowRoot` on `Element`. Slimdom also does not support the APIs for custom elements using the `is` option on `createElement` / `createElementNS`.
84+
85+
This library has no notion of URLs (`baseURI` on `Node`, and `URL` / `documentURI` / `origin` on `Document`), nor of encodings (`characterSet` / `charset` / `inputEncoding` on `Document`). This library only deals with JavaScript strings, not raw byte streams.
86+
87+
This library omits properties and methods that exist mainly for web compatibility reasons (`insertAdjacentElement` / `insertAdjacentText` on `Element`, `hasFeature` on `DOMImplementation`, and `specified` on `Attr`).
88+
89+
### Miscellaneous
90+
91+
The following features are missing simply because I have not yet had a need for them. If you do need one, feel free to create a feature request issue or even submit a pull request.
92+
93+
- Older non-CSS, non-HTML query methods (`getElementsByTagName` / `getElementsByTagNameNS` on `Document`).
94+
- Iteration helpers (`NodeIterator` / `TreeWalker` / `NodeFilter`, and the `createNodeIterator` / `createTreeWalker` methods on `Document`).
95+
- DOM-modifying methods on Range (`deleteContents` / `extractContents` / `cloneContents` / `insertNode` / `surroundContents`).
96+
- `attributeFilter` for mutation observers.
97+
- `isConnected` / `getRootNode` / `isEqualNode` / `isSameNode` / `compareDocumentPosition` on `Node`
7598

7699
[slimdom-sax-parser]: https://github.com/wvbe/slimdom-sax-parser
77100
[fontoxpath]: https://github.com/FontoXML/fontoxpath/
78101
[parse5-example]: https://github.com/bwrrp/slimdom.js/tree/master/test/examples/parse5
79102
[parse5]: https://github.com/inikulin/parse5
80103
[dom-treeadapter]: https://github.com/RReverser/dom-treeadapter
81-
82-
Do not rely on the behavior or presence of any methods and properties not specified in the DOM standard. For example, do not use JavaScript array methods exposed on properties that should expose a NodeList and do not use Element as a constructor. This behavior is _not_ considered public API and may change without warning in a future release.
104+
[jsdom]: https://github.com/jsdom/jsdom
83105

84106
## Contributing
85107

0 commit comments

Comments
 (0)