netscape-bookmark-parser 1.1.3 → 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.
@@ -103,10 +103,16 @@ export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
103
103
  * ```typescript
104
104
  * const tree = new BookmarksTree();
105
105
  * tree.set("Google", "https://google.com");
106
- * const html = tree.HTMLText;
106
+ * const html = tree.HTMLString;
107
107
  * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
108
108
  * ```
109
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
+ */
110
116
  get HTMLText(): string;
111
117
  }
112
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;;;;;;;;;;;;;;;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,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"}
@@ -157,7 +157,7 @@ export class BookmarksTree extends Map {
157
157
  * ```
158
158
  */
159
159
  toDOM() {
160
- return new DOMParser().parseFromString(this.HTMLText, "text/html");
160
+ return new DOMParser().parseFromString(this.HTMLString, "text/html");
161
161
  }
162
162
  /**
163
163
  * Gets the BookmarksTree as an HTML string in Netscape Bookmark format
@@ -171,11 +171,11 @@ export class BookmarksTree extends Map {
171
171
  * ```typescript
172
172
  * const tree = new BookmarksTree();
173
173
  * tree.set("Google", "https://google.com");
174
- * const html = tree.HTMLText;
174
+ * const html = tree.HTMLString;
175
175
  * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
176
  * ```
177
177
  */
178
- get HTMLText() {
178
+ get HTMLString() {
179
179
  const escapeHtml = (text) => {
180
180
  return text
181
181
  .replace(/&/g, "&amp;")
@@ -214,4 +214,12 @@ ${createBookmarkList(this)}</BODY>
214
214
  </HTML>`;
215
215
  return htmlTemplate;
216
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
+ }
217
225
  }
@@ -4,6 +4,7 @@
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";
8
9
  /**
9
10
  * A parser for Netscape Bookmark format files
@@ -31,13 +32,10 @@ import { BookmarksTree } from "../BookmarksTree/index.js";
31
32
  */
32
33
  export declare class BookmarksParser {
33
34
  /**
34
- * Parses a Netscape Bookmark format HTML string into a BookmarksTree
35
+ * Alias for the {@link parseFromHTMLString} method.
35
36
  *
36
- * Takes an HTML string in Netscape Bookmark format and converts it into a structured
37
- * BookmarksTree that preserves the hierarchical organization of folders and bookmarks.
38
- *
39
- * @param data The HTML string in Netscape Bookmark format to parse
40
- * @returns A BookmarksTree representing the parsed bookmark structure
37
+ * @param htmlString HTML string in Netscape Bookmark format
38
+ * @returns The parsed BookmarksTree
41
39
  *
42
40
  * @example
43
41
  * ```typescript
@@ -55,12 +53,78 @@ export declare class BookmarksParser {
55
53
  * </HTML>`;
56
54
  *
57
55
  * const tree = BookmarksParser.parse(bookmarkHtml);
58
- * console.log(tree.get("Google")); // "https://google.com"
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.
59
103
  *
60
- * const folder = tree.get("Development");
61
- * console.log(folder.get("GitHub")); // "https://github.com"
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);
62
126
  * ```
63
127
  */
64
- static parse(data: string): BookmarksTree;
128
+ static parseFromJSON(jsonObj: Record<string, unknown>): BookmarksTree;
65
129
  }
66
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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,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"}
@@ -32,13 +32,10 @@ import { BookmarksTree } from "../BookmarksTree/index.js";
32
32
  */
33
33
  export class BookmarksParser {
34
34
  /**
35
- * Parses a Netscape Bookmark format HTML string into a BookmarksTree
35
+ * Alias for the {@link parseFromHTMLString} method.
36
36
  *
37
- * Takes an HTML string in Netscape Bookmark format and converts it into a structured
38
- * BookmarksTree that preserves the hierarchical organization of folders and bookmarks.
39
- *
40
- * @param data The HTML string in Netscape Bookmark format to parse
41
- * @returns A BookmarksTree representing the parsed bookmark structure
37
+ * @param htmlString HTML string in Netscape Bookmark format
38
+ * @returns The parsed BookmarksTree
42
39
  *
43
40
  * @example
44
41
  * ```typescript
@@ -56,15 +53,90 @@ export class BookmarksParser {
56
53
  * </HTML>`;
57
54
  *
58
55
  * const tree = BookmarksParser.parse(bookmarkHtml);
59
- * console.log(tree.get("Google")); // "https://google.com"
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>`;
60
81
  *
61
- * const folder = tree.get("Development");
62
- * console.log(folder.get("GitHub")); // "https://github.com"
82
+ * const tree = BookmarksParser.parseFromHTMLString(bookmarkHtml);
63
83
  * ```
64
84
  */
65
- static parse(data) {
66
- const dom = new DOMParser().parseFromString(data, "text/html");
85
+ static parseFromHTMLString(htmlString) {
86
+ const dom = new DOMParser().parseFromString(htmlString, "text/html");
67
87
  const tree = BookmarksTree.fromDOM(dom);
68
88
  return tree;
69
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
+ }
70
142
  }
@@ -103,10 +103,16 @@ export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
103
103
  * ```typescript
104
104
  * const tree = new BookmarksTree();
105
105
  * tree.set("Google", "https://google.com");
106
- * const html = tree.HTMLText;
106
+ * const html = tree.HTMLString;
107
107
  * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
108
108
  * ```
109
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
+ */
110
116
  get HTMLText(): string;
111
117
  }
112
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;;;;;;;;;;;;;;;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,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"}
@@ -157,7 +157,7 @@ export class BookmarksTree extends Map {
157
157
  * ```
158
158
  */
159
159
  toDOM() {
160
- return new DOMParser().parseFromString(this.HTMLText, "text/html");
160
+ return new DOMParser().parseFromString(this.HTMLString, "text/html");
161
161
  }
162
162
  /**
163
163
  * Gets the BookmarksTree as an HTML string in Netscape Bookmark format
@@ -171,11 +171,11 @@ export class BookmarksTree extends Map {
171
171
  * ```typescript
172
172
  * const tree = new BookmarksTree();
173
173
  * tree.set("Google", "https://google.com");
174
- * const html = tree.HTMLText;
174
+ * const html = tree.HTMLString;
175
175
  * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
176
  * ```
177
177
  */
178
- get HTMLText() {
178
+ get HTMLString() {
179
179
  const escapeHtml = (text) => {
180
180
  return text
181
181
  .replace(/&/g, "&amp;")
@@ -214,4 +214,12 @@ ${createBookmarkList(this)}</BODY>
214
214
  </HTML>`;
215
215
  return htmlTemplate;
216
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
+ }
217
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netscape-bookmark-parser",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "keywords": [
5
5
  "bookmark",
6
6
  "parser",