Skip to content

Commit

Permalink
refactor(configDocs): custom apidoc parsing (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Mar 8, 2023
1 parent 85b173d commit 87ebb30
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/docs/configDocs.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
/**
* Configure Apidoc output. Filter custom "apiMock" related key/value
* Configure apiDocs output. Filter custom "apiMock" related key/value
* pairs such as randomResponse, forceStatus, or delayResponse.
*/
let group = '';

/**
* apiDoc parsing extension, see apiDocs parsing for setup.
*
* @param {string} content
* @param {*} source
* @param {*} defaultGroup
* @returns {{}}
*/
const parse = (content, source, defaultGroup) => {
group = defaultGroup || 'settings';

const keyValue = content.split('}');

let key = (keyValue[0] || '').replace(/{/, '').trim();
const value = (keyValue[1] || '').trim();
const [tempKey = '', tempValue = ''] = content.split('}');

key = key.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
});
const updatedKey = tempKey
?.replace(/{/, '')
?.trim()
?.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => {
return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
});

return { [key]: value };
return { [updatedKey]: tempValue?.trim() };
};

const getGroup = () => group;
Expand Down

0 comments on commit 87ebb30

Please sign in to comment.