netscape-bookmark-parser 1.1.1 → 1.1.3

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/README-ja.md CHANGED
@@ -1,17 +1,10 @@
1
- <!--
2
- Copyright (c) 2025 grakeice
3
-
4
- This software is released under the MIT License.
5
- https://opensource.org/licenses/MIT
6
- -->
7
-
8
1
  # Netscape Bookmark Parser
9
2
 
3
+ ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。Deno と Node.js の両方のランタイムに対応しています。
4
+
10
5
  > **注意:**
11
6
  > この README は AI 生成されたドキュメントです。詳細はほぼ正確ですが、不正確な説明が含まれる可能性があります。
12
7
 
13
- ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。Deno と Node.js の両方のランタイムに対応しています。
14
-
15
8
  ## 機能
16
9
 
17
10
  - **HTML ブックマークファイルの解析**: Chrome、Firefox、Safari、その他のブラウザからエクスポートされた HTML ブックマークファイルを解析
@@ -29,6 +22,10 @@
29
22
  npm install netscape-bookmark-parser
30
23
  ```
31
24
 
25
+ ```typescript
26
+ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
27
+ ```
28
+
32
29
  ### Deno
33
30
 
34
31
  ```typescript
@@ -65,26 +62,13 @@ function handleFileUpload(event: Event) {
65
62
  }
66
63
  ```
67
64
 
68
- #### オプション 2: 直接 ES モジュールインポート
69
-
70
- ```html
71
- <script type="module">
72
- import {
73
- BookmarksParser,
74
- BookmarksTree,
75
- } from "./node_modules/netscape-bookmark-parser/esm/mod_web.js";
76
-
77
- // ブックマーク処理コードをここに...
78
- </script>
79
- ```
80
-
81
- #### オプション 3: Import Maps を使用した CDN
65
+ #### オプション 2: Import Maps を使用した CDN
82
66
 
83
67
  ```html
84
68
  <script type="importmap">
85
69
  {
86
70
  "imports": {
87
- "netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.0/esm/mod_web.js"
71
+ "netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js"
88
72
  }
89
73
  }
90
74
  </script>
@@ -96,14 +80,14 @@ function handleFileUpload(event: Event) {
96
80
  </script>
97
81
  ```
98
82
 
99
- #### オプション 4: CDN を直接インポート
83
+ #### オプション 3: CDN を直接インポート
100
84
 
101
85
  ```html
102
86
  <script type="module">
103
87
  import {
104
88
  BookmarksParser,
105
89
  BookmarksTree,
106
- } from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.0/esm/mod_web.js";
90
+ } from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js";
107
91
 
108
92
  // import maps なしでの直接 CDN インポート
109
93
  </script>
@@ -629,7 +613,25 @@ MIT License - 詳細は[LICENSE](LICENSE)ファイルを参照してください
629
613
 
630
614
  ## 変更履歴
631
615
 
632
- ### v1.1.0(最新)
616
+ ### v1.1.3(最新)
617
+
618
+ - 📝 **JSDoc コメント追加**: 主要なクラス・メソッドに JSDoc 形式のコメントを追加し、型情報と API 自動ドキュメント生成を強化
619
+ - 📚 **ドキュメント更新**: インストール手順(Node.js/npm)に TypeScript でのインポート例を追加
620
+
621
+ ### v1.1.2
622
+
623
+ - 📝 **ドキュメント強化**: 最新バージョン参照と改善された例を含む包括的な README ドキュメントの更新
624
+ - 🔧 **バージョン一貫性**: 全ドキュメントとコード例でのバージョン番号の同期
625
+ - 📚 **コンテンツ更新**: より明確性のためのインストール手順、使用例、API ドキュメントの改良
626
+
627
+ ### v1.1.1
628
+
629
+ - 🛡️ **セキュリティ強化**: [`BookmarksTree.prototype.HTMLText`](src/BookmarksTree/BookmarksTree.ts) がブックマークのタイトルと URL の HTML エンティティを適切にエスケープするように修正
630
+ - 🔧 **コード一貫性**: Node.js とブラウザ版間で HTML エスケープ動作を統一
631
+ - 📝 **ドキュメント更新**: セキュリティ考慮事項を含む API ドキュメントの強化
632
+ - 🐛 **バグ修正**: マイナーな安定性改善とエッジケース処理
633
+
634
+ ### v1.1.0
633
635
 
