netscape-bookmark-parser 1.1.2 → 1.1.4

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.
@@ -6,10 +6,137 @@
6
6
  */
7
7
  import { DOMParser } from "../deps.js";
8
8
  import { BookmarksTree } from "../BookmarksTree/index.js";
9
+ /**
10
+ * A parser for Netscape Bookmark format files
11
+ *
12
+ * This class provides static methods to parse Netscape Bookmark format HTML strings
13
+ * and convert them into BookmarksTree instances for easier manipulation.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
18
+ * <HTML>
19
+ * <BODY>
20
+ * <DL><p>
21
+ * <DT><A HREF="https://google.com">Google</A>
22
+ * <DT><H3>Development</H3>
23
+ * <DL><p>
24
+ * <DT><A HREF="https://github.com">GitHub</A>
25
+ * </DL><p>
26
+ * </DL>
27
+ * </BODY>
28
+ * </HTML>`;
29
+ *
30
+ * const tree = BookmarksParser.parse(bookmarkHtml);
31
+ * ```
32
+ */
9
33
  export class BookmarksParser {
10
- static parse(data) {
11
- const dom = new DOMParser().parseFromString(data, "text/html");
34
+ /**
35
+ * Alias for the {@link parseFromHTMLString} method.
36
+ *
37
+ * @param htmlString HTML string in Netscape Bookmark format
38
+ * @returns The parsed BookmarksTree
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
43
+ * <HTML>
44
+ * <BODY>
45
+ * <DL><p>
46
+ * <DT><A HREF="https://google.com">Google</A>
47
+ * <DT><H3>Development</H3>
48
+ * <DL><p>
49
+ * <DT><A HREF="https://github.com">GitHub</A>
50
+ * </DL><p>
51
+ * </DL>
52
+ * </BODY>
53
+ * </HTML>`;
54
+ *
55
+ * const tree = BookmarksParser.parse(bookmarkHtml);
56
+ * ```
57
+ */
58
+ static parse(htmlString) {
59
+ return this.parseFromHTMLString(htmlString);
60
+ }
61
+ /**
62
+ * Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
63
+ *
64
+ * @param htmlString HTML string in Netscape Bookmark format
65
+ * @returns The parsed BookmarksTree
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
70
+ * <HTML>
71
+ * <BODY>
72
+ * <DL><p>
73
+ * <DT><A HREF="https://google.com">Google</A>
74
+ * <DT><H3>Development</H3>
75
+ * <DL><p>
76
+ * <DT><A HREF="https://github.com">GitHub</A>
77
+ * </DL><p>
78
+ * </DL>
79
+ * </BODY>
80
+ * </HTML>`;
81
+ *
82
+ * const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
83
+ * ```
84
+ */
85
+ static parseFromHTMLString(htmlString) {
86
+ const dom = new DOMParser().parseFromString(htmlString, "text/html");
12
87
  const tree = BookmarksTree.fromDOM(dom);
13
88
  return tree;
14
89
  }
90
+ /**
91
+ * Creates a BookmarksTree from an existing HTMLDocument.
92
+ *
93
+ * This is an alias for {@link BookmarksTree.fromDOM}.
94
+ *
95
+ * Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
96
+ *
97
+ * @param dom An HTMLDocument instance
98
+ * @returns The parsed BookmarksTree
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
103
+ * const tree = BookmarksParser.parseFromDOM(dom);
104
+ * ```
105
+ */
106
+ static parseFromDOM(dom) {
107
+ return BookmarksTree.fromDOM(dom);
108
+ }
109
+ /**
110
+ * Parses a JSON string and returns a BookmarksTree.
111
+ *
112
+ * @param jsonString JSON string representing the bookmark structure
113
+ * @returns The parsed BookmarksTree
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
118
+ * const tree = BookmarksParser.parseFromJSONString(json);
119
+ * ```
120
+ */
121
+ static parseFromJSONString(jsonString) {
122
+ const obj = JSON.parse(jsonString);
123
+ return BookmarksTree.fromJSON(obj);
124
+ }
125
+ /**
126
+ * Parses a JSON object and returns a BookmarksTree.
127
+ *
128
+ * This is an alias for {@link BookmarksTree.fromJSON}.
129
+ *
130
+ * @param jsonObj JSON object representing the bookmark structure
131
+ * @returns The parsed BookmarksTree
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
136
+ * const tree = BookmarksParser.parseFromJSON(obj);
137
+ * ```
138
+ */
139
+ static parseFromJSON(jsonObj) {
140
+ return BookmarksTree.fromJSON(jsonObj);
141
+ }
15
142
  }
@@ -5,12 +5,114 @@
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
7
  import { type HTMLDocument } from "../deps.js";
8
+ /**
9
+ * A class representing a bookmark tree in Netscape Bookmark format
10
+ *
11
+ * This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
12
+ * in a hierarchical structure.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const tree = new BookmarksTree();
17
+ * tree.set("Google", "https://google.com");
18
+ *
19
+ * const folder = new BookmarksTree();
20
+ * folder.set("GitHub", "https://github.com");
21
+ * tree.set("Development", folder);
22
+ * ```
23
+ */
8
24
  export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
25
+ /**
26
+ * Creates a new BookmarksTree instance
27
+ */
9
28
  constructor();
29
+ /**
30
+ * Converts the BookmarksTree to a JSON object
31
+ *
32
+ * Folders are recursively converted to objects, and bookmarks are preserved as strings.
33
+ *
34
+ * @returns JSON object representation of the bookmark data
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const tree = new BookmarksTree();
39
+ * tree.set("Google", "https://google.com");
40
+ * const json = tree.toJSON();
41
+ * // { "Google": "https://google.com" }
42
+ * ```
43
+ */
10
44
  toJSON(): Record<string, unknown>;
45
+ /**
46
+ * Creates a BookmarksTree from a JSON object
47
+ *
48
+ * String properties are treated as bookmarks, and object properties are
49
+ * recursively processed as folders.
50
+ *
51
+ * @param json The source JSON object to convert
52
+ * @returns A new BookmarksTree instance
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
57
+ * const tree = BookmarksTree.fromJSON(json);
58
+ * ```
59
+ */
11
60
  static fromJSON(json: Record<string, unknown>): BookmarksTree;
61
+ /**
62
+ * Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
63
+ *
64
+ * Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
65
+ * the hierarchical structure. H3 elements within DT elements are treated as folders,
66
+ * and A elements are treated as bookmarks.
67
+ *
68
+ * @param dom The HTML document to parse
69
+ * @returns A new BookmarksTree instance
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const parser = new DOMParser();
74
+ * const dom = parser.parseFromString(bookmarkHtml, "text/html");
75
+ * const tree = BookmarksTree.fromDOM(dom);
76
+ * ```
77
+ */
12
78
  static fromDOM(dom: HTMLDocument): BookmarksTree;
79
+ /**
80
+ * Converts the BookmarksTree to an HTML document
81
+ *
82
+ * Generates an HTML document in Netscape Bookmark format.
83
+ *
84
+ * @returns HTML document in Netscape Bookmark format
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const tree = new BookmarksTree();
89
+ * tree.set("Google", "https://google.com");
90
+ * const dom = tree.toDOM();
91
+ * ```
92
+ */
13
93
  toDOM(): HTMLDocument;
94
+ /**
95
+ * Gets the BookmarksTree as an HTML string in Netscape Bookmark format
96
+ *
97
+ * Generates a complete HTML document string including DOCTYPE, metadata, and body
98
+ * in Netscape Bookmark format.
99
+ *
100
+ * @returns HTML string in Netscape Bookmark format
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const tree = new BookmarksTree();
105
+ * tree.set("Google", "https://google.com");
106
+ * const html = tree.HTMLString;
107
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
108
+ * ```
109
+ */
110
+ get HTMLString(): string;
111
+ /**
112
+ * @deprecated Use {@link HTMLString} instead.
113
+ *
114
+ * Gets the BookmarksTree as an HTML string in Netscape Bookmark format.
115
+ */
14
116
  get HTMLText(): string;
15
117
  }
