flat-file-parser
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -1,1 +0,1 @@ | ||
"use strict";const LineParser=function(e,n,r){let t,i,o,s,c={};return c.process=(e,n,r,s)=>i>0&&t++>=i?null:{data:o.call(s,e,n,r,s),completed:i>0&&t>=i},c.callback=(e,n,r)=>{if(s)return s.call(r,e,n,r)},((e,n,r)=>{if(c[Symbol.toStringTag]="LineParser",t=0,"function"!=typeof e)throw"lineProcessor is a function parameter. definition: function lineProcessor<Any>(line: String, currentProcessIndex: Int, lineNumber: Int): <Any>";return o=e,i=isNaN(n)?0:n>=0?n:0,r&&"function"==typeof r&&(s=r),c})(e,n,r)};module.exports={LineParser}; | ||
"use strict";const LineParser=function(e,n,r){let t,i,o,s,c={};return c.process=(e,n,r,s)=>i>0&&t++>=i?null:{data:o.call(n,e,n,r,s),completed:i>0&&t>=i},c.callback=(e,n,r,t,i)=>{if(s)return s.call(r,e,n,r,t,i)},((e,n,r)=>{if(c[Symbol.toStringTag]="LineParser",t=0,"function"!=typeof e)throw"lineProcessor is a function parameter. definition: function lineProcessor<Any>(line: String, currentProcessIndex: Int, lineNumber: Int): <Any>";return o=e,i=isNaN(n)?0:n>=0?n:0,r&&"function"==typeof r&&(s=r),c})(e,n,r)};module.exports={LineParser}; |
@@ -1,1 +0,1 @@ | ||
"use strict";const fs=require("fs"),readline=require("readline"),{once}=require("events"),{LineParser}=require("./lineParser"),FlatFileParser=function(){let e={},r=null,l=!1,n=[];const _ensureOpened=()=>{if(!l||null==r)throw"No file has been opened for parsing. Please use open() before using it"};return e.open=n=>(r=fs.createReadStream(n),l=!0,e),e.next=(r,l,s)=>(_ensureOpened(),n.push(LineParser(r,l,s)),e),e.process=async()=>{_ensureOpened();try{let l=0,s=0;const t=readline.createInterface({input:r});t.on("line",((r,a)=>{if(n.length>s){const t=n[s],a=t.process(r,s,l,e);a.completed&&s++;t.callback(a.data,r,e)}else t.close();l++})).on("close",(()=>{e.done(),t.removeAllListeners()})),await once(t,"close")}catch(e){console.error(e)}return e},e.done=()=>(null!=r&&r.destroy(),r=null,l=!1,n.splice(0),e),e[Symbol.toStringTag]="FlatFileParser",e};module.exports={FlatFileParser,flatFileParser:FlatFileParser()}; | ||
"use strict";const fs=require("fs"),readline=require("readline"),{once}=require("events"),{LineParser}=require("./lineParser"),FlatFileParser=function(){let e={},r=null,l=!1,n=!1,s=0,a=0,t=[];const _ensureOpened=()=>{if(!l||null==r)throw"No file has been opened for parsing. Please use open() before using it"};return e.open=n=>(r=fs.createReadStream(n),l=!0,e),e.next=(r,l,o)=>(_ensureOpened(),n?t.splice(++a+s,0,LineParser(r,l,o)):t.push(LineParser(r,l,o)),e),e.process=async()=>{_ensureOpened(),n=!0;try{let l=0;const n=readline.createInterface({input:r});n.on("line",((r,o)=>{if(t.length>s){const n=t[s],o=n.process(r,e,s,l);n.callback(o.data,r,e,s,l);o.completed&&(a=0,s++)}else n.close();l++})).on("close",(()=>{e.done(),n.removeAllListeners()})),await once(n,"close")}catch(e){console.error(e)}return e},e.done=()=>(null!=r&&r.destroy(),r=null,l=!1,t.splice(0),s=0,a=0,n=!1,e),e[Symbol.toStringTag]="FlatFileParser",e};module.exports={FlatFileParser,flatFileParser:FlatFileParser()}; |
{ | ||
"name": "flat-file-parser", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "some Flat File Parser", | ||
@@ -23,2 +23,3 @@ "main": "index.js", | ||
"chai": "^4.3.4", | ||
"chai-as-promised": "^7.1.1", | ||
"custom-exception": "^0.1.2", | ||
@@ -25,0 +26,0 @@ "del": "^6.0.0", |
3235
8