Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: left-hand-side character fixes + refactoring #39

Merged
merged 9 commits into from
Jun 27, 2020
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