54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import type { FinancialStatementKind } from '@/lib/types';
|
|
|
|
export function classifyStatementRole(roleUri: string): FinancialStatementKind | null {
|
|
const normalized = roleUri.toLowerCase();
|
|
|
|
if (/cash\s*flow|statementsof?cashflows|netcash/.test(normalized)) {
|
|
return 'cash_flow';
|
|
}
|
|
|
|
if (/shareholders?|stockholders?|equity|retainedearnings/.test(normalized)) {
|
|
return 'equity';
|
|
}
|
|
|
|
if (/comprehensive\s*income/.test(normalized)) {
|
|
return 'comprehensive_income';
|
|
}
|
|
|
|
if (/balance\s*sheet|financial\s*position|assets?andliabilities/.test(normalized)) {
|
|
return 'balance';
|
|
}
|
|
|
|
if (/operations|income\s*statement|statementsofincome|profit/.test(normalized)) {
|
|
return 'income';
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function conceptStatementFallback(localName: string): FinancialStatementKind | null {
|
|
const normalized = localName.toLowerCase();
|
|
|
|
if (/cash|operatingactivities|investingactivities|financingactivities/.test(normalized)) {
|
|
return 'cash_flow';
|
|
}
|
|
|
|
if (/equity|retainedearnings|additionalpaidincapital/.test(normalized)) {
|
|
return 'equity';
|
|
}
|
|
|
|
if (/comprehensiveincome/.test(normalized)) {
|
|
return 'comprehensive_income';
|
|
}
|
|
|
|
if (/asset|liabilit|debt/.test(normalized)) {
|
|
return 'balance';
|
|
}
|
|
|
|
if (/revenue|income|profit|expense|costof/.test(normalized)) {
|
|
return 'income';
|
|
}
|
|
|
|
return null;
|
|
}
|