netscape-bookmark-parser 1.1.4 → 1.2.2

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.
Files changed (122) hide show
  1. package/LICENSE +2 -2
  2. package/README-ja.md +108 -98
  3. package/README.md +108 -98
  4. package/dist/index.d.ts +237 -0
  5. package/dist/index.js +347 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/web.d.ts +239 -0
  8. package/dist/web.js +340 -0
  9. package/dist/web.js.map +1 -0
  10. package/package.json +58 -15
  11. package/esm/_dnt.polyfills.d.ts +0 -101
  12. package/esm/_dnt.polyfills.d.ts.map +0 -1
  13. package/esm/_dnt.polyfills.js +0 -127
  14. package/esm/_dnt.shims.d.ts +0 -6
  15. package/esm/_dnt.shims.d.ts.map +0 -1
  16. package/esm/_dnt.shims.js +0 -61
  17. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts +0 -14
  18. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.d.ts.map +0 -1
  19. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/build/deno-wasm/deno-wasm.js +0 -151
  20. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts +0 -23
  21. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.d.ts.map +0 -1
  22. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/deno-dom-wasm.js +0 -26
  23. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts +0 -24
  24. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.d.ts.map +0 -1
  25. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/api.js +0 -48
  26. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts +0 -5
  27. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.d.ts.map +0 -1
  28. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/constructor-lock.js +0 -4
  29. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts +0 -4
  30. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.d.ts.map +0 -1
  31. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/deserialize.js +0 -61
  32. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts +0 -19
  33. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.d.ts.map +0 -1
  34. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document-fragment.js +0 -110
  35. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts +0 -68
  36. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.d.ts.map +0 -1
  37. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/document.js +0 -322
  38. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts +0 -6
  39. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.d.ts.map +0 -1
  40. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/dom-parser.js +0 -46
  41. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts +0 -127
  42. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.d.ts.map +0 -1
  43. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/element.js +0 -1068
  44. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts +0 -29
  45. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.d.ts.map +0 -1
  46. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/elements/html-template-element.js +0 -94
  47. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts +0 -21
  48. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.d.ts.map +0 -1
  49. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/html-collection.js +0 -80
  50. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts +0 -23
  51. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.d.ts.map +0 -1
  52. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node-list.js +0 -159
  53. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts +0 -127
  54. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.d.ts.map +0 -1
  55. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/node.js +0 -629
  56. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts +0 -6
  57. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.d.ts.map +0 -1
  58. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/custom-api.js +0 -5
  59. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts +0 -12
  60. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.d.ts.map +0 -1
  61. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi-types.js +0 -2
  62. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts +0 -90
  63. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.d.ts.map +0 -1
  64. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/nwsapi.js +0 -1611
  65. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts +0 -16
  66. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.d.ts.map +0 -1
  67. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/selectors.js +0 -28
  68. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts +0 -8
  69. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.d.ts.map +0 -1
  70. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle-types.js +0 -2
  71. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts +0 -7
  72. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.d.ts.map +0 -1
  73. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/selectors/sizzle.js +0 -2061
  74. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts +0 -3
  75. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.d.ts.map +0 -1
  76. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/string-cache.js +0 -10
  77. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts +0 -13
  78. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.d.ts.map +0 -1
  79. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils-types.js +0 -8
  80. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts +0 -31
  81. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.d.ts.map +0 -1
  82. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/dom/utils.js +0 -239
  83. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts +0 -5
  84. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.d.ts.map +0 -1
  85. package/esm/deps/jsr.io/@b-fuze/deno-dom/0.1.49/src/parser.js +0 -20
  86. package/esm/mod.d.ts +0 -10
  87. package/esm/mod.d.ts.map +0 -1
  88. package/esm/mod.js +0 -9
  89. package/esm/mod_web.d.ts +0 -9
  90. package/esm/mod_web.d.ts.map +0 -1
  91. package/esm/mod_web.js +0 -8
  92. package/esm/package.json +0 -3
  93. package/esm/src/BookmarksParser/BookmarksParser.d.ts +0 -130
  94. package/esm/src/BookmarksParser/BookmarksParser.d.ts.map +0 -1
  95. package/esm/src/BookmarksParser/BookmarksParser.js +0 -142
  96. package/esm/src/BookmarksParser/index.d.ts +0 -8
  97. package/esm/src/BookmarksParser/index.d.ts.map +0 -1
  98. package/esm/src/BookmarksParser/index.js +0 -7
  99. package/esm/src/BookmarksTree/BookmarksTree.d.ts +0 -118
  100. package/esm/src/BookmarksTree/BookmarksTree.d.ts.map +0 -1
  101. package/esm/src/BookmarksTree/BookmarksTree.js +0 -225
  102. package/esm/src/BookmarksTree/index.d.ts +0 -8
  103. package/esm/src/BookmarksTree/index.d.ts.map +0 -1
  104. package/esm/src/BookmarksTree/index.js +0 -7
  105. package/esm/src/deps.d.ts +0 -9
  106. package/esm/src/deps.d.ts.map +0 -1
  107. package/esm/src/deps.js +0 -7
  108. package/esm/src/web/BookmarksParser/BookmarksParser.d.ts +0 -130
  109. package/esm/src/web/BookmarksParser/BookmarksParser.d.ts.map +0 -1
  110. package/esm/src/web/BookmarksParser/BookmarksParser.js +0 -142
  111. package/esm/src/web/BookmarksParser/index.d.ts +0 -8
  112. package/esm/src/web/BookmarksParser/index.d.ts.map +0 -1
  113. package/esm/src/web/BookmarksParser/index.js +0 -7
  114. package/esm/src/web/BookmarksTree/BookmarksTree.d.ts +0 -118
  115. package/esm/src/web/BookmarksTree/BookmarksTree.d.ts.map +0 -1
  116. package/esm/src/web/BookmarksTree/BookmarksTree.js +0 -225
  117. package/esm/src/web/BookmarksTree/index.d.ts +0 -8
  118. package/esm/src/web/BookmarksTree/index.d.ts.map +0 -1
  119. package/esm/src/web/BookmarksTree/index.js +0 -7
  120. package/esm/src/web/deps.d.ts +0 -10
  121. package/esm/src/web/deps.d.ts.map +0 -1
  122. package/esm/src/web/deps.js +0 -9