16
118
  //# sourceMappingURL=BookmarksTree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BookmarksTree.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksTree/BookmarksTree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAExE,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;;IAKrE,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcjC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAmB7D,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IA8ChD,KAAK,IAAI,YAAY;IAIrB,IAAI,QAAQ,IAAI,MAAM,CA+CrB;CACD"}
1
+ {"version":3,"file":"BookmarksTree.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksTree/BookmarksTree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAExE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAc,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IACrE;;OAEG;;IAKH;;;;;;;;;;;;;;OAcG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcjC;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAmB7D;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IA8ChD;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,YAAY;IAIrB;;;;;;;;;;;;;;;OAeG;IACH,IAAI,UAAU,IAAI,MAAM,CA+CvB;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;CACD"}
@@ -5,10 +5,44 @@
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
7
  import { DOMParser } from "../deps.js";
8
+ /**
9
+ * A class representing a bookmark tree in Netscape Bookmark format
10
+ *
11
+ * This class extends Map and manages folders (BookmarksTree) and bookmarks (URL strings)
12
+ * in a hierarchical structure.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const tree = new BookmarksTree();
17
+ * tree.set("Google", "https://google.com");
18
+ *
19
+ * const folder = new BookmarksTree();
20
+ * folder.set("GitHub", "https://github.com");
21
+ * tree.set("Development", folder);
22
+ * ```
23
+ */
8
24
  export class BookmarksTree extends Map {
25
+ /**
26
+ * Creates a new BookmarksTree instance
27
+ */
9
28
  constructor() {
10
29
  super();
11
30
  }
31
+ /**
32
+ * Converts the BookmarksTree to a JSON object
33
+ *
34
+ * Folders are recursively converted to objects, and bookmarks are preserved as strings.
35
+ *
36
+ * @returns JSON object representation of the bookmark data
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const tree = new BookmarksTree();
41
+ * tree.set("Google", "https://google.com");
42
+ * const json = tree.toJSON();
43
+ * // { "Google": "https://google.com" }
44
+ * ```
45
+ */
12
46
  toJSON() {
13
47
  const json = {};
14
48
  for (const [key, value] of this.entries()) {
@@ -21,6 +55,21 @@ export class BookmarksTree extends Map {
21
55
  }
22
56
  return json;
23
57
  }
58
+ /**
59
+ * Creates a BookmarksTree from a JSON object
60
+ *
61
+ * String properties are treated as bookmarks, and object properties are
62
+ * recursively processed as folders.
63
+ *
64
+ * @param json The source JSON object to convert
65
+ * @returns A new BookmarksTree instance
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const json = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
70
+ * const tree = BookmarksTree.fromJSON(json);
71
+ * ```
72
+ */
24
73
  static fromJSON(json) {
25
74
  const tree = new BookmarksTree();
26
75
  if (typeof json === "object" && json !== null) {
@@ -35,6 +84,23 @@ export class BookmarksTree extends Map {
35
84
  }
36
85
  return tree;
37
86
  }
87
+ /**
88
+ * Creates a BookmarksTree from an HTML document (Netscape Bookmark format)
89
+ *
90
+ * Parses Netscape Bookmark format HTML and generates a BookmarksTree that preserves
91
+ * the hierarchical structure. H3 elements within DT elements are treated as folders,
92
+ * and A elements are treated as bookmarks.
93
+ *
94
+ * @param dom The HTML document to parse
95
+ * @returns A new BookmarksTree instance
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const parser = new DOMParser();
100
+ * const dom = parser.parseFromString(bookmarkHtml, "text/html");
101
+ * const tree = BookmarksTree.fromDOM(dom);
102
+ * ```
103
+ */
38
104
  static fromDOM(dom) {
39
105
  const tree = new BookmarksTree();
40
106
  const document = dom;
@@ -76,10 +142,40 @@ export class BookmarksTree extends Map {
76
142
  }
77
143
  return tree;
78
144
  }
145
+ /**
146
+ * Converts the BookmarksTree to an HTML document
147
+ *
148
+ * Generates an HTML document in Netscape Bookmark format.
149
+ *
150
+ * @returns HTML document in Netscape Bookmark format
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const tree = new BookmarksTree();
155
+ * tree.set("Google", "https://google.com");
156
+ * const dom = tree.toDOM();
157
+ * ```
158
+ */
79
159
  toDOM() {
80
- return new DOMParser().parseFromString(this.HTMLText, "text/html");
160
+ return new DOMParser().parseFromString(this.HTMLString, "text/html");
81
161
  }
82
- get HTMLText() {
162
+ /**
163
+ * Gets the BookmarksTree as an HTML string in Netscape Bookmark format
164
+ *
165
+ * Generates a complete HTML document string including DOCTYPE, metadata, and body
166
+ * in Netscape Bookmark format.
167
+ *
168
+ * @returns HTML string in Netscape Bookmark format
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const tree = new BookmarksTree();
173
+ * tree.set("Google", "https://google.com");
174
+ * const html = tree.HTMLString;
175
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
+ * ```
177
+ */
178
+ get HTMLString() {
83
179
  const escapeHtml = (text) => {
84
180
  return text
85
181
  .replace(/&/g, "&amp;")
@@ -118,4 +214,12 @@ ${createBookmarkList(this)}</BODY>
118
214
  </HTML>`;
119
215
  return htmlTemplate;
120
216
  }
217
+ /**
218
+ * @deprecated Use {@link HTMLString} instead.
219
+ *
220
+ * Gets the BookmarksTree as an HTML string in Netscape Bookmark format.
221
+ */
222
+ get HTMLText() {
223
+ return this.HTMLString;
224
+ }
121
225
  }
@@ -4,8 +4,127 @@
4
4
  * This software is released under the MIT License.
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
+ import type { HTMLDocument } from "../deps.js";
7
8
  import { BookmarksTree } from "../BookmarksTree/index.js";
9
+ /**
10
+ * A parser for Netscape Bookmark format files
11
+ *
12
+ * This class provides static methods to parse Netscape Bookmark format HTML strings
13
+ * and convert them into BookmarksTree instances for easier manipulation.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
18
+ * <HTML>
19
+ * <BODY>
20
+ * <DL><p>
21
+ * <DT><A HREF="https://google.com">Google</A>
22
+ * <DT><H3>Development</H3>
23
+ * <DL><p>
24
+ * <DT><A HREF="https://github.com">GitHub</A>
25
+ * </DL><p>
26
+ * </DL>
27
+ * </BODY>
28
+ * </HTML>`;
29
+ *
30
+ * const tree = BookmarksParser.parse(bookmarkHtml);
31
+ * ```
32
+ */
8
33
  export declare class BookmarksParser {
9
- static parse(data: string): BookmarksTree;
34
+ /**
35
+ * Alias for the {@link parseFromHTMLString} method.
36
+ *
37
+ * @param htmlString HTML string in Netscape Bookmark format
38
+ * @returns The parsed BookmarksTree
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
43
+ * <HTML>
44
+ * <BODY>
45
+ * <DL><p>
46
+ * <DT><A HREF="https://google.com">Google</A>
47
+ * <DT><H3>Development</H3>
48
+ * <DL><p>
49
+ * <DT><A HREF="https://github.com">GitHub</A>
50
+ * </DL><p>
51
+ * </DL>
52
+ * </BODY>
53
+ * </HTML>`;
54
+ *
55
+ * const tree = BookmarksParser.parse(bookmarkHtml);
56
+ * ```
57
+ */
58
+ static parse(htmlString: string): BookmarksTree;
59
+ /**
60
+ * Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
61
+ *
62
+ * @param htmlString HTML string in Netscape Bookmark format
63
+ * @returns The parsed BookmarksTree
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
68
+ * <HTML>
69
+ * <BODY>
70
+ * <DL><p>
71
+ * <DT><A HREF="https://google.com">Google</A>
72
+ * <DT><H3>Development</H3>
73
+ * <DL><p>
74
+ * <DT><A HREF="https://github.com">GitHub</A>
75
+ * </DL><p>
76
+ * </DL>
77
+ * </BODY>
78
+ * </HTML>`;
79
+ *
80
+ * const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
81
+ * ```
82
+ */
83
+ static parseFromHTMLString(htmlString: string): BookmarksTree;
84
+ /**
85
+ * Creates a BookmarksTree from an existing HTMLDocument.
86
+ *
87
+ * This is an alias for {@link BookmarksTree.fromDOM}.
88
+ *
89
+ * Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
90
+ *
91
+ * @param dom An HTMLDocument instance
92
+ * @returns The parsed BookmarksTree
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
97
+ * const tree = BookmarksParser.parseFromDOM(dom);
98
+ * ```
99
+ */
100
+ static parseFromDOM(dom: HTMLDocument): BookmarksTree;
101
+ /**
102
+ * Parses a JSON string and returns a BookmarksTree.
103
+ *
104
+ * @param jsonString JSON string representing the bookmark structure
105
+ * @returns The parsed BookmarksTree
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
110
+ * const tree = BookmarksParser.parseFromJSONString(json);
111
+ * ```
112
+ */
113
+ static parseFromJSONString(jsonString: string): BookmarksTree;
114
+ /**
115
+ * Parses a JSON object and returns a BookmarksTree.
116
+ *
117
+ * This is an alias for {@link BookmarksTree.fromJSON}.
118
+ *
119
+ * @param jsonObj JSON object representing the bookmark structure
120
+ * @returns The parsed BookmarksTree
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
125
+ * const tree = BookmarksParser.parseFromJSON(obj);
126
+ * ```
127
+ */
128
+ static parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree;
10
129
  }
11
130
  //# sourceMappingURL=BookmarksParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,qBAAa,eAAe;IAC3B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
1
+ {"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksParser/BookmarksParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAI/C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAM7D;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa;IAIrD;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa;IAK7D;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;CAGrE"}
@@ -6,10 +6,137 @@
6
6
  */
7
7
  import { DOMParser } from "../deps.js";
8
8
  import { BookmarksTree } from "../BookmarksTree/index.js";
9
+ /**
10
+ * A parser for Netscape Bookmark format files
11
+ *
12
+ * This class provides static methods to parse Netscape Bookmark format HTML strings
13
+ * and convert them into BookmarksTree instances for easier manipulation.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
18
+ * <HTML>
19
+ * <BODY>
20
+ * <DL><p>
21
+ * <DT><A HREF="https://google.com">Google</A>
22
+ * <DT><H3>Development</H3>
23
+ * <DL><p>
24
+ * <DT><A HREF="https://github.com">GitHub</A>
25
+ * </DL><p>
26
+ * </DL>
27
+ * </BODY>
28
+ * </HTML>`;
29
+ *
30
+ * const tree = BookmarksParser.parse(bookmarkHtml);
31
+ * ```
32
+ */
9
33
  export class BookmarksParser {
10
- static parse(data) {
11
- const dom = new DOMParser().parseFromString(data, "text/html");
34
+ /**
35
+ * Alias for the {@link parseFromHTMLString} method.
36
+ *
37
+ * @param htmlString HTML string in Netscape Bookmark format
38
+ * @returns The parsed BookmarksTree
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
43
+ * <HTML>
44
+ * <BODY>
45
+ * <DL><p>
46
+ * <DT><A HREF="https://google.com">Google</A>
47
+ * <DT><H3>Development</H3>
48
+ * <DL><p>
49
+ * <DT><A HREF="https://github.com">GitHub</A>
50
+ * </DL><p>
51
+ * </DL>
52
+ * </BODY>
53
+ * </HTML>`;
54
+ *
55
+ * const tree = BookmarksParser.parse(bookmarkHtml);
56
+ * ```
57
+ */
58
+ static parse(htmlString) {
59
+ return this.parseFromHTMLString(htmlString);
60
+ }
61
+ /**
62
+ * Parses a Netscape Bookmark format HTML string and returns a BookmarksTree.
63
+ *
64
+ * @param htmlString HTML string in Netscape Bookmark format
65
+ * @returns The parsed BookmarksTree
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
70
+ * <HTML>
71
+ * <BODY>
72
+ * <DL><p>
73
+ * <DT><A HREF="https://google.com">Google</A>
74
+ * <DT><H3>Development</H3>
75
+ * <DL><p>
76
+ * <DT><A HREF="https://github.com">GitHub</A>
77
+ * </DL><p>
78
+ * </DL>
79
+ * </BODY>
80
+ * </HTML>`;
81
+ *
82
+ * const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
83
+ * ```
84
+ */
85
+ static parseFromHTMLString(htmlString) {
86
+ const dom = new DOMParser().parseFromString(htmlString, "text/html");
12
87
  const tree = BookmarksTree.fromDOM(dom);
13
88
  return tree;
14
89
  }
90
+ /**
91
+ * Creates a BookmarksTree from an existing HTMLDocument.
92
+ *
93
+ * This is an alias for {@link BookmarksTree.fromDOM}.
94
+ *
95
+ * Use this when you already have a parsed HTMLDocument and want to convert it to a BookmarksTree.
96
+ *
97
+ * @param dom An HTMLDocument instance
98
+ * @returns The parsed BookmarksTree
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const dom = new DOMParser().parseFromString(bookmarkHtml, "text/html");
103
+ * const tree = BookmarksParser.parseFromDOM(dom);
104
+ * ```
105
+ */
106
+ static parseFromDOM(dom) {
107
+ return BookmarksTree.fromDOM(dom);
108
+ }
109
+ /**
110
+ * Parses a JSON string and returns a BookmarksTree.
111
+ *
112
+ * @param jsonString JSON string representing the bookmark structure
113
+ * @returns The parsed BookmarksTree
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const json = '{"Google":"https://google.com","Development":{"GitHub":"https://github.com"}}';
118
+ * const tree = BookmarksParser.parseFromJSONString(json);
119
+ * ```
120
+ */
121
+ static parseFromJSONString(jsonString) {
122
+ const obj = JSON.parse(jsonString);
123
+ return BookmarksTree.fromJSON(obj);
124
+ }
125
+ /**
126
+ * Parses a JSON object and returns a BookmarksTree.
127
+ *
128
+ * This is an alias for {@link BookmarksTree.fromJSON}.
129
+ *
130
+ * @param jsonObj JSON object representing the bookmark structure
131
+ * @returns The parsed BookmarksTree
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const obj = { "Google": "https://google.com", "Development": { "GitHub": "https://github.com" } };
136
+ * const tree = BookmarksParser.parseFromJSON(obj);
137
+ * ```
138
+ */
139
+ static parseFromJSON(jsonObj) {
140
+ return BookmarksTree.fromJSON(jsonObj);
141
+ }
15
142
  }