dbfread
v1.0.0
Published
A lightweight parser for DBF (dBase/Visual FoxPro) files with memo support
Maintainers
Readme
dbfread
A lightweight parser for DBF (dBase/Visual FoxPro) files with memo support, written in TypeScript.
Features
- 🚀 Lightweight: No external dependencies, pure TypeScript/JavaScript
- 📄 Memo Support: Automatically detects and parses associated .fpt memo files
- 🔧 TypeScript: Full TypeScript support with type definitions
- 📊 Multiple Data Types: Supports all common DBF field types
- 🎯 Simple API: Easy-to-use function with minimal configuration
- 🧪 Well Tested: Comprehensive test suite
Installation
npm install dbfreadQuick Start
import { parseDBF } from 'dbfread';
// Parse a DBF file
const records = parseDBF('./path/to/your/file.dbf');
// Each record is a plain object with field names as keys
console.log(records[0]);
// Output: { id: 1, name: "John Doe", age: 30, active: true }API Reference
parseDBF(dbfPath: string, encoding?: string): Record<string, any>[]
Parses a DBF file and returns an array of records.
Parameters:
dbfPath(string): Path to the .dbf fileencoding(optional string): Text encoding (defaults to Windows-1252)
Returns:
- Array of record objects where keys are field names
Supported Field Types
| Type | Description | JavaScript Type |
|------|-------------|-----------------|
| C | Character/String | string |
| N | Numeric | number |
| F | Float | number |
| D | Date | Date |
| L | Logical/Boolean | boolean |
| M | Memo | string |
| I | Integer | number |
| B | Binary/Double | number |
| Y | Currency | number |
| T | DateTime | Date |
| O | Double | number |
Examples
Basic Usage
import { parseDBF } from 'dbfread';
const records = parseDBF('./data/employees.dbf');
records.forEach(record => {
console.log(`${record.name}: ${record.salary}`);
});With Custom Encoding
import { parseDBF } from 'dbfread';
// Use UTF-8 encoding
const records = parseDBF('./data/employees.dbf', 'utf-8');
// Use Windows-1251 encoding
const records = parseDBF('./data/employees.dbf', 'windows-1251');Working with Memo Fields
import { parseDBF } from 'dbfread';
const records = parseDBF('./data/employees.dbf');
// Memo fields are automatically parsed if .fpt file exists
records.forEach(record => {
if (record.notes) {
console.log(`Notes for ${record.name}: ${record.notes}`);
}
});TypeScript Usage
import { parseDBF } from 'dbfread';
interface Employee {
id: number;
name: string;
salary: number;
hireDate: Date;
active: boolean;
notes?: string;
}
const records = parseDBF('./data/employees.dbf') as Employee[];
records.forEach((employee: Employee) => {
console.log(`${employee.name} was hired on ${employee.hireDate.toLocaleDateString()}`);
});File Format Support
This library supports:
- dBase III+ (.dbf files)
- Visual FoxPro (.dbf files)
- Memo files (.fpt files) - automatically detected and parsed
- Various encodings - with fallback to Windows-1252
Development
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Build the project
npm run buildLicense
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
