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.
@@ -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/web/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/web/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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netscape-bookmark-parser",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "keywords": [
5
5
  "bookmark",
6
6
  "parser",