Skip to content

Commit

Permalink
Add CSV support and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhuko committed Nov 9, 2015
1 parent d6f93a7 commit 451b47f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ A text extraction node module.
* ODG, OTG
* PNG, JPG, GIF
* DXF
* `application/csv`
* `application/javascript`
* All `text/*` mime-types.

Expand Down
2 changes: 1 addition & 1 deletion lib/extractors/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ var extractText = function( filePath, options, cb ) {
};

module.exports = {
types: [/text\//, "application/javascript"],
types: [/text\//, "application/csv", "application/javascript"],
extract: extractText
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"textract",
"extract",
"html",
"csv",
"text",
"pdf",
"docx",
Expand Down
30 changes: 30 additions & 0 deletions test/extract_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ var path = require('path');

describe('textract', function() {

describe('for .csv files ', function() {

// is some oddness testing html files, not sure what the deal is

it('from csv files', function(done) {
var docPath = path.join( __dirname, "files", "csv.csv" );
fromFileWithPath(docPath, function( error, text ) {
expect(error).to.be.null;
expect(text).to.be.an('string');
expect(text.length).to.eql( 18 );
expect(text.substring(0, 80)).to.eql("Foo,Bar Foo2,Bar2 ")
done();
});
});

it('it will extract text from csv files and insert newlines in the right places', function(done) {
var docPath = path.join( __dirname, "files", "csv.csv" );
fromFileWithPath(docPath, {preserveLineBreaks:true}, function( error, text ) {
expect(error).to.be.null;
expect(text).to.be.an('string');
expect(text.length).to.eql( 18 );
expect(text.substring(0, 80)).to.eql("Foo,Bar\nFoo2,Bar2\n")
done();
});
});



});

describe('for .html files', function() {

// is some oddness testing html files, not sure what the deal is
Expand Down

0 comments on commit 451b47f

Please sign in to comment.