This repository was archived by the owner on Aug 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +68
-115
lines changed
Expand file tree Collapse file tree 6 files changed +68
-115
lines changed Original file line number Diff line number Diff line change @@ -3,5 +3,7 @@ const through = require('through2')
33const stream = require ( './' )
44
55const req = request . get ( 'http://localhost:8000/file.xlsx' )
6+ . buffer ( false )
67 . pipe ( stream ( ) )
7- . on ( 'data' , ( d ) => console . log ( String ( d ) ) )
8+ . on ( 'data' , ( d ) => console . log ( String ( d ) , 'line' ) )
9+ . on ( 'end' , console . log )
Original file line number Diff line number Diff line change @@ -12,17 +12,19 @@ module.exports = () => {
1212 . then ( ( worksheet ) => {
1313 workbook . eachSheet ( ( sheet , id ) => {
1414 sheet . eachRow ( ( row , id ) => {
15- if ( id === 1 ) {
15+ if ( id === 1 || ! headers ) {
1616 headers = row . values
1717 return
1818 }
1919 let item = { }
2020 row . values . forEach ( ( v , k ) => {
21+ if ( ! headers ) return
2122 item [ headers [ k ] ] = v
2223 } )
2324 second . push ( JSON . stringify ( item ) )
2425 } )
2526 } )
27+ second . emit ( 'end' )
2628 } )
2729 return duplex . obj ( input , second )
2830}
Original file line number Diff line number Diff line change 11{
2+ "name" : " exceljs-transform-stream" ,
3+ "description" : " Parse XLSX files as a through stream to exceljs" ,
4+ "main" : " index.js" ,
5+ "repository" : {
6+ "type" : " git" ,
7+ "url" : " git+https://github.com/stevelacy/exceljs-transform-stream.git"
8+ },
9+ "scripts" : {
10+ "test" : " mocha test/"
11+ },
12+ "author" :
" Steve Lacy <[email protected] > (http://slacy.me)" ,
13+ "license" : " MIT" ,
14+ "bugs" : {
15+ "url" : " https://github.com/stevelacy/exceljs-transform-stream/issues"
16+ },
17+ "homepage" : " https://github.com/stevelacy/exceljs-transform-stream#readme" ,
218 "dependencies" : {
3- "duplexer " : " ^0.1.1 " ,
19+ "duplexify " : " ^3.5.0 " ,
420 "exceljs" : " ^0.2.41" ,
5- "sheetjs" : " ^1.0.21" ,
6- "through2" : " ^2.0.3" ,
7- "unzip" : " ^0.1.11" ,
8- "xlsx" : " ^0.8.2" ,
9- "xml-stream" : " ^0.4.5"
21+ "through2" : " ^2.0.3"
1022 },
1123 "devDependencies" : {
12- "superagent" : " ^3.4.1"
13- }
24+ "mocha" : " ^3.2.0" ,
25+ "should" : " ^11.2.0"
26+ },
27+ "keywords" : [
28+ " stream" ,
29+ " xlsx" ,
30+ " exceljs" ,
31+ " transform" ,
32+ " convert"
33+ ]
1434}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' )
2+ const should = require ( 'should' )
3+ const stream = require ( 'stream' )
4+ const exs = require ( '..' )
5+
6+ describe ( 'exceljs-through-stream' , ( ) => {
7+ it ( 'should export a function' , ( done ) => {
8+ should ( typeof exs ) . equal ( 'function' )
9+ done ( )
10+ } )
11+ it ( 'should export a function that returns a stream' , ( done ) => {
12+ should ( exs ( ) instanceof stream )
13+ done ( )
14+ } )
15+ it ( 'parse xlsx files' , ( done ) => {
16+ const file = fs . createReadStream ( __dirname + '/file.xlsx' )
17+ const res = [ ]
18+ file . pipe ( exs ( ) )
19+ . on ( 'data' , ( d ) => {
20+ res . push ( JSON . parse ( String ( d ) ) )
21+ } )
22+ . on ( 'end' , ( ) => {
23+ should ( res . length ) . equal ( 4 )
24+ should ( JSON . stringify ( res [ 0 ] ) ) . equal (
25+ JSON . stringify ( {
26+ row : 'row1' ,
27+ date : '2017-02-08T00:00:00.000Z' ,
28+ cost : 100 ,
29+ notes : 111
30+ } ) )
31+ done ( )
32+ } )
33+ } )
34+ } )
You can’t perform that action at this time.
0 commit comments