Skip to content

Commit

Permalink
clean(code): Move clear decode function to outer scope
Browse files Browse the repository at this point in the history
  • Loading branch information
korzio committed May 25, 2019
1 parent 4b3fd50 commit 5e65fda
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/utils/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ function template(state, options) {
return tpl;
}

function clearDecode(tplString) {
return tplString
.replace('[', '')
.replace(']', '')
.replace('(', '')
.replace(')', '')
.replace('decodeURIComponent', '');
}

const error = typeof options.errorHandler === 'function' ?
options.errorHandler :
function defaultErrorHandler(errorType) {
Expand All @@ -47,14 +56,7 @@ function template(state, options) {
.replace(/\[i([0-9]*)\]/ig, '/items')
.replace(/\['([^']+)'\]/ig, '/properties/$1')
}/${errorType}`;
function clearDecode(tplString) {
return tplString
.replace('[', '')
.replace(']', '')
.replace('(', '')
.replace(')', '')
.replace('decodeURIComponent', '');
}

return `return {
keyword: '${errorType}',
dataPath: decodeURIComponent("${clearDecode(dataPath)}"),
Expand Down

0 comments on commit 5e65fda

Please sign in to comment.