Skip to content

Commit

Permalink
factor out interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Apr 15, 2013
1 parent 5891471 commit 1b21b01
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ exports.parse = function (s, env) {
;
}
else if (/^"/.test(s)) {
return s
.replace(/^"|"$/g, '')
.replace(/\\(["'\\$`(){}!#&*|])/g, '$1')
.replace(/\$(\w+)/g, getVar)
.replace(/\${(\w+)}/g, getVar)
;
}
else {
return s
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
.replace(/\$(\w+)/g, getVar)
.replace(/\${(\w+)}/g, getVar)
;
return interpolate(s.replace(/^"|"$/g, ''))
}
else return interpolate(s);
})
;

function getVar (_, x) {
return String(env[x])
}

function interpolate (s) {
return s
.replace(/\\([ "'\\$`(){}!#&*|])/g, '$1')
.replace(/\$(\w+)/g, getVar)
.replace(/\${(\w+)}/g, getVar)
;
}
};

0 comments on commit 1b21b01

Please sign in to comment.