This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from joolfe/feature/replace-var
Feature/replace var
- Loading branch information
Showing
17 changed files
with
1,537 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Mustache = require('mustache') | ||
|
||
/** | ||
* Rewrite escapedValue() function to not delete undefined variables | ||
*/ | ||
Mustache.Writer.prototype.escapedValue = function escapedValue (token, context, config) { | ||
const value = context.lookup(token[1]) || `{{${token[1]}}}` | ||
return String(value) | ||
} | ||
|
||
function replacePostmanVariables (collectionString, additionalVars = {}) { | ||
const postmanJson = JSON.parse(collectionString) | ||
const { variable } = postmanJson | ||
const formatVars = variable.reduce((obj, { key, value }) => { | ||
obj[key] = value | ||
return obj | ||
}, {}) | ||
// Merge collection vars with additional vars | ||
const context = { ...formatVars, ...additionalVars } | ||
return Mustache.render(collectionString, context) | ||
} | ||
|
||
module.exports = replacePostmanVariables |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.