txt-file-to-json
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "txt-file-to-json", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Reads a txt file having a table and returns an array of obects. In which each object consists of all headers as keys and there data as values.", | ||
"main": "txt_to_json.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "nyc --reporter=text mocha" | ||
}, | ||
@@ -30,3 +30,7 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/vprince001/txt_to_json#readme" | ||
"homepage": "https://github.com/vprince001/txt_to_json#readme", | ||
"dependencies": { | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.1" | ||
} | ||
} |
const fs = require("fs"); | ||
const { CR, NL, WS, ES, FORMAT } = require("./constants.js"); | ||
const { addEndPoint, getObject } = require("./lib.js"); | ||
@@ -11,13 +12,14 @@ const getHeadersAndStartPoints = function(data) { | ||
line.forEach((char, index) => { | ||
const charIsSpace = char == WS; | ||
const nextCharIsNotSpace = line[index + 1] != WS; | ||
const charIsNotSpace = char != WS; | ||
const charIsNotCR = char != CR; | ||
const charIsCR = char == CR; | ||
const previousCharIsNOtSpace = line[index - 1] != WS; | ||
const isNotSpace = char != WS; | ||
const isNotCR = char != CR; | ||
const isSpace = char == WS; | ||
const nextIsNotSpace = line[index + 1] != WS; | ||
const isCR = char == CR; | ||
const isPreviousNOtSpace = line[index - 1] != WS; | ||
if (charIsNotSpace && charIsNotCR) { | ||
if (isNotSpace && isNotCR) { | ||
return (header += char); | ||
} | ||
if (charIsSpace && nextCharIsNotSpace) { | ||
if (isSpace && nextIsNotSpace) { | ||
startPoints.push(index + 1); | ||
@@ -27,3 +29,4 @@ headers.push(header); | ||
} | ||
if (charIsCR && previousCharIsNOtSpace) { | ||
if (isCR && isPreviousNOtSpace) { | ||
headers.push(header); | ||
@@ -37,10 +40,2 @@ header = ES; | ||
const addEndPoint = function(data) { | ||
const lengths = []; | ||
data.forEach(line => { | ||
lengths.push(line.length); | ||
}); | ||
return Math.max(...lengths); | ||
}; | ||
const formatDataInArray = function(data, startPoints, headers) { | ||
@@ -51,9 +46,3 @@ let finalResult = []; | ||
data.forEach(line => { | ||
let obj = headers.reduce(function(acc, currentElement, index) { | ||
acc[currentElement] = line | ||
.substring(startPoints[index], startPoints[index + 1]) | ||
.trim(); | ||
return acc; | ||
}, {}); | ||
finalResult.push(obj); | ||
finalResult.push(getObject(line, headers, startPoints)); | ||
}); | ||
@@ -60,0 +49,0 @@ return finalResult; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
7860
7
115
0
2
+ Addedmocha@^6.1.4
+ Addednyc@^14.1.1
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedansi-colors@3.2.3(transitive)
+ Addedansi-regex@3.0.14.1.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedappend-transform@1.0.0(transitive)
+ Addedarchy@1.0.0(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarray.prototype.reduce@1.0.7(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbrowser-stdout@1.3.1(transitive)
+ Addedcaching-transform@3.0.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcliui@5.0.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcommondir@1.0.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcp-file@6.2.0(transitive)
+ Addedcross-spawn@4.0.2(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddebug@3.2.64.3.7(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddefault-require-extensions@2.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddiff@3.5.0(transitive)
+ Addedemoji-regex@7.0.3(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedes-abstract@1.23.5(transitive)
+ Addedes-array-method-boxes-properly@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedes6-error@4.1.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfind-cache-dir@2.1.0(transitive)
+ Addedfind-up@3.0.0(transitive)
+ Addedflat@4.1.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedforeground-child@1.5.6(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglob@7.1.3(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedgrowl@1.10.5(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasha@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhe@1.2.0(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedhtml-escaper@2.0.2(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-async-function@2.0.0(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-finalizationregistry@1.0.2(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-map@2.0.3(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-set@2.0.3(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakmap@2.0.2(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedis-weakset@2.0.3(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedistanbul-lib-coverage@2.0.5(transitive)
+ Addedistanbul-lib-hook@2.0.7(transitive)
+ Addedistanbul-lib-instrument@3.3.0(transitive)
+ Addedistanbul-lib-report@2.0.8(transitive)
+ Addedistanbul-lib-source-maps@3.0.6(transitive)
+ Addedistanbul-reports@2.2.7(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@3.13.1(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.flattendeep@4.4.0(transitive)
+ Addedlog-symbols@2.2.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmake-dir@2.1.0(transitive)
+ Addedmerge-source-map@1.1.0(transitive)
+ Addedminimatch@3.0.4(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.4(transitive)
+ Addedmocha@6.2.3(transitive)
+ Addedms@2.1.12.1.3(transitive)
+ Addednested-error-stacks@2.1.1(transitive)
+ Addednode-environment-flags@1.0.5(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addednyc@14.1.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.04.1.5(transitive)
+ Addedobject.getownpropertydescriptors@2.1.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpackage-hash@3.0.0(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpify@3.0.04.0.1(transitive)
+ Addedpkg-dir@3.0.0(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@4.0.0(transitive)
+ Addedreflect.getprototypeof@1.0.6(transitive)
+ Addedregexp.prototype.flags@1.5.3(transitive)
+ Addedrelease-zalgo@1.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedsemver@5.7.26.3.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedspawn-wrap@1.4.3(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstring-width@2.1.13.1.0(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedstrip-ansi@4.0.05.2.0(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedsupports-color@5.5.06.0.06.1.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtest-exclude@5.2.3(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.3(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-builtin-type@1.1.4(transitive)
+ Addedwhich-collection@1.0.2(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedwide-align@1.1.3(transitive)
+ Addedwrap-ansi@5.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedwrite-file-atomic@2.4.3(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyallist@2.1.2(transitive)
+ Addedyargs@13.3.2(transitive)
+ Addedyargs-parser@13.1.2(transitive)
+ Addedyargs-unparser@1.6.0(transitive)