Skip to content

Commit

Permalink
support ${} for vaiable substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
haithembelhaj committed Jan 31, 2024
1 parent 766681f commit 20a88f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseString } from "./parser";
const JOBS = `
NAME post with token
CRON * * * * *
POST $APP_URL/api/post?token=$TOKEN
POST $\{APP_URL\}/api/post?token=$TOKEN
Content-Type: application/json
{
Expand Down
7 changes: 5 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export function parseString(fileContent: string, variables = {}) {
return jobs.map((job) => createJob(job));
}

function inject(fileContent: string, variables: Record<string, any>) {
export function inject(fileContent: string, variables: Record<string, any>) {
let res = fileContent;
Object.keys(variables).map(
(v) => (res = res.replaceAll(`\$${v}`, variables[v]))
(v) =>
(res = res
.replaceAll(`\$${v}`, variables[v])
.replaceAll(`\$\{${v}\}`, variables[v]))
);
return res;
}
Expand Down

0 comments on commit 20a88f2

Please sign in to comment.