@bernierllc/markdown-parser 1.2.4 → 1.4.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/dist/MarkdownParser.js +3 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/utils/cache.js +3 -0
- package/package.json +7 -3
- package/.eslintrc.js +0 -27
- package/CHANGELOG.md +0 -108
- package/__tests__/MarkdownParser.test.ts +0 -791
- package/__tests__/ast-utils.test.ts +0 -319
- package/__tests__/cache.test.ts +0 -243
- package/__tests__/plugins.test.ts +0 -282
- package/jest.config.cjs +0 -29
- package/src/MarkdownParser.ts +0 -517
- package/src/index.ts +0 -13
- package/src/plugins/commonmark.ts +0 -23
- package/src/plugins/gfm.ts +0 -23
- package/src/plugins/index.ts +0 -10
- package/src/types.ts +0 -114
- package/src/utils/ast-utils.ts +0 -81
- package/src/utils/cache.ts +0 -106
- package/tsconfig.json +0 -30
package/src/utils/ast-utils.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ASTNode } from '../types';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Count total nodes in AST
|
|
13
|
-
*/
|
|
14
|
-
export function countNodes(node: ASTNode): number {
|
|
15
|
-
let count = 1;
|
|
16
|
-
if (node.children) {
|
|
17
|
-
for (const child of node.children) {
|
|
18
|
-
count += countNodes(child);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return count;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Visit each node in the AST
|
|
26
|
-
*/
|
|
27
|
-
export function visitNodes(node: ASTNode, visitor: (node: ASTNode) => void): void {
|
|
28
|
-
visitor(node);
|
|
29
|
-
if (node.children) {
|
|
30
|
-
for (const child of node.children) {
|
|
31
|
-
visitNodes(child, visitor);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Transform AST nodes recursively
|
|
38
|
-
*/
|
|
39
|
-
export function transformNodes(node: ASTNode, transformer: (node: ASTNode) => ASTNode): ASTNode {
|
|
40
|
-
const transformed = transformer(node);
|
|
41
|
-
if (transformed.children) {
|
|
42
|
-
return {
|
|
43
|
-
...transformed,
|
|
44
|
-
children: transformed.children.map((child) => transformNodes(child, transformer)),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return transformed;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Find nodes matching a predicate
|
|
52
|
-
*/
|
|
53
|
-
export function findNodes(node: ASTNode, predicate: (node: ASTNode) => boolean): ASTNode[] {
|
|
54
|
-
const results: ASTNode[] = [];
|
|
55
|
-
if (predicate(node)) {
|
|
56
|
-
results.push(node);
|
|
57
|
-
}
|
|
58
|
-
if (node.children) {
|
|
59
|
-
for (const child of node.children) {
|
|
60
|
-
results.push(...findNodes(child, predicate));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return results;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Clone an AST node deeply
|
|
68
|
-
*/
|
|
69
|
-
export function cloneNode(node: ASTNode): ASTNode {
|
|
70
|
-
return {
|
|
71
|
-
...node,
|
|
72
|
-
children: node.children ? node.children.map(cloneNode) : undefined,
|
|
73
|
-
attributes: node.attributes ? { ...node.attributes } : undefined,
|
|
74
|
-
position: node.position
|
|
75
|
-
? {
|
|
76
|
-
start: { ...node.position.start },
|
|
77
|
-
end: { ...node.position.end },
|
|
78
|
-
}
|
|
79
|
-
: undefined,
|
|
80
|
-
};
|
|
81
|
-
}
|
package/src/utils/cache.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { ASTNode, CacheEntry } from '../types';
|
|
10
|
-
import { createHash } from 'crypto';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Cache manager for parsed markdown AST
|
|
14
|
-
*/
|
|
15
|
-
export class CacheManager {
|
|
16
|
-
private cache: Map<string, CacheEntry>;
|
|
17
|
-
private maxSize: number;
|
|
18
|
-
private ttl: number; // Time to live in seconds
|
|
19
|
-
|
|
20
|
-
constructor(maxSize: number = 1000, ttl: number = 3600) {
|
|
21
|
-
this.cache = new Map();
|
|
22
|
-
this.maxSize = maxSize;
|
|
23
|
-
this.ttl = ttl;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Generate cache key from markdown content
|
|
28
|
-
*/
|
|
29
|
-
generateKey(markdown: string): string {
|
|
30
|
-
return createHash('sha256').update(markdown).digest('hex').substring(0, 16);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get AST from cache if valid
|
|
35
|
-
*/
|
|
36
|
-
get(key: string): ASTNode | null {
|
|
37
|
-
const entry = this.cache.get(key);
|
|
38
|
-
if (!entry) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Check TTL
|
|
43
|
-
const age = (Date.now() - entry.timestamp) / 1000;
|
|
44
|
-
if (age > this.ttl) {
|
|
45
|
-
this.cache.delete(key);
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return entry.ast;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Store AST in cache with size limit
|
|
54
|
-
*/
|
|
55
|
-
set(key: string, ast: ASTNode): void {
|
|
56
|
-
// Enforce max size (FIFO eviction)
|
|
57
|
-
if (this.cache.size >= this.maxSize) {
|
|
58
|
-
const oldestKey = this.cache.keys().next().value as string;
|
|
59
|
-
this.cache.delete(oldestKey);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.cache.set(key, {
|
|
63
|
-
ast,
|
|
64
|
-
timestamp: Date.now(),
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Check if key exists in cache
|
|
70
|
-
*/
|
|
71
|
-
has(key: string): boolean {
|
|
72
|
-
return this.get(key) !== null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Clear all cache entries
|
|
77
|
-
*/
|
|
78
|
-
clear(): void {
|
|
79
|
-
this.cache.clear();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Get current cache size
|
|
84
|
-
*/
|
|
85
|
-
size(): number {
|
|
86
|
-
return this.cache.size;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Remove expired entries
|
|
91
|
-
*/
|
|
92
|
-
prune(): number {
|
|
93
|
-
const now = Date.now();
|
|
94
|
-
let removed = 0;
|
|
95
|
-
|
|
96
|
-
for (const [key, entry] of this.cache.entries()) {
|
|
97
|
-
const age = (now - entry.timestamp) / 1000;
|
|
98
|
-
if (age > this.ttl) {
|
|
99
|
-
this.cache.delete(key);
|
|
100
|
-
removed++;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return removed;
|
|
105
|
-
}
|
|
106
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"rootDir": "./src",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"moduleResolution": "node",
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"noImplicitAny": true,
|
|
17
|
-
"strictNullChecks": true,
|
|
18
|
-
"strictFunctionTypes": true,
|
|
19
|
-
"strictBindCallApply": true,
|
|
20
|
-
"strictPropertyInitialization": true,
|
|
21
|
-
"noImplicitThis": true,
|
|
22
|
-
"alwaysStrict": true,
|
|
23
|
-
"noUnusedLocals": true,
|
|
24
|
-
"noUnusedParameters": true,
|
|
25
|
-
"noImplicitReturns": true,
|
|
26
|
-
"noFallthroughCasesInSwitch": true
|
|
27
|
-
},
|
|
28
|
-
"include": ["src/**/*"],
|
|
29
|
-
"exclude": ["node_modules", "dist", "__tests__"]
|
|
30
|
-
}
|