Skip to content

Commit 12fb719

Browse files
Converted the library from CoffeeScript to ES6
1 parent be7ca61 commit 12fb719

File tree

11 files changed

+2816
-220
lines changed

11 files changed

+2816
-220
lines changed

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
language: node_js
22
node_js:
3-
- "6"
4-
- "6.1"
5-
- "6.0"
6-
- "5"
7-
- "5.1"
8-
- "4"
9-
- "0.12"
10-
- "0.11"
113
- "node"
4+
- "lts/*"
5+
- "9"
6+
- "8"
7+
- "7"

Cakefile

Lines changed: 0 additions & 16 deletions
This file was deleted.

README.md

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
node-dbf
2-
========
1+
DBF Parser
2+
==========
33

44
This is an event-based dBase file parser for very efficiently reading data from `*.dbf` files.
55

@@ -8,25 +8,29 @@ This is an event-based dBase file parser for very efficiently reading data from
88
[![NPM Version][npm-image]][npm-url]
99
[![NPM Downloads][downloads-image]][downloads-url]
1010

11-
The codebase is written in CoffeeScript but compiled in the npm module so CoffeeScript is not a dependency in production.
11+
The codebase is written in ES6 JavaScript but compiled in the npm module to pure JavaScript.
1212

1313
To get started, simply install the module using npm:
1414

15-
npm install node-dbf
15+
```bash
16+
$ npm install node-dbf
17+
```
1618

17-
and then `require` it:
19+
and then `import` it:
1820

19-
var Parser = require('node-dbf');
21+
```js
22+
import Parser from 'node-dbf';
23+
```
2024

21-
#Classes
25+
# Classes
2226

2327
There are two classes - the `Parser` and the `Header`. The `Parser` is the most interesting class.
2428

25-
##Parser
29+
## Parser
2630

2731
This class is the main interface for reading data from dBase files. It extends `EventEmitter` and its output is via events.
2832

29-
###new Parser(path, options)
33+
### new Parser(path, options)
3034

3135
* path `String` The full path to the DBF file to parse
3236
* options `Object` An object containing options for the parser.
@@ -37,36 +41,36 @@ The support options are:
3741

3842
Creates a new Parser and attaches it to the specified filename.
3943

40-
var Parser = require('node-dbf');
44+
import Parser from 'node-dbf';
4145

42-
var parser = new Parser('/path/to/my/dbase/file.dbf');
46+
let parser = new Parser('/path/to/my/dbase/file.dbf');
4347

44-
###parser.on(event, listener)
48+
### parser.on(event, listener)
4549

4650
* event `String` The event name to listen for (see below for details)
4751
* listener `Function` The callback to bind to the event
4852

4953
This method is inherited from the `EventEmitter` class.
5054

51-
###parser.parse()
55+
### parser.parse()
5256

5357
Call this method once you have bound to the events you are interested in. Although it returns the parser object (for chaining), all the dBase data is outputted via events.
5458

5559
parser.parse();
5660

57-
###Event: 'start'
61+
### Event: 'start'
5862

5963
* parser `Parser` The parser object
6064

6165
This event is emitted as soon as the `parser.parse()` method has been invoked.
6266

63-
###Event: 'header'
67+
### Event: 'header'
6468

6569
* header `Header` The header object as parsed from the dBase file
6670

6771
This event is emitted once the header has been parsed from the dBase file
6872

69-
###Event: 'record'
73+
### Event: 'record'
7074

7175
* record `Object` An object representing the record that has been found
7276

@@ -78,65 +82,74 @@ In addition to the fields, the object contains two special keys:
7882
* @deleted `Boolean` whether this record has been deleted or not
7983

8084
This object may look like:
85+
```json
86+
{
87+
"@sequenceNumber": 123,
88+
"@deleted": false,
89+
"firstName": "John",
90+
"lastName": "Smith"
91+
}
92+
```
8193

82-
{
83-
"@sequenceNumber": 123,
84-
"@deleted": false,
85-
"firstName": "John",
86-
"lastName": "Smith
87-
}
88-
89-
###Event: 'end'
94+
### Event: 'end'
9095

9196
* parser `Parser` The parser object
9297

9398
This event is fired once the dBase parsing is complete and there are no more records remaining.
9499

95-
##Usage
100+
## Usage
96101

97102
The following code example illustrates a very simple usage for this module:
98103

99-
var Parser = require('node-dbf');
100-
101-
var parser = new Parser('/path/to/my/dbase/file.dbf');
102-
103-
parser.on('start', function(p) {
104-
console.log('dBase file parsing has started');
105-
});
106-
107-
parser.on('header', function(h) {
108-
console.log('dBase file header has been parsed');
109-
});
110-
111-
parser.on('record', function(record) {
112-
console.log('Name: ' + record.firstName + ' ' + record.lastName); // Name: John Smith
113-
});
114-
115-
parser.on('end', function(p) {
116-
console.log('Finished parsing the dBase file');
117-
});
118-
119-
parser.parse();
104+
```js
105+
import Parser from 'node-dbf';
106+
107+
let parser = new Parser('/path/to/my/dbase/file.dbf');
108+
109+
parser.on('start', (p) => {
110+
console.log('dBase file parsing has started');
111+
});
112+
113+
parser.on('header', (h) => {
114+
console.log('dBase file header has been parsed');
115+
});
116+
117+
parser.on('record', (record) => {
118+
console.log('Name: ' + record.firstName + ' ' + record.lastName); // Name: John Smith
119+
});
120+
121+
parser.on('end', (p) => {
122+
console.log('Finished parsing the dBase file');
123+
});
124+
125+
parser.parse();
126+
```
120127

121-
#Command-Line Interface (CLI)
128+
# Command-Line Interface (CLI)
122129

123130
The parser also supports a command-line interface (CLI) for converting DBF files to CSV. You can invoke it as follows:
124131

125-
$ node-dbf convert /path/to/file.dbf
132+
```bash
133+
$ node-dbf convert /path/to/file.dbf
134+
```
126135

127136
This will write the converted rows to `stdout` and metadata about the process (e.g. number of rows, etc) to `stderr`. This allows you to write stdout directly to an output file, for example:
128137

129-
$ node-dbf convert file.dbf > file.csv
138+
```bash
139+
$ node-dbf convert file.dbf > file.csv
140+
```
130141

131142
For more help information on using the command line options, use the integrated help:
132143

133-
$ node-dbf help
144+
```bash
145+
$ node-dbf help
146+
```
134147

135-
#Tests
148+
# Tests
136149

137150
Tests are written in Mocha using Chai BDD for the expectations. Data on San Francisco zip codes was used as a reference test file - downloaded from [SF OpenData](https://data.sfgov.org/) and included in the `./test/fixtures/bayarea_zipcodes.dbf` file within the repository.
138151

139-
#TODO
152+
# To Do
140153

141154
* Add more tests
142155
* Add support for field types other than Character and Numeric

bin/node-dbf-convert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var wrap = function(t) {
2323
return [quote, t, quote].join('');
2424
};
2525

26-
var Parser = require('../lib/parser.js');
26+
var Parser = require('../lib/parser').default;
2727
var fields;
2828

2929
var timeStart = process.hrtime();

0 commit comments

Comments
 (0)