Skip to content

Commit

Permalink
feat: bru hasEnvVar, hasVar, deleteVar (usebruno#2531)
Browse files Browse the repository at this point in the history
Co-authored-by: Anoop M D <[email protected]>
  • Loading branch information
2 people authored and jwetzell committed Aug 2, 2024
1 parent cb4099d commit 5d863ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/bruno-app/src/components/CodeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ if (!SERVER_RENDERED) {
'bru.cwd()',
'bru.getEnvName(key)',
'bru.getProcessEnv(key)',
'bru.hasEnvVar(key)',
'bru.getEnvVar(key)',
'bru.setEnvVar(key,value)',
'bru.hasVar(key)',
'bru.getVar(key)',
'bru.setVar(key,value)',
'bru.deleteVar(key)',
'bru.setNextRequest(requestName)'
];
CodeMirror.registerHelper('hint', 'brunoJS', (editor, options) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/bruno-js/src/bru.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Bru {
return this.processEnvVars[key];
}

hasEnvVar(key) {
return Object.hasOwn(this.envVariables, key);
}

getEnvVar(key) {
return this._interpolate(this.envVariables[key]);
}
Expand All @@ -55,6 +59,10 @@ class Bru {
this.envVariables[key] = value;
}

hasVar(key) {
return Object.hasOwn(this.collectionVariables, key);
}

setVar(key, value) {
if (!key) {
throw new Error('Creating a variable without specifying a name is not allowed.');
Expand All @@ -81,6 +89,10 @@ class Bru {
return this._interpolate(this.collectionVariables[key]);
}

deleteVar(key) {
delete this.collectionVariables[key];
}

getRequestVar(key) {
return this._interpolate(this.requestVariables[key]);
}
Expand Down

0 comments on commit 5d863ee

Please sign in to comment.