634
636
  - 🌐 **ブラウザサポート**: ブラウザ環境用の Web 最適化版を追加
635
637
  - 📦 **デュアルエントリーポイント**: Node.js/Deno 用(`./mod.ts`)とブラウザ用(`./mod_web.ts`)の分離ビルド
package/README.md CHANGED
@@ -1,18 +1,10 @@
1
- <!--
2
- Copyright (c) 2025 grakeice
3
-
4
- This software is released under the MIT License.
5
- https://opensource.org/licenses/MIT
6
- -->
7
-
8
1
  # Netscape Bookmark Parser
9
2
 
10
- > **Note:**
11
- > This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
12
-
13
3
  A TypeScript/JavaScript library for parsing browser bookmark files (HTML format) and manipulating them as structured data. Compatible with both Deno and Node.js runtimes.
14
4
 
15
- 日本語ドキュメント: [`./README-ja.md`](./README-ja.md)
5
+ > **Note:**
6
+ > This README is an AI-generated document. Details are mostly accurate but might include inaccurate description.
7
+ > 日本語ドキュメント: [`./README-ja.md`](./README-ja.md)
16
8
 
17
9
  ## Features
18
10
 
@@ -31,6 +23,10 @@ A TypeScript/JavaScript library for parsing browser bookmark files (HTML format)
31
23
  npm install netscape-bookmark-parser
32
24
  ```
33
25
 
26
+ ```typescript
27
+ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser";
28
+ ```
29
+
34
30
  ### Deno
35
31
 
36
32
  ```typescript
@@ -67,26 +63,13 @@ function handleFileUpload(event: Event) {
67
63
  }
68
64
  ```
69
65
 
70
- #### Option 2: Direct ES Module Import
71
-
72
- ```html
73
- <script type="module">
74
- import {
75
- BookmarksParser,
76
- BookmarksTree,
77
- } from "./node_modules/netscape-bookmark-parser/esm/mod_web.js";
78
-
79
- // Your bookmark processing code here...
80
- </script>
81
- ```
82
-
83
- #### Option 3: CDN with Import Maps
66
+ #### Option 2: CDN with Import Maps
84
67
 
85
68
  ```html
86
69
  <script type="importmap">
87
70
  {
88
71
  "imports": {
89
- "netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.0/esm/mod_web.js"
72
+ "netscape-bookmark-parser/web": "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js"
90
73
  }
91
74
  }
92
75
  </script>
@@ -98,14 +81,14 @@ function handleFileUpload(event: Event) {
98
81
  </script>
99
82
  ```
100
83
 
101
- #### Option 4: Direct CDN Import
84
+ #### Option 3: Direct CDN Import
102
85
 
103
86
  ```html
104
87
  <script type="module">
105
88
  import {
106
89
  BookmarksParser,
107
90
  BookmarksTree,
108
- } from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.0/esm/mod_web.js";
91
+ } from "https://cdn.jsdelivr.net/npm/netscape-bookmark-parser@1.1.3/esm/mod_web.js";
109
92
 
110
93
  // Direct CDN import without import maps
111
94
  </script>
@@ -630,7 +613,25 @@ When reporting issues, please include:
630
613
 
631
614
  ## Changelog
632
615
 
633
- ### v1.1.0 (Latest)
616
+ ### v1.1.3 (Latest)
617
+
618
+ - 📝 **Added JSDoc comments**: Added JSDoc-style comments to major classes and methods to improve type information and enable automatic API documentation generation
619
+ - 📚 **Documentation Update**: Added TypeScript import example for Node.js/npm in the Installation section
620
+
621
+ ### v1.1.2
622
+
623
+ - 📝 **Documentation Enhancement**: Updated comprehensive README documentation with latest version references and improved examples
624
+ - 🔧 **Version Consistency**: Synchronized version numbers across all documentation and code examples
625
+ - 📚 **Content Updates**: Refined installation instructions, usage examples, and API documentation for better clarity
626
+
627
+ ### v1.1.1
628
+
629
+ - 🛡️ **Security Enhancement**: [`BookmarksTree.prototype.HTMLText`](src/BookmarksTree/BookmarksTree.ts) now properly escapes HTML entities in bookmark titles and URLs
630
+ - 🔧 **Code Consistency**: Unified HTML escaping behavior between Node.js and browser versions
631
+ - 📝 **Documentation Updates**: Enhanced API documentation with security considerations
632
+ - 🐛 **Bug Fixes**: Minor stability improvements and edge case handling
633
+
634
+ ### v1.1.0
634
635
 
