npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dbffile-expanded

v0.0.1

Published

### Summary

Downloads

21

Readme

DBFFile

Summary

Read and write .dbf (dBase III) files in Node.js:

  • Supports C (string) , N (numeric) , F (float) , I (integer) , L (logical) and D (date) field types
  • Can open an existing .dbf file
    • Can access all field descriptors
    • Can access total record count
    • Can read records in arbitrary-sized batches
    • Supports very large files
  • Can create a new .dbf file
    • Can use field descriptors from a hash of from another instance
  • Can append records to an existing .dbf file
    • Supports very large files
  • All operations are asyncronous and return a promise

Installation

npm install dbffile-expanded

Example: reading a .dbf file

var DBFFile = require('dbffile-expanded');

DBFFile.open('[full path to .dbf file]')
    .then(dbf => {
        console.log(`DBF file contains ${dbf.recordCount} rows.`);
        console.log(`Field names: ${dbf.fields.map(f => f.name)}`);
        return dbf.readRecords(100);
    })
    .then(rows => rows.forEach(row => console.log(row)))
    .catch(err => console.log('An error occurred: ' + err));

Example: writing a .dbf file

var DBFFile = require('dbffile-expanded');

var fieldDescriptors = [
    { name: 'fname', type: 'C', size: 255 },
    { name: 'lname', type: 'C', size: 255 }
];

var rows = [
    { fname: 'Joe', lname: 'Bloggs' },
    { fname: 'Mary', lname: 'Smith' }
];

DBFFile.create('[full path to .dbf file]', fieldDescriptors)
    .then(dbf => {
        console.log('DBF file created.');
        return dbf.append(rows);
    })
    .then(() => console.log(rows.length + ' rows added.'))
    .catch(err => console.log('An error occurred: ' + err));

API

The module exports two functions and a class, as follows:


/** Open an existing DBF file. */
function open(path: string): Promise<DBFFile>;


/** Create a new DBF file with no records. */
function create(path: string, fields: Field[]): Promise<DBFFile>;


/** Represents a DBF file. */
class DBFFile {

    /** Full path to the DBF file. */
    path: string;

    /** Total number of records in the DBF file (NB: includes deleted records). */
    recordCount: number;

    /** Metadata for all fields defined in the DBF file. */
    fields: { name: string; type: string; size: number; decs: number; }[];

    /** Append the specified records to this DBF file. */
    append(records: any[]): Promise<DBFFile>;

    /** read some specific rows from the dbf file. **/
    readRecords(maxRows?: number): Promise<any[]>;
}