nx-json-parser 1.2.0 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-json-parser",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Transform strings to JSON based on Markdown structure using unified/remark",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,4 +41,4 @@
41
41
  "ts-node": "^10.9.2",
42
42
  "typescript": "^5.3.3"
43
43
  }
44
- }
44
+ }
@@ -1,86 +0,0 @@
1
- import { toString } from 'mdast-util-to-string';
2
-
3
- export function remarkBulletSections() {
4
- return (tree: any) => {
5
- const children = tree.children;
6
- if (!children) return;
7
-
8
- for (let i = 0; i < children.length; i++) {
9
- const node = children[i];
10
- if (node.type === 'list' && node.ordered === false) {
11
- const items = node.children;
12
- if (items.length === 0) continue;
13
-
14
- const newRootNodes: any[] = [];
15
- let currentListItems: any[] = [];
16
-
17
- items.forEach((item: any, idx: number) => {
18
- const firstChild = item.children[0];
19
- const text = firstChild ? toString(firstChild) : '';
20
- const lines = text.trim().split('\n');
21
- const firstLine = lines[0]?.trim() || '';
22
-
23
- const isShort = firstLine.length > 0 && firstLine.length < 150;
24
- const hasMoreContent = lines.length > 1 || item.children.length > 1;
25
-
26
- // Section detection:
27
- // 1. It's short and has more content.
28
- // 2. OR it's short and is followed by a non-short item? (Hard to check here)
29
- // 3. OR it's one of the "known" section keywords.
30
- const keywords = ['answer', 'assumptions', 'unknowns', 'evidence', 'protection', 'control', 'management', 'design', 'logging', 'monitoring', 'backups', 'compliance', 'governance', 'modeling', 'incident', 'vendor', 'changes'];
31
- const isSectionKeyword = keywords.some(k => firstLine.toLowerCase().includes(k));
32
-
33
- if (isShort && (hasMoreContent || isSectionKeyword)) {
34
- // Flush existing list items if any
35
- if (currentListItems.length > 0) {
36
- newRootNodes.push({
37
- type: 'list',
38
- ordered: false,
39
- children: [...currentListItems]
40
- });
41
- currentListItems = [];
42
- }
43
-
44
- // Add as heading
45
- newRootNodes.push({
46
- type: 'heading',
47
- depth: 2,
48
- children: [{ type: 'text', value: firstLine }]
49
- });
50
-
51
- // Add content
52
- if (lines.length > 1) {
53
- newRootNodes.push({
54
- type: 'paragraph',
55
- children: [{ type: 'text', value: lines.slice(1).join('\n').trim() }]
56
- });
57
- }
58
- if (item.children.length > 1) {
59
- newRootNodes.push(...item.children.slice(1));
60
- }
61
- } else {
62
- currentListItems.push(item);
63
- }
64
- });
65
-
66
- // Flush remaining
67
- if (currentListItems.length > 0) {
68
- newRootNodes.push({
69
- type: 'list',
70
- ordered: false,
71
- children: [...currentListItems]
72
- });
73
- }
74
-
75
- if (newRootNodes.length > 0) {
76
- // If we performed any transformation (i.e., we found at least one heading)
77
- const hasHeadings = newRootNodes.some(n => n.type === 'heading');
78
- if (hasHeadings) {
79
- children.splice(i, 1, ...newRootNodes);
80
- i += newRootNodes.length - 1;
81
- }
82
- }
83
- }
84
- }
85
- };
86
- }