@oh-my-pi/pi-utils 13.5.0 → 13.5.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.
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/mermaid-ascii.ts +31 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-utils",
|
|
4
|
-
"version": "13.5.
|
|
4
|
+
"version": "13.5.2",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"test": "bun test"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"beautiful-mermaid": "1.1.3",
|
|
30
31
|
"winston": "^3.19",
|
|
31
32
|
"winston-daily-rotate-file": "^5.0"
|
|
32
33
|
},
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./glob";
|
|
|
9
9
|
export * from "./indent";
|
|
10
10
|
export * from "./json";
|
|
11
11
|
export * as logger from "./logger";
|
|
12
|
+
export * from "./mermaid-ascii";
|
|
12
13
|
export * as postmortem from "./postmortem";
|
|
13
14
|
export * as procmgr from "./procmgr";
|
|
14
15
|
export { setNativeKillTree } from "./procmgr";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type AsciiRenderOptions, renderMermaidASCII } from "beautiful-mermaid";
|
|
2
|
+
|
|
3
|
+
export type { AsciiRenderOptions as MermaidAsciiRenderOptions };
|
|
4
|
+
|
|
5
|
+
export function renderMermaidAscii(source: string, options?: AsciiRenderOptions): string {
|
|
6
|
+
return renderMermaidASCII(source, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function renderMermaidAsciiSafe(source: string, options?: AsciiRenderOptions): string | null {
|
|
10
|
+
try {
|
|
11
|
+
return renderMermaidASCII(source, options);
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extract mermaid code blocks from markdown text.
|
|
19
|
+
*/
|
|
20
|
+
export function extractMermaidBlocks(markdown: string): { source: string; hash: bigint }[] {
|
|
21
|
+
const blocks: { source: string; hash: bigint }[] = [];
|
|
22
|
+
const regex = /```mermaid\s*\n([\s\S]*?)```/g;
|
|
23
|
+
|
|
24
|
+
for (let match = regex.exec(markdown); match !== null; match = regex.exec(markdown)) {
|
|
25
|
+
const source = match[1].trim();
|
|
26
|
+
const hash = Bun.hash.xxHash64(source);
|
|
27
|
+
blocks.push({ source, hash });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return blocks;
|
|
31
|
+
}
|