635
636
  - 🌐 **Browser Support**: Added web-optimized version for browser environments
636
637
  - 📦 **Dual Entry Points**: Separate builds for Node.js/Deno (`./mod.ts`) and browsers (`./mod_web.ts`)
@@ -5,7 +5,62 @@
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
7
  import { BookmarksTree } from "../BookmarksTree/index.js";
8
+ /**
9
+ * A parser for Netscape Bookmark format files
10
+ *
11
+ * This class provides static methods to parse Netscape Bookmark format HTML strings
12
+ * and convert them into BookmarksTree instances for easier manipulation.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
17
+ * <HTML>
18
+ * <BODY>
19
+ * <DL><p>
20
+ * <DT><A HREF="https://google.com">Google</A>
21
+ * <DT><H3>Development</H3>
22
+ * <DL><p>
23
+ * <DT><A HREF="https://github.com">GitHub</A>
24
+ * </DL><p>
25
+ * </DL>
26
+ * </BODY>
27
+ * </HTML>`;
28
+ *
29
+ * const tree = BookmarksParser.parse(bookmarkHtml);
30
+ * ```
31
+ */
8
32
  export declare class BookmarksParser {
33
+ /**
34
+ * Parses a Netscape Bookmark format HTML string into a BookmarksTree
35
+ *
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
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
45
+ * <HTML>
46
+ * <BODY>
47
+ * <DL><p>
48
+ * <DT><A HREF="https://google.com">Google</A>
49
+ * <DT><H3>Development</H3>
50
+ * <DL><p>
51
+ * <DT><A HREF="https://github.com">GitHub</A>
52
+ * </DL><p>
53
+ * </DL>
54
+ * </BODY>
55
+ * </HTML>`;
56
+ *
57
+ * const tree = BookmarksParser.parse(bookmarkHtml);
58
+ * console.log(tree.get("Google")); // "https://google.com"
59
+ *
60
+ * const folder = tree.get("Development");
61
+ * console.log(folder.get("GitHub")); // "https://github.com"
62
+ * ```
63
+ */
9
64
  static parse(data: string): BookmarksTree;
10
65
  }
11
66
  //# sourceMappingURL=BookmarksParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BookmarksParser.d.ts","sourceRoot":"","sources":["../../../src/src/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/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"}
