netscape-bookmark-parser 1.0.0-pre → 1.1.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/README-ja.md CHANGED
@@ -10,7 +10,7 @@
10
10
  > **注意:**
11
11
  > この README は AI 生成されたドキュメントです。詳細はほぼ正確ですが、不正確な説明が含まれる可能性があります。
12
12
 
13
- ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。DenoNode.js の両方のランタイムに対応しています。
13
+ ブラウザのブックマークファイル(HTML 形式)を解析し、構造化データとして操作するための TypeScript/JavaScript ライブラリです。DenoNode.js、**ブラウザ**の全てのランタイムに対応しています。
14
14
 
15
15
  ## 機能
16
16
 
@@ -38,6 +38,13 @@ import {
38
38
  } from "jsr:@grakeice/netscape-bookmark-parser";
39
39
  ```
40
40
 
41
+ ### ブラウザ
42
+
43
+ ```typescript
44
+ // ブラウザ環境では、Web最適化版を使用
45
+ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
46
+ ```
47
+
41
48
  ## 使用方法
42
49
 
43
50
  ### 基本的な例
@@ -543,8 +550,24 @@ MIT License - 詳細は[LICENSE](LICENSE)ファイルを参照してください
543
550
 
544
551
  ## 変更履歴
545
552
 
546
- ### v1.0.0-pre(最新)
553
+ ### v1.1.0(最新)
554
+
555
+ - 🌐 **ブラウザサポート**: ブラウザ環境用の Web 最適化版を追加
556
+ - 📦 **デュアルエントリーポイント**: Node.js/Deno 用(`./mod.ts`)とブラウザ用(`./mod_web.ts`)の分離ビルド
557
+ - ⚡ **ネイティブ DOM API**: ブラウザ版はネイティブ DOMParser と DOM API を使用してパフォーマンス向上
558
+ - 🔧 **ビルド最適化**: ブラウザ互換性のためのポリフィル除去を含む強化されたビルドプロセス
559
+ - 📚 **ドキュメント更新**: ブラウザ使用例と API リファレンスを追加
560
+
561
+ ### v1.0.1
547
562
 
548
- - 🚀 **プレリリース版**: 安定版 1.0.0 リリースに向けた準備
549
563
  - ✨ **コア機能**: 完全な HTML ブックマークファイル解析機能
550
- - 🏗️ **BookmarksTree クラス**: Map インターフェースを持つ階層
564
+ - 🏗️ **BookmarksTree クラス**: Map インターフェースを持つ階層構造管理
565
+ - 🔄 **双方向変換**: JSON ↔ HTML ↔ DOM 変換サポート
566
+ - 🧪 **包括的テスト**: エッジケースハンドリングを含む完全なテストカバレッジ
567
+ - 📦 **マルチランタイムサポート**: ネイティブ Deno と Node.js 互換性
568
+ - 🔧 **TypeScript サポート**: 完全な型定義と IntelliSense
569
+ - 🤖 **CI/CD パイプライン**: GitHub Actions による自動テストと公開
570
+ - 📚 **ドキュメント**: 例と API リファレンスを含む包括的な README
571
+ - 🌐 **国際化サポート**: Unicode と多言語ブックマークハンドリング
572
+ - ⚡ **パフォーマンス最適化**: 大規模ブックマークコレクションの効率的解析
573
+ - 🛡️ **エラーハンドリング**: 不正な HTML と無効な URL の適切な処理
package/README.md CHANGED
@@ -40,6 +40,13 @@ import {
40
40
  } from "jsr:@grakeice/netscape-bookmark-parser";
41
41
  ```
42
42
 
43
+ ### Browser
44
+
45
+ ```typescript
46
+ // For browser environments, use the web-optimized version
47
+ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
48
+ ```
49
+
43
50
  ## Usage
44
51
 
45
52
  ### Basic Example
@@ -143,6 +150,30 @@ console.log(devFolder.get("GitHub")); // "https://github.com"
143
150
 
144
151
  ## API Reference
145
152
 
153
+ ### Web-Optimized Version
154
+
155
+ The library provides a browser-optimized version that eliminates Node.js dependencies and uses native browser APIs:
156
+
157
+ ```typescript
158
+ // Import browser-optimized version
159
+ import { BookmarksParser, BookmarksTree } from "netscape-bookmark-parser/web";
160
+
161
+ // Works with browser File API
162
+ document
163
+ .getElementById("fileInput")
164
+ .addEventListener("change", async (event) => {
165
+ const file = event.target.files[0];
166
+ const htmlContent = await file.text();
167
+
168
+ const bookmarksTree = BookmarksParser.parse(htmlContent);
169
+ console.log(bookmarksTree.toJSON());
170
+ });
171
+
172
+ // Use native DOMParser for fromDOM method
173
+ const dom = new DOMParser().parseFromString(htmlContent, "text/html");
174
+ const tree = BookmarksTree.fromDOM(dom);
175
+ ```
176
+
146
177
  ### BookmarksParser Class
