From 2544e44be1d9c0c18399b6e300dfc47c2a83e479 Mon Sep 17 00:00:00 2001 From: Greg Yachuk Date: Wed, 22 Jul 2020 16:27:14 -0700 Subject: [PATCH] Return FieldValue in FDF data. --- index.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 1b278b3..c6a08dc 100644 --- a/index.js +++ b/index.js @@ -49,9 +49,10 @@ }, generateFieldJson: function( sourceFile, nameRegex, callback){ - var regName = /FieldName: ([^\n]*)/, - regType = /FieldType: ([A-Za-z\t .]+)/, - regFlags = /FieldFlags: ([0-9\t .]+)/, + var regName = /^FieldName: /, + regType = /^FieldType: /, + regFlags = /^FieldFlags: /, + regValue = /^FieldValue: /, fieldArray = [], currField = {}; @@ -63,28 +64,28 @@ return callback(error, null); } - fields = stdout.toString().split("---").slice(1); - fields.forEach(function(field){ - currField = {}; - - currField['title'] = field.match(regName)[1].trim() || ''; - - if(field.match(regType)){ - currField['fieldType'] = field.match(regType)[1].trim() || ''; - }else { - currField['fieldType'] = ''; - } - - if(field.match(regFlags)){ - currField['fieldFlags'] = field.match(regFlags)[1].trim()|| ''; - }else{ - currField['fieldFlags'] = ''; + var output = stdout.toString(); + var fields = output.split('\n').slice(1); + fields.forEach(function (line) { + if (line.match(regName)) { + currField.title = line.substr(line.indexOf(' ') + 1).trim() || ''; + } else if (line.match(regType)) { + currField.fieldType = line.substr(line.indexOf(' ') + 1).trim() || ''; + } else if (line.match(regFlags)) { + currField.fieldFlags = line.substr(line.indexOf(' ') + 1).trim() || ''; + } else if (line.match(regValue)) { + currField.fieldValue = line.substr(line.indexOf(' ') + 1).trim() || ''; + } else if (line === '---') { + currField.fieldValue = currField.fieldValue || ''; + fieldArray.push(currField); + currField = {}; } + }); - currField['fieldValue'] = ''; - + if (Object.keys(currField).length) { + currField.fieldValue = currField.fieldValue || ''; fieldArray.push(currField); - }); + } return callback(null, fieldArray); });