netscape-bookmark-parser 1.1.3 โ 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README-ja.md +233 -386
- package/README.md +152 -302
- package/dist/index.d.ts +240 -0
- package/dist/index.js +333 -0
- package/dist/index.js.map +1 -0
- package/dist/web.d.ts +241 -0
- package/dist/web.js +330 -0
- package/dist/web.js.map +1 -0
- package/package.json +58 -15
- package/esm/_dnt.polyfills.d.ts +0 -101
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -127
- package/esm/_dnt.shims.d.ts +0 -6
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -61
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts +0 -14
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.js +0 -151
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts +0 -23
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js +0 -26
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts +0 -24
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.js +0 -48
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.js +0 -4
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts +0 -4
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.js +0 -61
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts +0 -19
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.js +0 -110
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts +0 -68
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.js +0 -322
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts +0 -6
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.js +0 -46
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts +0 -127
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.js +0 -1068
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts +0 -29
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.js +0 -94
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts +0 -21
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.js +0 -80
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts +0 -23
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.js +0 -159
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts +0 -127
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.js +0 -629
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts +0 -6
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.js +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts +0 -12
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.js +0 -2
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts +0 -90
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.js +0 -1611
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts +0 -16
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.js +0 -28
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts +0 -8
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.js +0 -2
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts +0 -7
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.js +0 -2061
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts +0 -3
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.js +0 -10
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts +0 -13
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.js +0 -8
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts +0 -31
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.js +0 -239
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts +0 -5
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts.map +0 -1
- package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.js +0 -20
- package/esm/mod.d.ts +0 -10
- package/esm/mod.d.ts.map +0 -1
- package/esm/mod.js +0 -9
- package/esm/mod_web.d.ts +0 -9
- package/esm/mod_web.d.ts.map +0 -1
- package/esm/mod_web.js +0 -8
- package/esm/package.json +0 -3
- package/esm/src/BookmarksParser/BookmarksParser.d.ts +0 -66
- package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/BookmarksParser/BookmarksParser.js +0 -70
- package/esm/src/BookmarksParser/index.d.ts +0 -8
- package/esm/src/BookmarksParser/index.d.ts.map +0 -1
- package/esm/src/BookmarksParser/index.js +0 -7
- package/esm/src/BookmarksTree/BookmarksTree.d.ts +0 -112
- package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/BookmarksTree/BookmarksTree.js +0 -217
- package/esm/src/BookmarksTree/index.d.ts +0 -8
- package/esm/src/BookmarksTree/index.d.ts.map +0 -1
- package/esm/src/BookmarksTree/index.js +0 -7
- package/esm/src/deps.d.ts +0 -9
- package/esm/src/deps.d.ts.map +0 -1
- package/esm/src/deps.js +0 -7
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +0 -66
- package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +0 -1
- package/esm/src/web/BookmarksParser/BookmarksParser.js +0 -70
- package/esm/src/web/BookmarksParser/index.d.ts +0 -8
- package/esm/src/web/BookmarksParser/index.d.ts.map +0 -1
- package/esm/src/web/BookmarksParser/index.js +0 -7
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +0 -112
- package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +0 -1
- package/esm/src/web/BookmarksTree/BookmarksTree.js +0 -217
- package/esm/src/web/BookmarksTree/index.d.ts +0 -8
- package/esm/src/web/BookmarksTree/index.d.ts.map +0 -1
- package/esm/src/web/BookmarksTree/index.js +0 -7
- package/esm/src/web/deps.d.ts +0 -10
- package/esm/src/web/deps.d.ts.map +0 -1
- package/esm/src/web/deps.js +0 -9
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ A TypeScript/JavaScript library for parsing browser bookmark files (HTML format)
|
|
|
4
4
|
|
|
5
5
|
> **Note:**
|
|
6
6
|
> This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
ๆฅๆฌ่ชใใญใฅใกใณใ: [`./README-ja.md`](./README-ja.md)
|
|
8
9
|
|
|
9
10
|
## Features
|
|
10
11
|
|
|
@@ -30,13 +31,10 @@ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
|
|
|
30
31
|
### Deno
|
|
31
32
|
|
|
32
33
|
```typescript
|
|
33
|
-
import {
|
|
34
|
-
BookmarksParser,
|
|
35
|
-
BookmarksTree,
|
|
36
|
-
} from "jsr:@grakeice/netscape-bookmark-parser";
|
|
34
|
+
import { BookmarksParser, BookmarksTree } from "jsr:@grakeice/netscape-bookmark-parser";
|
|
37
35
|
```
|
|
38
36
|
|
|
39
|
-
> **Note:** The JSR
|
|
37
|
+
> **Note:** The JSR package provides the Node.js/Deno entry. For browser support, use the npm package's dependency-free `./web` entry.
|
|
40
38
|
|
|
41
39
|
### Browser
|
|
42
40
|
|
|
@@ -50,16 +48,16 @@ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
|
50
48
|
|
|
51
49
|
// Example: Parse uploaded bookmark file
|
|
52
50
|
function handleFileUpload(event: Event) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
const file = (event.target as HTMLInputElement).files?.[0];
|
|
52
|
+
if (file) {
|
|
53
|
+
const reader = new FileReader();
|
|
54
|
+
reader.onload = (e) => {
|
|
55
|
+
const htmlContent = e.target?.result as string;
|
|
56
|
+
const bookmarksTree = BookmarksParser.parse(htmlContent);
|
|
57
|
+
console.log(bookmarksTree.toJSON());
|
|
58
|
+
};
|
|
59
|
+
reader.readAsText(file);
|
|
60
|
+
}
|
|
63
61
|
}
|
|
64
62
|
```
|
|
65
63
|
|
|
@@ -67,17 +65,15 @@ function handleFileUpload(event: Event) {
|
|
|
67
65
|
|
|
68
66
|
```html
|
|
69
67
|
<script type="importmap">
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
{
|
|
69
|
+
"imports": {
|
|
70
|
+
"netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.4/dist/web.js"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
75
73
|
</script>
|
|
76
74
|
<script type="module">
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Works the same as local imports
|
|
80
|
-
const tree = BookmarksParser.parse(htmlContent);
|
|
75
|
+
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
76
|
+
const tree = BookmarksParser.parse(htmlContent);
|
|
81
77
|
</script>
|
|
82
78
|
```
|
|
83
79
|
|
|
@@ -85,16 +81,14 @@ function handleFileUpload(event: Event) {
|
|
|
85
81
|
|
|
86
82
|
```html
|
|
87
83
|
<script type="module">
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Direct CDN import without import maps
|
|
84
|
+
import {
|
|
85
|
+
BookmarksParser,
|
|
86
|
+
BookmarksTree,
|
|
87
|
+
} from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.4/dist/web.js";
|
|
94
88
|
</script>
|
|
95
89
|
```
|
|
96
90
|
|
|
97
|
-
> **Browser Support:**
|
|
91
|
+
> **Browser Support:** The web-optimized version is available from the npm `./web` export. It uses native browser APIs and has no DOM library dependency.
|
|
98
92
|
|
|
99
93
|
> **Note:** The web-optimized version uses native browser APIs (DOMParser, etc.) and does not include Node.js polyfills, making it lighter and faster in browser environments.
|
|
100
94
|
|
|
@@ -203,119 +197,146 @@ console.log(devFolder.get("GitHub")); // "https://github.com"
|
|
|
203
197
|
|
|
204
198
|
### Web-Optimized Version
|
|
205
199
|
|
|
206
|
-
> **Important:** Browser support is
|
|
200
|
+
> **Important:** Browser support is available from the npm `./web` export.
|
|
207
201
|
|
|
208
202
|
The library provides a browser-optimized version that eliminates Node.js dependencies and uses native browser APIs:
|
|
209
203
|
|
|
210
204
|
```typescript
|
|
211
|
-
// Import browser-optimized version
|
|
205
|
+
// Import the browser-optimized version
|
|
212
206
|
import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
|
|
213
207
|
```
|
|
214
208
|
|
|
209
|
+
> **Note:** The web-optimized version uses native browser APIs (DOMParser, etc.) and does not include Node.js polyfills, making it lighter and faster in browser environments.
|
|
210
|
+
|
|
215
211
|
### BookmarksParser Class
|
|
216
212
|
|
|
217
|
-
|
|
213
|
+
`BookmarksParser` provides static methods to parse Netscape Bookmark format HTML or JSON and convert them into `BookmarksTree` instances.
|
|
218
214
|
|
|
219
|
-
####
|
|
215
|
+
#### Static Methods
|
|
220
216
|
|
|
221
|
-
|
|
217
|
+
- [`static parse(htmlString: string): BookmarksTree`](#static-parsehtmlstring-string-bookmarkstree)
|
|
222
218
|
|
|
223
|
-
-
|
|
224
|
-
-
|
|
219
|
+
- Parses a Netscape Bookmark format HTML string and returns a `BookmarksTree`.
|
|
220
|
+
- Alias for [`parseFromHTMLString`](#static-parsefromhtmlstringhtmlstring-string-bookmarkstree).
|
|
225
221
|
|
|
226
|
-
**Example:**
|
|
222
|
+
**Example:**
|
|
227
223
|
|
|
228
|
-
```typescript
|
|
229
|
-
const
|
|
230
|
-
const tree = BookmarksParser.parse(
|
|
231
|
-
|
|
224
|
+
```typescript
|
|
225
|
+
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<HTML><BODY><DL><p>\n <DT><A HREF=\"https://example.com\">Example</A>\n</DL><p></BODY></HTML>`;
|
|
226
|
+
const tree = BookmarksParser.parse(html);
|
|
227
|
+
console.log(tree.toJSON());
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
- [`static parseFromHTMLString(htmlString: string): BookmarksTree`](#static-parsefromhtmlstringhtmlstring-string-bookmarkstree)
|
|
231
|
+
|
|
232
|
+
- Parses a Netscape Bookmark format HTML string and returns a `BookmarksTree`.
|
|
233
|
+
|
|
234
|
+
**Example:**
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const html = `<!DOCTYPE NETSCAPE-Bookmark-file-1>...`;
|
|
238
|
+
const tree = BookmarksParser.parseFromHTMLString(html);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
- [`static parseFromDOM(dom: HTMLDocument): BookmarksTree`](#static-parsefromdomdom-htmldocument-bookmarkstree)
|
|
242
|
+
|
|
243
|
+
- Converts an existing `HTMLDocument` to a `BookmarksTree`.
|
|
244
|
+
|
|
245
|
+
**Example:**
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
const dom = new DOMParser().parseFromString(html, "text/html");
|
|
249
|
+
const tree = BookmarksParser.parseFromDOM(dom);
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
- [`static parseFromJSON(jsonString: string): BookmarksTree`](#static-parsefromjsonjsonstring-string-bookmarkstree)
|
|
253
|
+
|
|
254
|
+
- Parses a JSON string and returns a `BookmarksTree`.
|
|
255
|
+
|
|
256
|
+
**Example:**
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
const json = '{"Google": "https://google.com"}';
|
|
260
|
+
const tree = BookmarksParser.parseFromJSON(json);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
232
264
|
|
|
233
265
|
### BookmarksTree Class
|
|
234
266
|
|
|
235
|
-
|
|
267
|
+
`BookmarksTree` extends `Map` and manages folders (`BookmarksTree`) and bookmarks (URL strings) in a hierarchical structure.
|
|
236
268
|
|
|
237
269
|
#### Constructor
|
|
238
270
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
271
|
+
- [`new BookmarksTree()`](#constructor)
|
|
272
|
+
|
|
273
|
+
**Example:**
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const tree = new BookmarksTree();
|
|
277
|
+
tree.set("Google", "https://google.com");
|
|
278
|
+
```
|
|
242
279
|
|
|
243
280
|
#### Instance Methods
|
|
244
281
|
|
|
245
|
-
|
|
282
|
+
- [`toJSON(): Record<string, unknown>`](#tojson-recordstring-unknown)
|
|
246
283
|
|
|
247
|
-
|
|
284
|
+
- Converts the tree to a JSON object representation.
|
|
248
285
|
|
|
249
|
-
|
|
250
|
-
const json = tree.toJSON();
|
|
251
|
-
console.log(JSON.stringify(json, null, 2));
|
|
252
|
-
```
|
|
286
|
+
**Example:**
|
|
253
287
|
|
|
254
|
-
|
|
288
|
+
```typescript
|
|
289
|
+
const json = tree.toJSON();
|
|
290
|
+
console.log(json);
|
|
291
|
+
```
|
|
255
292
|
|
|
256
|
-
|
|
293
|
+
- [`toDOM(): HTMLDocument`](#todom-htmldocument)
|
|
257
294
|
|
|
258
|
-
|
|
259
|
-
const htmlDocument = tree.toDOM();
|
|
260
|
-
```
|
|
295
|
+
- Converts the tree to a Netscape Bookmark format HTML document.
|
|
261
296
|
|
|
262
|
-
|
|
297
|
+
**Example:**
|
|
263
298
|
|
|
264
|
-
|
|
299
|
+
```typescript
|
|
300
|
+
const dom = tree.toDOM();
|
|
301
|
+
```
|
|
265
302
|
|
|
266
|
-
|
|
267
|
-
const htmlString = tree.HTMLText;
|
|
268
|
-
console.log(htmlString); // Complete HTML bookmark file
|
|
269
|
-
```
|
|
303
|
+
- [`get HTMLString(): string`](#get-htmlstring-string)
|
|
270
304
|
|
|
271
|
-
|
|
305
|
+
- Gets the complete HTML string in Netscape Bookmark format.
|
|
272
306
|
|
|
273
|
-
|
|
307
|
+
**Example:**
|
|
274
308
|
|
|
275
|
-
|
|
309
|
+
```typescript
|
|
310
|
+
const html = tree.HTMLString;
|
|
311
|
+
console.log(html);
|
|
312
|
+
```
|
|
276
313
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const tree = BookmarksTree.fromJSON(json);
|
|
280
|
-
```
|
|
314
|
+
- [`get HTMLText(): string`](#get-htmltext-string)
|
|
315
|
+
- Alias for `HTMLString` (deprecated).
|
|
281
316
|
|
|
282
|
-
|
|
317
|
+
#### Static Methods
|
|
283
318
|
|
|
284
|
-
|
|
319
|
+
- [`static fromJSON(json: Record<string, unknown>): BookmarksTree`](#static-fromjsonjson-recordstring-unknown-bookmarkstree)
|
|
285
320
|
|
|
286
|
-
|
|
287
|
-
const dom = new DOMParser().parseFromString(htmlContent, "text/html");
|
|
288
|
-
const tree = BookmarksTree.fromDOM(dom);
|
|
289
|
-
```
|
|
321
|
+
- Creates a tree from a JSON object.
|
|
290
322
|
|
|
291
|
-
|
|
323
|
+
**Example:**
|
|
292
324
|
|
|
293
|
-
|
|
325
|
+
```typescript
|
|
326
|
+
const json = { Google: "https://google.com" };
|
|
327
|
+
const tree = BookmarksTree.fromJSON(json);
|
|
328
|
+
```
|
|
294
329
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
tree
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
tree.has("bookmark"); // true
|
|
306
|
-
|
|
307
|
-
// Delete items
|
|
308
|
-
tree.delete("bookmark");
|
|
309
|
-
|
|
310
|
-
// Iterate
|
|
311
|
-
for (const [name, value] of tree) {
|
|
312
|
-
if (typeof value === "string") {
|
|
313
|
-
console.log(`Bookmark: ${name} -> ${value}`);
|
|
314
|
-
} else {
|
|
315
|
-
console.log(`Folder: ${name} (${value.size} items)`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
```
|
|
330
|
+
- [`static fromDOM(dom: HTMLDocument): BookmarksTree`](#static-fromdomdom-htmldocument-bookmarkstree)
|
|
331
|
+
|
|
332
|
+
- Creates a tree from an HTML document.
|
|
333
|
+
|
|
334
|
+
**Example:**
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
const dom = new DOMParser().parseFromString(html, "text/html");
|
|
338
|
+
const tree = BookmarksTree.fromDOM(dom);
|
|
339
|
+
```
|
|
319
340
|
|
|
320
341
|
## Project Structure
|
|
321
342
|
|
|
@@ -330,16 +351,28 @@ src/
|
|
|
330
351
|
โโโ BookmarksParser.test.ts # Parser tests
|
|
331
352
|
โโโ index.ts # Export definitions
|
|
332
353
|
scripts/
|
|
333
|
-
โโโ
|
|
354
|
+
โโโ sync-jsr-version.mjs # Keep JSR version in sync with package.json
|
|
334
355
|
.github/
|
|
335
356
|
โโโ workflows/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
357
|
+
โโโ changesets.yml # Changesets version pull requests
|
|
358
|
+
โโโ ci.yml # Test, typecheck, and build checks
|
|
359
|
+
โโโ release.yml # NPM/JSR publishing and GitHub releases
|
|
360
|
+
dist/ # Generated package files (not committed)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Development and Release
|
|
364
|
+
|
|
365
|
+
Install dependencies with pnpm and run the local checks:
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
pnpm install
|
|
369
|
+
pnpm test
|
|
370
|
+
pnpm typecheck
|
|
371
|
+
pnpm build
|
|
341
372
|
```
|
|
342
373
|
|
|
374
|
+
Create a release note with `pnpm changeset`. Changesets opens a version pull request on `main`; merging it updates `package.json` and synchronizes the JSR version in `jsr.json`. A subsequent `main` push publishes the package to NPM and JSR and creates the matching `v<version>` Git tag and GitHub release.
|
|
375
|
+
|
|
343
376
|
## Supported Formats
|
|
344
377
|
|
|
345
378
|
### Input Formats
|
|
@@ -365,117 +398,10 @@ npm/ # Node.js build artifacts
|
|
|
365
398
|
- **Empty Folder Support**: Preserves empty folders in the bookmark structure
|
|
366
399
|
- **Duplicate Handling**: Last value wins for duplicate bookmark names
|
|
367
400
|
|
|
368
|
-
## Output Examples
|
|
369
|
-
|
|
370
|
-
### JSON Format
|
|
371
|
-
|
|
372
|
-
```json
|
|
373
|
-
{
|
|
374
|
-
"Development": {
|
|
375
|
-
"MDN": "https://developer.mozilla.org",
|
|
376
|
-
"Tools": {
|
|
377
|
-
"GitHub": "https://github.com",
|
|
378
|
-
"Stack Overflow": "https://stackoverflow.com"
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
"Google": "https://google.com"
|
|
382
|
-
}
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
### HTML Format
|
|
386
|
-
|
|
387
|
-
```html
|
|
388
|
-
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
389
|
-
<HTML>
|
|
390
|
-
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
|
391
|
-
<TITLE>Bookmark</TITLE>
|
|
392
|
-
<H1>Bookmark</H1>
|
|
393
|
-
<BODY>
|
|
394
|
-
<DL><p>
|
|
395
|
-
<DT><H3>Development</H3>
|
|
396
|
-
<DL><p>
|
|
397
|
-
<DT><A HREF="https://developer.mozilla.org">MDN</A>
|
|
398
|
-
<DT><H3>Tools</H3>
|
|
399
|
-
<DL><p>
|
|
400
|
-
<DT><A HREF="https://github.com">GitHub</A>
|
|
401
|
-
<DT><A HREF="https://stackoverflow.com">Stack Overflow</A>
|
|
402
|
-
</DL><p>
|
|
403
|
-
</DL><p>
|
|
404
|
-
<DT><A HREF="https://google.com">Google</A>
|
|
405
|
-
</DL>
|
|
406
|
-
</BODY>
|
|
407
|
-
</HTML>
|
|
408
|
-
```
|
|
409
|
-
|
|
410
401
|
## Dependencies
|
|
411
402
|
|
|
412
403
|
- [`@b-fuze/deno-dom`](https://jsr.io/@b-fuze/deno-dom): DOM parser and manipulation for both Deno and Node.js environments
|
|
413
404
|
|
|
414
|
-
## Development
|
|
415
|
-
|
|
416
|
-
### Prerequisites
|
|
417
|
-
|
|
418
|
-
- [Deno](https://deno.land/) 1.x or later
|
|
419
|
-
|
|
420
|
-
### Setup
|
|
421
|
-
|
|
422
|
-
```bash
|
|
423
|
-
git clone https://github.com/grakeice/netscape-bookmark-parser.git
|
|
424
|
-
cd netscape-bookmark-parser
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
### Development Commands
|
|
428
|
-
|
|
429
|
-
```bash
|
|
430
|
-
# Run development server with file watching
|
|
431
|
-
deno task dev
|
|
432
|
-
|
|
433
|
-
# Run all tests
|
|
434
|
-
deno test
|
|
435
|
-
|
|
436
|
-
# Run tests with coverage
|
|
437
|
-
deno test --coverage
|
|
438
|
-
|
|
439
|
-
# Format code
|
|
440
|
-
deno fmt
|
|
441
|
-
|
|
442
|
-
# Lint code
|
|
443
|
-
deno lint
|
|
444
|
-
|
|
445
|
-
# Build for Node.js
|
|
446
|
-
deno task build:npm
|
|
447
|
-
|
|
448
|
-
# Build with specific version
|
|
449
|
-
deno task build:npm 1.0.0
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
### Running Tests
|
|
453
|
-
|
|
454
|
-
The project includes comprehensive test suites for all functionality:
|
|
455
|
-
|
|
456
|
-
```bash
|
|
457
|
-
# Run all tests
|
|
458
|
-
deno test
|
|
459
|
-
|
|
460
|
-
# Run specific test file
|
|
461
|
-
deno test src/BookmarksTree/BookmarksTree.test.ts
|
|
462
|
-
|
|
463
|
-
# Run tests with detailed output
|
|
464
|
-
deno test --verbose
|
|
465
|
-
|
|
466
|
-
# Run tests and generate coverage report
|
|
467
|
-
deno test --coverage=coverage_dir
|
|
468
|
-
deno coverage coverage_dir
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### Publishing
|
|
472
|
-
|
|
473
|
-
The project uses automated publishing via GitHub Actions:
|
|
474
|
-
|
|
475
|
-
1. Create a version tag: `git tag v1.0.0`
|
|
476
|
-
2. Push the tag: `git push origin v1.0.0`
|
|
477
|
-
3. GitHub Actions will automatically build and publish to both NPM and JSR
|
|
478
|
-
|
|
479
405
|
## Browser Compatibility
|
|
480
406
|
|
|
481
407
|
### Supported Browsers for Export Files
|
|
@@ -518,93 +444,10 @@ The library can parse bookmark files exported from:
|
|
|
518
444
|
</DL>
|
|
519
445
|
```
|
|
520
446
|
|
|
521
|
-
## Error Handling
|
|
522
|
-
|
|
523
|
-
The library gracefully handles various error conditions:
|
|
524
|
-
|
|
525
|
-
```typescript
|
|
526
|
-
// Invalid HTML
|
|
527
|
-
const invalidHtml = "<html><body>Not a bookmark file</body></html>";
|
|
528
|
-
const tree = BookmarksParser.parse(invalidHtml);
|
|
529
|
-
console.log(tree.size); // 0 - empty tree
|
|
530
|
-
|
|
531
|
-
// Empty content
|
|
532
|
-
const emptyTree = BookmarksParser.parse("");
|
|
533
|
-
console.log(emptyTree.size); // 0
|
|
534
|
-
|
|
535
|
-
// Malformed URLs are skipped
|
|
536
|
-
const htmlWithBadUrls = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
|
537
|
-
<HTML><BODY><DL><p>
|
|
538
|
-
<DT><A HREF="">Empty URL</A>
|
|
539
|
-
<DT><A>No HREF attribute</A>
|
|
540
|
-
<DT><A HREF="https://valid.com">Valid Link</A>
|
|
541
|
-
</DL><p></BODY></HTML>`;
|
|
542
|
-
|
|
543
|
-
const parsedTree = BookmarksParser.parse(htmlWithBadUrls);
|
|
544
|
-
console.log(parsedTree.size); // 1 - only valid link included
|
|
545
|
-
```
|
|
546
|
-
|
|
547
|
-
## Performance
|
|
548
|
-
|
|
549
|
-
The library is optimized for performance:
|
|
550
|
-
|
|
551
|
-
- **Memory Efficient**: Uses native Map structure for O(1) lookups
|
|
552
|
-
- **Streaming Capable**: Can handle large bookmark files (1000+ bookmarks)
|
|
553
|
-
- **Fast Parsing**: DOM-based parsing with efficient tree traversal
|
|
554
|
-
- **JSON Conversion**: Optimized serialization/deserialization
|
|
555
|
-
|
|
556
|
-
## TypeScript Support
|
|
557
|
-
|
|
558
|
-
Full TypeScript definitions included:
|
|
559
|
-
|
|
560
|
-
```typescript
|
|
561
|
-
interface BookmarkValue extends Map<string, string | BookmarksTree> {
|
|
562
|
-
toJSON(): Record<string, unknown>;
|
|
563
|
-
toDOM(): HTMLDocument;
|
|
564
|
-
readonly HTMLText: string;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
class BookmarksParser {
|
|
568
|
-
static parse(htmlContent: string): BookmarksTree;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
class BookmarksTree extends Map<string, string | BookmarksTree> {
|
|
572
|
-
toJSON(): Record<string, unknown>;
|
|
573
|
-
static fromJSON(json: Record<string, unknown>): BookmarksTree;
|
|
574
|
-
static fromDOM(dom: HTMLDocument): BookmarksTree;
|
|
575
|
-
toDOM(): HTMLDocument;
|
|
576
|
-
get HTMLText(): string;
|
|
577
|
-
}
|
|
578
|
-
```
|
|
579
|
-
|
|
580
447
|
## License
|
|
581
448
|
|
|
582
449
|
MIT License - See [LICENSE](LICENSE) file for details.
|
|
583
450
|
|
|
584
|
-
## Contributing
|
|
585
|
-
|
|
586
|
-
Pull requests and issue reports are welcome!
|
|
587
|
-
|
|
588
|
-
### How to Contribute
|
|
589
|
-
|
|
590
|
-
1. Fork this repository
|
|
591
|
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
592
|
-
3. Make your changes with tests
|
|
593
|
-
4. Ensure all tests pass (`deno test`)
|
|
594
|
-
5. Format your code (`deno fmt`)
|
|
595
|
-
6. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
596
|
-
7. Push to the branch (`git push origin feature/amazing-feature`)
|
|
597
|
-
8. Create a pull request
|
|
598
|
-
|
|
599
|
-
### Reporting Issues
|
|
600
|
-
|
|
601
|
-
When reporting issues, please include:
|
|
602
|
-
|
|
603
|
-
- Browser/environment information
|
|
604
|
-
- Sample bookmark HTML (if applicable)
|
|
605
|
-
- Expected vs actual behavior
|
|
606
|
-
- Steps to reproduce
|
|
607
|
-
|
|
608
451
|
## Author
|
|
609
452
|
|
|
610
453
|
**grakeice**
|
|
@@ -613,7 +456,14 @@ When reporting issues, please include:
|
|
|
613
456
|
|
|
614
457
|
## Changelog
|
|
615
458
|
|
|
616
|
-
### v1.1.
|
|
459
|
+
### v1.1.4 (Latest)
|
|
460
|
+
|
|
461
|
+
- ๐ ๏ธ **Improved parser** (better compatibility with various bookmark HTML formats, increased stability)
|
|
462
|
+
- ๐งน **Code refactoring and additional tests**
|
|
463
|
+
- ๐ **Minor bug fixes**
|
|
464
|
+
- ๐ **Documentation Update**: API Reference refresh, unified explanations, added usage examples, revived various sections
|
|
465
|
+
|
|
466
|
+
### v1.1.3
|
|
617
467
|
|
|
618
468
|
- ๐ **Added JSDoc comments**: Added JSDoc-style comments to major classes and methods to improve type information and enable automatic API documentation generation
|
|
619
469
|
- ๐ **Documentation Update**: Added TypeScript import example for Node.js/npm in the Installation section
|
|
@@ -634,7 +484,7 @@ When reporting issues, please include:
|
|
|
634
484
|
### v1.1.0
|
|
635
485
|
|
|
636
486
|
- ๐ **Browser Support**: Added web-optimized version for browser environments
|
|
637
|
-
- ๐ฆ **Dual Entry Points**: Separate builds for Node.js/Deno (
|
|
487
|
+
- ๐ฆ **Dual Entry Points**: Separate builds for Node.js/Deno (`src/index.ts`) and browsers (`src/web.ts`)
|
|
638
488
|
- โก **Native DOM APIs**: Browser version uses native DOMParser and DOM APIs for better performance
|
|
639
489
|
- ๐ง **Build Optimization**: Enhanced build process with polyfill removal for browser compatibility
|
|
640
490
|
- ๐ **Updated Documentation**: Added browser usage examples and API reference
|