@@ -6,7 +6,62 @@
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 {
34
+ /**
35
+ * Parses a Netscape Bookmark format HTML string into a BookmarksTree
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
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
46
+ * <HTML>
47
+ * <BODY>
48
+ * <DL><p>
49
+ * <DT><A HREF="https://google.com">Google</A>
50
+ * <DT><H3>Development</H3>
51
+ * <DL><p>
52
+ * <DT><A HREF="https://github.com">GitHub</A>
53
+ * </DL><p>
54
+ * </DL>
55
+ * </BODY>
56
+ * </HTML>`;
57
+ *
58
+ * const tree = BookmarksParser.parse(bookmarkHtml);
59
+ * console.log(tree.get("Google")); // "https://google.com"
60
+ *
61
+ * const folder = tree.get("Development");
62
+ * console.log(folder.get("GitHub")); // "https://github.com"
63
+ * ```
64
+ */
10
65
  static parse(data) {
11
66
  const dom = new DOMParser().parseFromString(data, "text/html");
12
67
  const tree = BookmarksTree.fromDOM(dom);
@@ -5,12 +5,108 @@
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.HTMLText;
107
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
108
+ * ```
109
+ */
14
110
  get HTMLText(): string;
15
111
  }
16
112
  //# 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,QAAQ,IAAI,MAAM,CA+CrB;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,9 +142,39 @@ 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
160
  return new DOMParser().parseFromString(this.HTMLText, "text/html");
81
161
  }
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.HTMLText;
175
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
+ * ```
177
+ */
82
178
  get HTMLText() {
83
179
  const escapeHtml = (text) => {
84
180
  return text
@@ -5,7 +5,62 @@
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
7
  import { BookmarksTree } from "../BookmarksTree/index.js";
8
+ /**
9
+ * A parser for Netscape Bookmark format files
10
+ *
11
+ * This class provides static methods to parse Netscape Bookmark format HTML strings
12
+ * and convert them into BookmarksTree instances for easier manipulation.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
17
+ * <HTML>
18
+ * <BODY>
19
+ * <DL><p>
20
+ * <DT><A HREF="https://google.com">Google</A>
21
+ * <DT><H3>Development</H3>
22
+ * <DL><p>
23
+ * <DT><A HREF="https://github.com">GitHub</A>
24
+ * </DL><p>
25
+ * </DL>
26
+ * </BODY>
27
+ * </HTML>`;
28
+ *
29
+ * const tree = BookmarksParser.parse(bookmarkHtml);
30
+ * ```
31
+ */
8
32
  export declare class BookmarksParser {
33
+ /**
34
+ * Parses a Netscape Bookmark format HTML string into a BookmarksTree
35
+ *
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
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
45
+ * <HTML>
46
+ * <BODY>
47
+ * <DL><p>
48
+ * <DT><A HREF="https://google.com">Google</A>
49
+ * <DT><H3>Development</H3>
50
+ * <DL><p>
51
+ * <DT><A HREF="https://github.com">GitHub</A>
52
+ * </DL><p>
53
+ * </DL>
54
+ * </BODY>
55
+ * </HTML>`;
56
+ *
57
+ * const tree = BookmarksParser.parse(bookmarkHtml);
58
+ * console.log(tree.get("Google")); // "https://google.com"
59
+ *
60
+ * const folder = tree.get("Development");
61
+ * console.log(folder.get("GitHub")); // "https://github.com"
62
+ * ```
63
+ */
9
64
  static parse(data: string): BookmarksTree;
10
65
  }
11
66
  //# 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,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAKzC"}
@@ -6,7 +6,62 @@
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 {
34
+ /**
35
+ * Parses a Netscape Bookmark format HTML string into a BookmarksTree
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
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const bookmarkHtml = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
46
+ * <HTML>
47
+ * <BODY>
48
+ * <DL><p>
49
+ * <DT><A HREF="https://google.com">Google</A>
50
+ * <DT><H3>Development</H3>
51
+ * <DL><p>
52
+ * <DT><A HREF="https://github.com">GitHub</A>
53
+ * </DL><p>
54
+ * </DL>
55
+ * </BODY>
56
+ * </HTML>`;
57
+ *
58
+ * const tree = BookmarksParser.parse(bookmarkHtml);
59
+ * console.log(tree.get("Google")); // "https://google.com"
60
+ *
61
+ * const folder = tree.get("Development");
62
+ * console.log(folder.get("GitHub")); // "https://github.com"
63
+ * ```
64
+ */
10
65
  static parse(data) {
11
66
  const dom = new DOMParser().parseFromString(data, "text/html");
12
67
  const tree = BookmarksTree.fromDOM(dom);
@@ -5,12 +5,108 @@
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.HTMLText;
107
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
108
+ * ```
109
+ */
14
110
  get HTMLText(): string;
15
111
  }
16
112
  //# 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,QAAQ,IAAI,MAAM,CA+CrB;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,9 +142,39 @@ 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
160
  return new DOMParser().parseFromString(this.HTMLText, "text/html");
81
161
  }
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.HTMLText;
175
+ * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
+ * ```
177
+ */
82
178
  get HTMLText() {
83
179
  const escapeHtml = (text) => {
84
180
  return text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netscape-bookmark-parser",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "keywords": [
5
5
  "bookmark",
6
6
  "parser",
@@ -19,6 +19,9 @@
19
19
  }
20
20
  },
21
21
  "scripts": {},
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
22
25
  "dependencies": {
23
26
  "@deno/shim-deno": "~0.18.0"
24
27
  },