JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18
  • Score
    100M100P100Q26096F
  • License MIT

Simple TypeScript library for parsing Indonesian government budget Excel files (Sakti FA)

Package Exports

  • sakti-parser-fa

Readme

sakti-parser-fa

Simple TypeScript library for parsing Indonesian government budget Excel files (Sakti FA format).

npm version TypeScript License: MIT

✨ Features

  • 🌐 Universal - Works seamlessly in Node.js and browsers
  • 🎯 Simple API - Just pass ExcelJS worksheet data
  • 📝 TypeScript - Full type definitions included
  • 📊 Multiple formats - JSON and CSV output
  • 🚀 Zero platform deps - No file system dependencies
  • 🔧 Lightweight - Single purpose, minimal footprint

📦 Installation

npm install sakti-parser-fa exceljs

🚀 Quick Start

Node.js

import ExcelJS from 'exceljs';
import { SaktiParser, SaktiFormatter } from 'sakti-parser-fa';

// Read Excel file
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile('budget.xlsx');
const worksheet = workbook.getWorksheet(1);

// Parse data
const parser = new SaktiParser();
const result = await parser.parse(worksheet);

// Format output
const formatter = new SaktiFormatter();
const json = formatter.format(result, { format: 'json' });
const csv = formatter.format(result, { format: 'csv' });

console.log('Metadata:', result.metadata);
console.log('Data rows:', result.data.length);

Browser (React/Vue/Vanilla)

import ExcelJS from 'exceljs';
import { SaktiParser, SaktiFormatter } from 'sakti-parser-fa';

async function parseExcelFile(file: File) {
  // Read file
  const arrayBuffer = await file.arrayBuffer();
  const workbook = new ExcelJS.Workbook();
  await workbook.xlsx.load(arrayBuffer);
  const worksheet = workbook.getWorksheet(1);
  
  // Parse and format
  const parser = new SaktiParser();
  const result = await parser.parse(worksheet);
  
  const formatter = new SaktiFormatter();
  return formatter.format(result, { format: 'json' });
}

// React example
function FileUpload() {
  const handleFile = async (e) => {
    const file = e.target.files[0];
    const parsed = await parseExcelFile(file);
    console.log(JSON.parse(parsed));
  };
  
  return <input type="file" accept=".xlsx" onChange={handleFile} />;
}

📋 Complete Example

import ExcelJS from 'exceljs';
import { SaktiParser, SaktiFormatter, type ParseResult } from 'sakti-parser-fa';

async function processBudget(filePath: string) {
  try {
    // 1. Load Excel file
    const workbook = new ExcelJS.Workbook();
    await workbook.xlsx.readFile(filePath);
    const worksheet = workbook.getWorksheet(1);

    // 2. Parse SAKTI data
    const parser = new SaktiParser();
    const result: ParseResult = await parser.parse(worksheet);

    // 3. Access parsed data
    console.log('Ministry:', result.metadata.kementerian_nama);
    console.log('Period:', result.metadata.periode_text);
    console.log('Budget items:', result.data.length);

    // 4. Export as needed
    const formatter = new SaktiFormatter();
    
    // JSON with metadata
    const json = formatter.format(result, { 
      format: 'json', 
      includeMetadata: true 
    });
    
    // CSV without metadata  
    const csv = formatter.format(result, { 
      format: 'csv', 
      includeMetadata: false 
    });

    return { json, csv, result };
  } catch (error) {
    console.error('Failed to process budget file:', error);
    throw error;
  }
}

📚 API Reference

SaktiParser

Main parser class for processing SAKTI Excel worksheets.

class SaktiParser {
  async parse(worksheet: Worksheet): Promise<ParseResult>
}

Parameters:

  • worksheet - ExcelJS Worksheet object

Returns: Promise resolving to ParseResult

SaktiFormatter

Formats parse results into different output formats.

class SaktiFormatter {
  format(result: ParseResult, options?: FormatOptions): string
}

interface FormatOptions {
  format?: 'json' | 'csv';          // Output format (default: 'json')
  includeMetadata?: boolean;        // Include metadata (default: true)
}

📊 Data Structure

ParseResult

interface ParseResult {
  metadata: Metadata;       // Document metadata
  data: ParsedData[];      // Parsed budget data
}

Metadata

interface Metadata {
  judul: string;                    // Document title
  periode_text: string;             // Period text (e.g., "Januari 2024")
  periode_bulan: number;            // Month number (1-12)
  periode_tahun: number;            // Year
  kementerian_kode: string;         // Ministry code
  kementerian_nama: string;         // Ministry name
  unit_kode: string;                // Unit code
  unit_nama: string;                // Unit name
  satuan_kerja_kode: string;        // Work unit code
  satuan_kerja_nama: string;        // Work unit name
}

ParsedData

Hierarchical budget data with up to 11 levels:

interface ParsedData {
  _level: number;                   // Current level (1-11)
  _parent: string;                  // Parent reference
  mata_anggaran: string;            // Budget type
  
  // Level 1-11 codes and descriptions
  level_1_kode: string;
  level_1_uraian: string;
  level_2_kode: string;
  level_2_uraian: string;
  // ... up to level_11_kode, level_11_uraian
  
  nilai_rupiah: number;             // Amount in rupiah
  nilai_total: number;              // Total amount
}

🛠️ Development

# Clone repository
git clone https://github.com/username/sakti-parser-fa.git
cd sakti-parser-fa

# Install dependencies
npm install

# Build
npm run build

# Test
npm test

# Development mode
npm run dev

📝 Requirements

  • Node.js 18+
  • ExcelJS 4.x (peer dependency)

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

MIT License - see the LICENSE file for details.

🙋‍♂️ Support


Made with ❤️ for Indonesian government budget transparency