Skip to content

Commit

Permalink
Merge pull request #39 from Berkmann18/dev
Browse files Browse the repository at this point in the history
fix: left-hand-side character fixes + refactoring
  • Loading branch information
Berkmann18 authored Jun 27, 2020
2 parents 6af7cad + f3c6d3c commit 3af6be1
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 182 deletions.
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const extraChar = (err) => err.expected[0].type === 'other' && ['}', ']'].includ

const trailingChar = (err) => {
const literal = err.expected[0].type === 'literal' && err.expected[0].text !== ':';
return (
['.', ',', 'x', 'b', 'o'].includes(err.found) && (err.expected[0].type === 'other' || literal)
);
return ['.', ',', 'x', 'b', 'o'].includes(err.found) && literal;
};

const missingChar = (err) => err.expected[0].text === ',' && ['"', '[', '{'].includes(err.found);
Expand Down Expand Up @@ -100,6 +98,15 @@ const fixJson = (err, data, options) => {
};
/*eslint-enable no-console */

const fixingTime = ({ data, err, optionsCopy }) => {
fixRounds = 0;
setFixThreshold(data);
return {
data: fixJson(err, data, optionsCopy),
changed: true
};
};

/**
* @param {string} data JSON string data to check (and fix).
* @param {{verbose:boolean, parse:boolean}} options configuration object which specifies verbosity and whether the object should be parsed or returned as fixed string
Expand Down Expand Up @@ -128,12 +135,7 @@ const checkJson = (data, options) => {
};
}
} catch (err) {
fixRounds = 0;
setFixThreshold(data);
return {
data: fixJson(err, data, optionsCopy),
changed: true
};
return fixingTime({ data, err, optionsCopy });
}
};

Expand Down
Loading

0 comments on commit 3af6be1

Please sign in to comment.