147
178
 
148
179
  The [`BookmarksParser`](src/BookmarksParser/BookmarksParser.ts) class provides static methods for parsing HTML bookmark files.
@@ -544,9 +575,16 @@ When reporting issues, please include:
544
575
 
545
576
  ## Changelog
546
577
 
547
- ### v1.0.0-pre (Latest)
578
+ ### v1.1.0 (Latest)
579
+
580
+ - 🌐 **Browser Support**: Added web-optimized version for browser environments
581
+ - 📦 **Dual Entry Points**: Separate builds for Node.js/Deno (`./mod.ts`) and browsers (`./mod_web.ts`)
582
+ - ⚡ **Native DOM APIs**: Browser version uses native DOMParser and DOM APIs for better performance
583
+ - 🔧 **Build Optimization**: Enhanced build process with polyfill removal for browser compatibility
584
+ - 📚 **Updated Documentation**: Added browser usage examples and API reference
585
+
586
+ ### v1.0.1
548
587
 
549
- - 🚀 **Pre-release Version**: Preparing for stable 1.0.0 release
550
588
  - ✨ **Core Features**: Complete HTML bookmark file parsing functionality
551
589
  - 🏗️ **BookmarksTree Class**: Hierarchical structure management with Map interface
552
590
  - 🔄 **Bidirectional Conversion**: JSON ↔ HTML ↔ DOM conversion support
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksTree } from "./src/web/BookmarksTree/index.js";
8
+ export { BookmarksParser } from "./src/web/BookmarksParser/index.js";
9
+ //# sourceMappingURL=mod_web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod_web.d.ts","sourceRoot":"","sources":["../src/mod_web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC"}
package/esm/mod_web.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksTree } from "./src/web/BookmarksTree/index.js";
8
+ export { BookmarksParser } from "./src/web/BookmarksParser/index.js";
@@ -4,7 +4,7 @@
4
4
  * This software is released under the MIT License.
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
- import { DOMParser } from "../../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
7
+ import { DOMParser } from "../deps.js";
8
8
  import { BookmarksTree } from "../BookmarksTree/index.js";
