Skip to content

Commit

Permalink
Merge pull request #258 from diegoreis42/minor-fix
Browse files Browse the repository at this point in the history
chore: change deprecated string method
  • Loading branch information
mrodrig authored Jul 8, 2024
2 parents 84f088b + fd1871f commit e26b141
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/csv2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const Csv2Json = function(options: FullCsv2JsonOptions) {
splitLine.push('');
} else {
// Otherwise, there's a valid value, and the start index isn't the current index, grab the whole value
splitLine.push(csv.substr(stateVariables.startIndex));
splitLine.push(csv.substring(stateVariables.startIndex));
}

// Since the last character is a comma, there's still an additional implied field value trailing the comma.
Expand Down Expand Up @@ -310,7 +310,8 @@ export const Csv2Json = function(options: FullCsv2JsonOptions) {
lastChar = fieldValue[lastIndex];
// If the field starts and ends with a wrap delimiter
if (firstChar === options.delimiter.wrap && lastChar === options.delimiter.wrap) {
return fieldValue.substr(1, lastIndex - 1);
// Handle the case where the field is just a pair of wrap delimiters
return fieldValue.length <= 2 ? '' : fieldValue.substring(1, lastIndex);
}
return fieldValue;
}
Expand Down

0 comments on commit e26b141

Please sign in to comment.