Advanced Parsee Usage
Learn advanced parsing strategies, filtering techniques, and complex source code analysis.
Parsing with Different Options
Configure parse options for detailed information:
ts
import { parseWithTsMorph } from "@briklab/parsee";
const source = `
export class User {
/**
* Create a user
* @param id - User ID
*/
constructor(public id: string) {}
getName(): string {
return "User";
}
}
`;
// Include all metadata
const fullParse = parseWithTsMorph(source, "user.ts", {
Name: "include",
Type: "include",
Members: "include",
Decorators: "include",
JSDoc: "include",
Position: "include"
});
console.log(fullParse);Filtering Parse Results
Process results by type:
ts
import { parseWithTsMorph } from "@briklab/parsee";
import type { ParsedItem } from "@briklab/parsee/types/parseditem";
const source = `
export class User { }
export function createUser(name: string) { }
export const version = "1.0.0";
export interface IUser { }
`;
const items = parseWithTsMorph(source, "file.ts", { Name: "include" });
// Filter by kind
const classes = items.filter(item => item.kind === "class");
const functions = items.filter(item => item.kind === "function");
const variables = items.filter(item => item.kind === "variable");
const interfaces = items.filter(item => item.kind === "interface");
console.log("Classes:", classes.length);
console.log("Functions:", functions.length);
console.log("Variables:", variables.length);
console.log("Interfaces:", interfaces.length);Live Demo - Code Analysis
Console
No logs yet.
Member Analysis
Analyze class members:
ts
import { parseWithTsMorph } from "@briklab/parsee";
const source = `
export class Database {
constructor(host: string, port: number) { }
connect(): Promise<void> { }
disconnect(): void { }
query(sql: string): unknown[] { }
}
`;
const items = parseWithTsMorph(source, "db.ts", {
Name: "include",
Members: "include"
});
const classItem = items.find(item => item.kind === "class");
if (classItem && "Members" in classItem) {
console.log(`Class has ${classItem.Members?.length || 0} members`);
}Type Information Extraction
Extract type annotations:
ts
import { parseWithTsMorph } from "@briklab/parsee";
const source = `
export function processUser(user: {
id: number;
name: string;
email: string;
}): Promise<{ success: boolean }> {
return Promise.resolve({ success: true });
}
`;
const items = parseWithTsMorph(source, "processor.ts", {
Name: "include",
Type: "include"
});
items.forEach(item => {
if ("Type" in item && item.Type) {
console.log(`${item.Name}: ${item.Type}`);
}
});Documentation Extraction
Extract JSDoc comments:
ts
import { parseWithTsMorph } from "@briklab/parsee";
const source = `
/**
* Calculates the sum of two numbers
* @param a - First number
* @param b - Second number
* @returns The sum of a and b
*/
export function add(a: number, b: number): number {
return a + b;
}
`;
const items = parseWithTsMorph(source, "math.ts", {
Name: "include",
JSDoc: "include"
});
console.log(items);Next Steps
- Getting Started: Back to basics
- Examples: Real-world use cases