Skip to content

Commit

Permalink
fix: extra characters in default value
Browse files Browse the repository at this point in the history
Remove extra characters from default value

Closes #154
  • Loading branch information
ifedchankau committed Aug 17, 2018
1 parent e1d0b0e commit d78327d
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ const unifyDescription = (description) => {
* @return {string} - default value
*/
const getDefaultValue = (description, regexp) => {
const result = getValueByRegexp(description, regexp);
return result ? removeCharAtTheEnd(
removeCharAtSides(result[5].trim(), ['\'', '\"', ',']), ['.']) : null;
let result = getValueByRegexp(description, regexp);
if (result) {
result = removeCharAtBegin(result[5].trim(), ['\'', '\"', ',']);
result = removeCharAtTheEnd(result, ['\'', '\"', ',', '.']);
return result;
}
return null;
};

/**
Expand Down Expand Up @@ -77,7 +81,7 @@ const getDelimiterValue = (string, regexp) => {
*/
const getPropertyName = (string, regexp) => {
const result = getValueByRegexp(string, regexp);
return result ? removeCharAtTheEnd(result[0].trim(), [',']) : null;
return result ? removeCharAtTheEnd(result[2].trim(), [',']) : null;
};

/**
Expand Down Expand Up @@ -150,24 +154,15 @@ const checkFlagsByExamples = (section, context) => {
}
};

/**
* Remove extra coma from string
* @param {string} string - any string
* @return {string} - result string
*/
const removeExtraComa = (string) => {
return removeChar(string, [',']).trim();
};
/**
* Remove argument names from string
* @param {string} string - any string
* @param {argument} argument - argument object with description, names, etc.
* @return {string} - result string
*/
const removeExtraArgumentNames = (string, argument) => {
return removeChar(
removeExtraComa(string),
[argument.longName, argument.shortName]).trim();
return removeChar(string,
[',', argument.longName, argument.shortName]).trim();
};

/**
Expand Down Expand Up @@ -200,12 +195,10 @@ const removeCharAtTheEnd = (string, array) => {
* @param {array} array - char for remove
* @return {*} - string without chars
*/
const removeCharAtSides = (string, array) => {
const removeCharAtBegin = (string, array) => {
let result = string;
array.map((char) => {
result = result.charAt(0) === char ? result.slice(1) : result;
result = result.charAt(result.length - 1) === char ?
result.slice(0, result.length - 1) : result;
});
return result;
};
Expand Down

0 comments on commit d78327d

Please sign in to comment.