A lightweight parser for DBF (dBase/Visual FoxPro) files with memo support
npm install dbfreadA lightweight parser for DBF (dBase/Visual FoxPro) files with memo support, written in TypeScript.
- ๐ 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
``bash`
npm install dbfread
`typescript
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 }
`
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
| 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 |
`typescript
import { parseDBF } from 'dbfread';
const records = parseDBF('./data/employees.dbf');
records.forEach(record => {
console.log(${record.name}: ${record.salary});`
});
`typescript
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');
`
`typescript
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
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()});`
});
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
`bashInstall dependencies
npm install
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
๐ฆ GitHub: https://github.com/richardhristov/dbfread