Skip to content

Commit 2316f65

Browse files
committed
chore: update docs
1 parent ad01cbd commit 2316f65

File tree

17 files changed

+156
-92
lines changed

17 files changed

+156
-92
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
## Start to develop and test
22

33
```bash
4-
yarn install
5-
yarn build
6-
yarn test
4+
npm install
5+
npm run build
6+
npm test
77
```
88

99
## Benchmark
1010

1111
```bash
1212
cargo benchmark
13-
yarn benchmark
13+
npm run benchmark
1414
```

README.md

Lines changed: 138 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# niddle
1+
# domparser-rs
22

3-
A super fast Node.js addon for HTML parsing and manipulation, written in Rust.
3+
A super fast Node.js addon for HTML parsing and manipulation, written in Rust. It aims to provide a standard-compliant DOM API for Node.js.
44

55
## Features
66

7+
- **Standard Compliant**: Implements standard DOM APIs including `DOMParser`, `querySelector`, `classList`, and more, making it easy to migrate from browser-based code.
78
- High-performance DOM parsing and manipulation
89
- Exposes a simple JavaScript API via NAPI-RS
910
- Designed for both server-side and CLI HTML processing
@@ -12,15 +13,15 @@ A super fast Node.js addon for HTML parsing and manipulation, written in Rust.
1213
## Installation
1314

1415
```bash
15-
yarn add niddle
16+
yarn add domparser-rs
1617
# or
17-
npm install niddle
18+
npm install domparser-rs
1819
```
1920

2021
## Usage
2122

