New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flat-file-parser

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat-file-parser - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

5

index.js

@@ -1,4 +0,1 @@

/**
* flat-file-parser: some Flat File Parser
*/
module.exports = require('./lib/main');
module.exports=require("./lib/main");

52

lib/lineParser.js

@@ -1,51 +0,1 @@

'use strict';
const LineParser = function (lineProcessor, threshold, processedCallback) {
let _th = {};
let _counter;
let _threshold;
let _lineProcessor;
let _processedCallback;
let _done = false;
const _init = (lineProcessor, threshold, processedCallback) => {
_th[Symbol.toStringTag] = 'LineParser';
_counter = 0;
if (typeof lineProcessor === 'function') _lineProcessor = lineProcessor;
else
throw 'lineProcessor is a function parameter. definition: function lineProcessor<Any>(line: String, currentProcessIndex: Int, lineNumber: Int): <Any>';
_threshold = isNaN(threshold) ? 0 : threshold >= 0 ? threshold : 0;
if (processedCallback && typeof processedCallback === 'function')
_processedCallback = processedCallback;
return _th;
};
_th.process = (line, currentProcessIndex, lineNumber, originalParser) => {
if (_threshold > 0 && _counter++ >= _threshold) return null;
return {
data: _lineProcessor.call(
originalParser,
line,
currentProcessIndex,
lineNumber,
originalParser
),
completed: _threshold > 0 && _counter >= _threshold,
};
};
_th.callback = (processedLineData, line, originalParser) => {
if (_processedCallback)
return _processedCallback.call(
originalParser,
processedLineData,
line,
originalParser
);
};
return _init(lineProcessor, threshold, processedCallback);
};
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(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};

@@ -1,85 +0,1 @@

'use strict';
const fs = require('fs');
const readline = require('readline');
const { once } = require('events');
const { LineParser } = require('./lineParser');
const FlatFileParser = function () {
let _th = {};
let _stream = null;
let _isOpen = false;
let _lineParsers = [];
const _ensureOpened = () => {
if (!_isOpen || null == _stream)
throw 'No file has been opened for parsing. Please use open() before using it';
};
const _init = () => {
_th[Symbol.toStringTag] = 'FlatFileParser';
return _th;
};
_th.open = (filePath) => {
_stream = fs.createReadStream(filePath);
_isOpen = true;
return _th;
};
_th.next = (lineProcessor, threshold, processedCallback) => {
_ensureOpened();
_lineParsers.push(LineParser(lineProcessor, threshold, processedCallback));
return _th;
};
_th.process = async () => {
_ensureOpened();
try {
let _linePointer = 0;
let _processPointer = 0;
const reader = readline.createInterface({ input: _stream });
reader
.on('line', (line, index) => {
//console.info(line);
if (_lineParsers.length > _processPointer) {
const _currentParser = _lineParsers[_processPointer];
const result = _currentParser.process(
line,
_processPointer,
_linePointer,
_th
);
if (result.completed) _processPointer++;
const postResult = _currentParser.callback(result.data, line, _th);
} else {
reader.close();
}
_linePointer++;
})
.on('close', () => {
_th.done();
reader.removeAllListeners();
});
await once(reader, 'close');
} catch (_) {
console.error(_);
}
return _th;
};
_th.done = () => {
if (null != _stream) _stream.destroy();
_stream = null;
_isOpen = false;
_lineParsers.splice(0);
return _th;
};
return _init();
};
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=[];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()};
{
"name": "flat-file-parser",
"version": "0.1.0",
"version": "0.2.0",
"description": "some Flat File Parser",

@@ -23,4 +23,9 @@ "main": "index.js",

"chai": "^4.3.4",
"mocha": "^9.1.3"
"custom-exception": "^0.1.2",
"del": "^6.0.0",
"gulp": "^4.0.2",
"gulp-terser": "^2.1.0",
"mocha": "^9.1.3",
"readable-stream": "^3.6.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc