@filen/utils 0.0.1 → 0.0.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/dist/checklistParser.js +52 -0
- package/dist/index.js +1 -0
- package/dist/types/checklistParser.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { parse } from "node-html-better-parser";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
export class ChecklistParser {
|
|
4
|
+
parse(html) {
|
|
5
|
+
try {
|
|
6
|
+
const root = parse(html);
|
|
7
|
+
const ul = root.querySelectorAll("ul");
|
|
8
|
+
if (!ul || ul.length === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const checklist = [];
|
|
12
|
+
for (const item of ul) {
|
|
13
|
+
const checked = item.getAttribute("data-checked") === "true";
|
|
14
|
+
const li = item.querySelectorAll("li");
|
|
15
|
+
for (const liItem of li) {
|
|
16
|
+
checklist.push({
|
|
17
|
+
checked,
|
|
18
|
+
content: liItem.rawText ? liItem.rawText.trim() : "",
|
|
19
|
+
id: uuidv4()
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return checklist;
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
stringify(checklist) {
|
|
30
|
+
if (checklist.length === 0) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
let html = "";
|
|
34
|
+
let currentCheckedStatus = null;
|
|
35
|
+
for (const item of checklist) {
|
|
36
|
+
if (currentCheckedStatus !== item.checked) {
|
|
37
|
+
if (currentCheckedStatus !== null) {
|
|
38
|
+
html += "</ul>";
|
|
39
|
+
}
|
|
40
|
+
html += `<ul data-checked="${item.checked}">`;
|
|
41
|
+
currentCheckedStatus = item.checked;
|
|
42
|
+
}
|
|
43
|
+
html += `<li>${item.content.trim().length > 0 ? item.content.trim() : "<br>"}</li>`;
|
|
44
|
+
}
|
|
45
|
+
if (checklist.length > 0) {
|
|
46
|
+
html += "</ul>";
|
|
47
|
+
}
|
|
48
|
+
return html;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const checklistParser = new ChecklistParser();
|
|
52
|
+
export default checklistParser;
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ChecklistItem = {
|
|
2
|
+
checked: boolean;
|
|
3
|
+
content: string;
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
export type Checklist = ChecklistItem[];
|
|
7
|
+
export declare class ChecklistParser {
|
|
8
|
+
parse(html: string): Checklist;
|
|
9
|
+
stringify(checklist: Checklist): string;
|
|
10
|
+
}
|
|
11
|
+
export declare const checklistParser: ChecklistParser;
|
|
12
|
+
export default checklistParser;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@filen/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A collection of utils for Filen",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/FilenCloudDienste/filen-
|
|
8
|
+
"url": "https://github.com/FilenCloudDienste/filen-ts/packages/filen-utils"
|
|
9
9
|
},
|
|
10
10
|
"author": "Filen Cloud Dienste UG",
|
|
11
11
|
"main": "dist/index.js",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"clsx": "^2.1.1",
|
|
37
|
+
"node-html-better-parser": "^1.5.8",
|
|
37
38
|
"tailwind-merge": "^3.3.1",
|
|
38
39
|
"uuid": "^13.0.0"
|
|
39
40
|
}
|