2223
```js
23-
const { parse } = require('niddle');
24+
const { parse } = require('domparser-rs');
2425
const root = parse('<div id="foo" class="bar">hello <span>world</span></div>');
2526

2627
const div = root.select('div');
@@ -36,83 +37,157 @@ console.log(div.outerHtml()); // <div id="foo" class="bar" title="my-title">hell
3637

3738
Parses an HTML string and returns a `NodeRepr` instance representing the root node.
3839

39-
#### Parameters
40+
### `DOMParser` Class
4041

41-
- `html` (string): The HTML content to parse.
42-
43-
#### Returns
44-
45-
- `NodeRepr`: The parsed root node.
42+
#### `parseFromString(string: string, mimeType: string): NodeRepr`
43+
Parses a string using the specified MIME type (e.g., "text/html").
4644

4745
---
4846

4947
### `NodeRepr` Class
5048

5149
Represents a DOM node and provides various manipulation methods.
5250

53-
#### Methods
54-
55-
- **append(content: string | NodeRepr): void**
56-
- Appends a new node or HTML string as a child.
57-
- **appendSequence(nodes: NodeRepr[]): void**
58-
- Appends multiple nodes.
59-
- **clone(): NodeRepr**
60-
- Clones the current node (not including descendants).
61-
- **cloneRecursive(): NodeRepr**
62-
- Clones the node and all descendants.
63-
- **getAttribute(name: string): string**
64-
- Gets an attribute value by name.
65-
- **getAttributes(): Record<string, string>**
66-
- Gets all attributes as a key-value object.
67-
- **getChildren(): NodeRepr[]**
68-
- Returns all child nodes.
69-
- **innerHtml(): string**
70-
- Gets the HTML content of all descendants.
71-
- **insertAfter(node: NodeRepr): void**
72-
- Inserts the current node after the specified node.
73-
- **insertBefore(node: NodeRepr): void**
74-
- Inserts the current node before the specified node.
75-
- **insertSequenceAfter(nodes: NodeRepr[]): void**
76-
- Inserts multiple nodes after the current node.
77-
- **insertSequenceBefore(nodes: NodeRepr[]): void**
78-
- Inserts multiple nodes before the current node.
79-
- **outerHtml(): string**
80-
- Gets the HTML content including the node itself.
81-
- **prepend(content: string | NodeRepr): void**
82-
- Prepends a new node or HTML string as a child.
83-
- **prependSequence(nodes: NodeRepr[]): void**
84-
- Prepends multiple nodes.
85-
- **remove(): void**
86-
- Removes the node from the DOM.
87-
- **removeAllAttributes(): void**
88-
- Removes all attributes from the node.
89-
- **removeAttribute(name: string): void**
90-
- Removes an attribute by name.
91-
- **select(selectors: string): NodeRepr**
92-
- Selects the first node matching the selector.
93-
- **selectAll(selectors: string): NodeRepr[]**
94-
- Selects all nodes matching the selector.
95-
- **setAttribute(name: string, value: string): void**
96-
- Sets an attribute value.
97-
- **setAttributes(attrs: Record<string, string>): void**
98-
- Sets multiple attributes.
99-
- **text(): string**
100-
- Gets the text content of the node.
51+
#### Properties (Getters/Setters)
52+
53+
- `nodeType`: number
54+
- `nodeName`: string
55+
- `tagName`: string | null
56+
- `namespaceURI`: string | null
57+
- `prefix`: string | null
58+
- `localName`: string | null
59+
- `id`: string
60+
- `className`: string
61+
- `parentNode`: NodeRepr | null
62+
- `parentElement`: NodeRepr | null
63+
- `firstChild`: NodeRepr | null
64+
- `lastChild`: NodeRepr | null
65+
- `previousSibling`: NodeRepr | null
66+
- `nextSibling`: NodeRepr | null
67+
- `firstElementChild`: NodeRepr | null
68+
- `lastElementChild`: NodeRepr | null
69+
- `previousElementSibling`: NodeRepr | null
70+
- `nextElementSibling`: NodeRepr | null
71+
- `children`: NodeRepr[]
72+
- `childElementCount`: number
73+
- `nodeValue`: string | null
74+
- `data`: string | null
75+
- `textContent`: string
76+
- `innerHTML`: string
77+
- `outerHTML`: string
78+
- `ownerDocument`: NodeRepr | null
79+
- `childNodes`: NodeRepr[]
80+
- `isConnected`: boolean
81+
- `doctype`: NodeRepr | null
82+
- `head`: NodeRepr | null
83+
- `body`: NodeRepr | null
84+
- `title`: string
85+
- `documentElement`: NodeRepr | null
86+
87+
#### Manipulation Methods
88+
89+
- `append(newChild: NodeRepr): void`
90+
- `appendChild(newChild: NodeRepr): NodeRepr`
91+
- `prepend(newChild: NodeRepr): void`
92+
- `after(newSibling: NodeRepr): void`
93+
- `before(newSibling: NodeRepr): void`
94+
- `insertBefore(newNode: NodeRepr, refNode?: NodeRepr | null): NodeRepr`
95+
- `replaceChild(newChild: NodeRepr, oldChild: NodeRepr): NodeRepr`
96+
- `replaceWith(newNode: NodeRepr): void`
97+
- `remove(): void`
98+
- `clone(): NodeRepr` (Shallow clone)
99+
- `cloneRecursive(): NodeRepr` (Deep clone)
100+
- `cloneNode(deep?: boolean): NodeRepr`
101+
- `importNode(externalNode: NodeRepr, deep?: boolean): NodeRepr`
102+
- `adoptNode(externalNode: NodeRepr): NodeRepr`
103+
- `normalize(): void`
104+
105+
#### Attribute Methods
106+
107+
- `getAttribute(name: string): string | null`
108+
- `setAttribute(name: string, value: string): void`
109+
- `removeAttribute(name: string): void`
110+
- `toggleAttribute(name: string, force?: boolean): boolean`
111+
- `hasAttribute(name: string): boolean`
112+
- `getAttributeNames(): string[]`
113+
- `getAttributes(): Record<string, string>`
114+
- `getAttributeNS(namespace: string | null, localName: string): string | null`
115+
- `setAttributeNS(namespace: string | null, name: string, value: string): void`
116+
- `removeAttributeNS(namespace: string | null, localName: string): void`
117+
- `hasAttributeNS(namespace: string | null, localName: string): boolean`
118+
119+
#### Query & Selection Methods
120+
121+
- `select(selectors: string): NodeRepr | null`
122+
- `selectAll(selectors: string): NodeRepr[]`
123+
- `querySelector(selectors: string): NodeRepr | null`
124+
- `querySelectorAll(selectors: string): NodeRepr[]`
125+
- `getElementById(id: string): NodeRepr | null`
126+
- `getElementsByClassName(classNames: string): NodeRepr[]`
127+
- `getElementsByTagName(tagName: string): NodeRepr[]`
128+
- `matches(selectors: string): boolean`
129+
- `closest(selectors: string): NodeRepr | null`
130+
- `contains(otherNode: NodeRepr): boolean`
131+
132+
#### ClassList & Dataset
133+
134+
- `classListAdd(className: string): void`
135+
- `classListRemove(className: string): void`
136+
- `classListToggle(className: string, force?: boolean): boolean`
137+
- `classListContains(className: string): boolean`
138+
- `datasetGet(): Record<string, string>`
139+
- `datasetSet(key: string, value: string): void`
140+
- `datasetRemove(key: string): void`
141+
142+
#### Other Methods
143+
144+
- `text(): string`
145+
- `innerHtml(): string`
146+
- `outerHtml(): string`
147+
- `createElement(tagName: string): NodeRepr`
148+
- `createTextNode(data: string): NodeRepr`
149+
- `createComment(data: string): NodeRepr`
150+
- `createDocumentFragment(): NodeRepr`
151+
- `createProcessingInstruction(target: string, data: string): NodeRepr`
152+
- `isSameNode(otherNode: NodeRepr): boolean`
153+
- `isEqualNode(otherNode: NodeRepr): boolean`
154+
- `compareDocumentPosition(other: NodeRepr): number`
155+
- `lookupPrefix(namespace?: string): string | null`
156+
- `lookupNamespaceURI(prefix?: string): string | null`
157+
- `isDefaultNamespace(namespace?: string): boolean`
158+
- `getRootNode(): NodeRepr`
159+
- `hasChildNodes(): boolean`
160+
- `hasAttributes(): boolean`
161+
162+
#### Text Node Methods
163+
164+
- `splitText(offset: number): NodeRepr`
165+
- `substringData(offset: number, count: number): string`
166+
- `appendData(data: string): void`
167+
- `insertData(offset: number, data: string): void`
168+
- `deleteData(offset: number, count: number): void`
169+
- `replaceData(offset: number, count: number, data: string): void`
170+
171+
#### Insertion Methods
172+
173+
- `insertAdjacentElement(position: string, element: NodeRepr): NodeRepr | null`
174+
- `insertAdjacentText(position: string, data: string): void`
175+
- `insertAdjacentHTML(position: string, html: string): void`
101176

102177

103178
## Contributing
104179

105180
```bash
106-
yarn install
107-
yarn build
108-
yarn test
181+
npm install
182+
npm run build
183+
npm test
109184
```
110185

111186
## Benchmark
112187

113188
```bash
114189
cargo benchmark
115-
yarn benchmark
190+
npm run benchmark
116191
```
117192

118193
---

npm/android-arm-eabi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"android"
3030
]

npm/android-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"android"
3030
]

npm/darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"darwin"
3030
]

npm/darwin-universal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"engines": {
2222
"node": ">= 10"
2323
},
24-
"repository": "https://github.com/xusd320/domparser-rs",
24+
"repository": "https://github.com/utooland/domparser-rs",
2525
"os": [
2626
"darwin"
2727
]

npm/freebsd-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"freebsd"
3030
]

npm/linux-arm-gnueabihf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"linux"
3030
]

npm/linux-arm-musleabihf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"linux"
3030
]

npm/linux-arm64-gnu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"engines": {
2525
"node": ">= 10"
2626
},
27-
"repository": "https://github.com/xusd320/domparser-rs",
27+
"repository": "https://github.com/utooland/domparser-rs",
2828
"os": [
2929
"linux"
3030
],

0 commit comments

Comments
 (0)