concept-collection / proofery
proofery / src / nodeParser.ts
26 lines · 809 BBlameHistoryRaw
1/**
2 * Node.js-specific parser functions that use the fs module.
3 * These functions are not available in browser environments.
4 */
6import * as fs from 'fs';
7import { parseContent } from './parser.js';
8import type { Block } from './block.js';
10/**
11 * Parse a .prf file from the filesystem and return a list of top-level blocks.
12 * This function is only available in Node.js environments.
13 */
14export function parseFileSync(filepath: string): Block[] {
15 const content = fs.readFileSync(filepath, 'utf-8');
16 return parseContent(content);
19/**
20 * Async version of parseFileSync.
21 * This function is only available in Node.js environments.
22 */
23export async function parseFile(filepath: string): Promise<Block[]> {
24 const content = fs.readFileSync(filepath, 'utf-8');
25 return parseContent(content);