@@ -1,142 +0,0 @@
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
- /**
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
- */
33
- export class BookmarksParser {
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");
87
- const tree = BookmarksTree.fromDOM(dom);
88
- return tree;
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
- }
142
- }
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksParser/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,7 +0,0 @@
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";
@@ -1,118 +0,0 @@
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
- /**
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
- */
24
- export declare class BookmarksTree extends Map<string, string | BookmarksTree> {
25
- /**
26
- * Creates a new BookmarksTree instance
27
- */
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
- */
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
- */
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
- */
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
- */
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
- */
116
- get HTMLText(): string;
117
- }
118
- //# sourceMappingURL=BookmarksTree.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,225 +0,0 @@
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
- /**
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
- */
24
- export class BookmarksTree extends Map {
25
- /**
26
- * Creates a new BookmarksTree instance
27
- */
28
- constructor() {
29
- super();
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
- */
46
- toJSON() {
47
- const json = {};
48
- for (const [key, value] of this.entries()) {
49
- if (typeof value === "string") {
50
- json[key] = value;
51
- }
52
- else if (value instanceof BookmarksTree) {
53
- json[key] = value.toJSON();
54
- }
55
- }
56
- return json;
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
- */
73
- static fromJSON(json) {
74
- const tree = new BookmarksTree();
75
- if (typeof json === "object" && json !== null) {
76
- for (const [key, value] of Object.entries(json)) {
77
- if (typeof value === "string") {
78
- tree.set(key, value);
79
- }
80
- else if (typeof value === "object" && value !== null) {
81
- tree.set(key, BookmarksTree.fromJSON(value));
82
- }
83
- }
84
- }
85
- return tree;
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
- */
104
- static fromDOM(dom) {
105
- const tree = new BookmarksTree();
106
- const document = dom;
107
- const processElement = (element, currentTree) => {
108
- const children = Array.from(element.children);
109
- for (let i = 0; i < children.length; i++) {
110
- const child = children[i];
111
- if (child.tagName === "DT") {
112
- const h3 = child.querySelector("h3");
113
- const link = child.querySelector("a");
114
- if (h3) {
115
- // フォルダの場合
116
- const folderName = h3.textContent?.trim() || "";
117
- if (folderName) {
118
- const folderTree = new BookmarksTree();
119
- currentTree.set(folderName, folderTree);
120
- processElement(child, folderTree);
121
- }
122
- }
123
- else if (link) {
124
- // リンクの場合
125
- const href = link.getAttribute("href");
126
- const title = link.textContent?.trim() || "";
127
- if (href && title) {
128
- currentTree.set(title, href);
129
- }
130
- }
131
- }
132
- else if (child.tagName === "DL") {
133
- // ネストしたDLタグの場合も処理
134
- processElement(child, currentTree);
135
- }
136
- }
137
- };
138
- // HTMLのBODY全体から処理を開始
139
- const body = document.body;
140
- if (body) {
141
- processElement(body, tree);
142
- }
143
- return tree;
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
- */
159
- toDOM() {
160
- return new DOMParser().parseFromString(this.HTMLString, "text/html");
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.HTMLString;
175
- * console.log(html); // <!DOCTYPE NETSCAPE-Bookmark-file-1>...
176
- * ```
177
- */
178
- get HTMLString() {
179
- const escapeHtml = (text) => {
180
- return text
181
- .replace(/&/g, "&amp;")
182
- .replace(/</g, "&lt;")
183
- .replace(/>/g, "&gt;")
184
- .replace(/"/g, "&quot;")
185
- .replace(/'/g, "&#39;");
186
- };
187
- const createBookmarkList = (tree, indent = "") => {
188
- let html = `${indent}<DL><p>\n`;
189
- for (const [key, value] of tree.entries()) {
190
- if (typeof value === "string") {
191
- // ブックマークの場合: <DT><A HREF="url">タイトル</A>
192
- html += `${indent} <DT><A HREF="${escapeHtml(value)}">${escapeHtml(key)}</A>\n`;
193
- }
194
- else if (value instanceof BookmarksTree) {
195
- // フォルダの場合: <DT><H3>フォルダ名</H3>
196
- html += `${indent} <DT><H3>${escapeHtml(key)}</H3>\n`;
197
- html += createBookmarkList(value, indent + " ");
198
- html += `${indent} </DL><p>\n`;
199
- }
200
- }
201
- if (indent === "") {
202
- // ルートレベルの場合は閉じタグを追加
203
- html += `</DL>\n`;
204
- }
205
- return html;
206
- };
207
- const htmlTemplate = `<!DOCTYPE NETSCAPE-Bookmark-file-1>
208
- <HTML>
209
- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
210
- <TITLE>Bookmark</TITLE>
211
- <H1>Bookmark</H1>
212
- <BODY>
213
- ${createBookmarkList(this)}</BODY>
214
- </HTML>`;
215
- return htmlTemplate;
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
- }
225
- }
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/BookmarksTree/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,7 +0,0 @@
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";
package/esm/src/deps.d.ts DELETED
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
package/esm/src/deps.js DELETED
@@ -1,7 +0,0 @@
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";
@@ -1,130 +0,0 @@
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
- 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
- */
33
- export declare class BookmarksParser {
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;
129
- }
130
- //# sourceMappingURL=BookmarksParser.d.ts.map