9
9
  export class BookmarksParser {
10
10
  static parse(data) {
@@ -4,7 +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/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
7
+ import { type HTMLDocument } from "../deps.js";
8
8
  export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
9
9
  constructor();
10
10
  toJSON(): Record<string, unknown>;
@@ -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,4DAA4D,CAAC;AAExH,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,CAoCrB;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,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,CAoCrB;CACD"}
@@ -4,7 +4,7 @@
4
4
  * This software is released under the MIT License.
5
5
  * https://opensource.org/licenses/MIT
6
6
  */
7
- import { DOMParser } from "../../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
7
+ import { DOMParser } from "../deps.js";
8
8
  export class BookmarksTree extends Map {
9
9
  constructor() {
10
10
  super();
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { DOMParser } from "../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
8
+ export type { Element, HTMLDocument } from "../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
9
+ //# sourceMappingURL=deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/src/deps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yDAAyD,CAAC;AACpF,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,yDAAyD,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { DOMParser } from "../deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ import { BookmarksTree } from "../BookmarksTree/index.js";
8
+ export declare class BookmarksParser {
9
+ static parse(data: string): BookmarksTree;
10
+ }
11
+ //# sourceMappingURL=BookmarksParser.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ import { DOMParser } from "../deps.js";
8
+ import { BookmarksTree } from "../BookmarksTree/index.js";
9
+ export class BookmarksParser {
10
+ static parse(data) {
11
+ const dom = new DOMParser().parseFromString(data, "text/html");
12
+ const tree = BookmarksTree.fromDOM(dom);
13
+ return tree;
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksParser } from "./BookmarksParser.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksParser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksParser } from "./BookmarksParser.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ import { type HTMLDocument } from "../deps.js";
8
+ export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
9
+ constructor();
10
+ toJSON(): Record<string, unknown>;
11
+ static fromJSON(json: Record<string, unknown>): BookmarksTree;
12
+ static fromDOM(dom: HTMLDocument): BookmarksTree;
13
+ toDOM(): HTMLDocument;
14
+ get HTMLText(): string;
15
+ }
16
+ //# sourceMappingURL=BookmarksTree.d.ts.map
@@ -0,0 +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,CAoCrB;CACD"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ import { DOMParser } from "../deps.js";
8
+ export class BookmarksTree extends Map {
9
+ constructor() {
10
+ super();
11
+ }
12
+ toJSON() {
13
+ const json = {};
14
+ for (const [key, value] of this.entries()) {
15
+ if (typeof value === "string") {
16
+ json[key] = value;
17
+ }
18
+ else if (value instanceof BookmarksTree) {
19
+ json[key] = value.toJSON();
20
+ }
21
+ }
22
+ return json;
23
+ }
24
+ static fromJSON(json) {
25
+ const tree = new BookmarksTree();
26
+ if (typeof json === "object" && json !== null) {
27
+ for (const [key, value] of Object.entries(json)) {
28
+ if (typeof value === "string") {
29
+ tree.set(key, value);
30
+ }
31
+ else if (typeof value === "object" && value !== null) {
32
+ tree.set(key, BookmarksTree.fromJSON(value));
33
+ }
34
+ }
35
+ }
36
+ return tree;
37
+ }
38
+ static fromDOM(dom) {
39
+ const tree = new BookmarksTree();
40
+ const document = dom;
41
+ const processElement = (element, currentTree) => {
42
+ const children = Array.from(element.children);
43
+ for (let i = 0; i < children.length; i++) {
44
+ const child = children[i];
45
+ if (child.tagName === "DT") {
46
+ const h3 = child.querySelector("h3");
47
+ const link = child.querySelector("a");
48
+ if (h3) {
49
+ // フォルダの場合
50
+ const folderName = h3.textContent?.trim() || "";
51
+ if (folderName) {
52
+ const folderTree = new BookmarksTree();
53
+ currentTree.set(folderName, folderTree);
54
+ processElement(child, folderTree);
55
+ }
56
+ }
57
+ else if (link) {
58
+ // リンクの場合
59
+ const href = link.getAttribute("href");
60
+ const title = link.textContent?.trim() || "";
61
+ if (href && title) {
62
+ currentTree.set(title, href);
63
+ }
64
+ }
65
+ }
66
+ else if (child.tagName === "DL") {
67
+ // ネストしたDLタグの場合も処理
68
+ processElement(child, currentTree);
69
+ }
70
+ }
71
+ };
72
+ // HTMLのBODY全体から処理を開始
73
+ const body = document.body;
74
+ if (body) {
75
+ processElement(body, tree);
76
+ }
77
+ return tree;
78
+ }
79
+ toDOM() {
80
+ return new DOMParser().parseFromString(this.HTMLText, "text/html");
81
+ }
82
+ get HTMLText() {
83
+ const createBookmarkList = (tree, indent = "") => {
84
+ let html = `${indent}<DL><p>\n`;
85
+ for (const [key, value] of tree.entries()) {
86
+ if (typeof value === "string") {
87
+ // ブックマークの場合: <DT><A HREF="url">タイトル</A>
88
+ html += `${indent} <DT><A HREF="${value}">${key}</A>\n`;
89
+ }
90
+ else if (value instanceof BookmarksTree) {
91
+ // フォルダの場合: <DT><H3>フォルダ名</H3>
92
+ html += `${indent} <DT><H3>${key}</H3>\n`;
93
+ html += createBookmarkList(value, indent + " ");
94
+ html += `${indent} </DL><p>\n`;
95
+ }
96
+ }
97
+ if (indent === "") {
98
+ // ルートレベルの場合は閉じタグを追加
99
+ html += `</DL>\n`;
100
+ }
101
+ return html;
102
+ };
103
+ const htmlTemplate = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
104
+ <HTML>
105
+ <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
106
+ <TITLE>Bookmark</TITLE>
107
+ <H1>Bookmark</H1>
108
+ <BODY>
109
+ ${createBookmarkList(this)}</BODY>
110
+ </HTML>`;
111
+ return htmlTemplate;
112
+ }
113
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksTree } from "./BookmarksTree.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/web/BookmarksTree/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ export { BookmarksTree } from "./BookmarksTree.js";
@@ -0,0 +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
+ export declare const DOMParser: any;
8
+ export type Element = globalThis.Element;
9
+ export type HTMLDocument = globalThis.HTMLDocument;
10
+ //# sourceMappingURL=deps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../../src/src/web/deps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,eAAO,MAAM,SAAS,KAAuB,CAAC;AAC9C,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;AACzC,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) 2025 grakeice
3
+ *
4
+ * This software is released under the MIT License.
5
+ * https://opensource.org/licenses/MIT
6
+ */
7
+ // deno-lint-ignore ban-ts-comment
8
+ // @ts-nocheck
9
+ export const DOMParser = globalThis.DOMParser;
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "netscape-bookmark-parser",
3
- "version": "1.0.0-pre",
3
+ "version": "1.1.0",
4
+ "keywords": [
5
+ "bookmark",
6
+ "parser",
7
+ "netscape"
8
+ ],
4
9
  "author": "grakeice",
5
10
  "repository": "https://github.com/grakeice/netscape-bookmark-parser",
6
11
  "license": "MIT",
@@ -8,6 +13,9 @@
8
13
  "exports": {
9
14
  ".": {
10
15
  "import": "./esm/mod.js"
16
+ },
17
+ "./web": {
18
+ "import": "./esm/mod_web.js"
11
19
  }
12
20
  },
13
21
  "scripts": {},