var-sub

1.1.0 • Public • Published

var-sub

Bash style variable substitutions.

String replacements

await stringFromTemplate(`foo $BAR`, {
  BAR: "baz"
}); // foo baz
 
await stringFromTemplate("foo ${bar}", {
  BAR: "baz"
}); // foo baz
 
await stringFromTemplate("my home dir is $HOME", {
  ...process.env
}); // my home dir is /Users/joeflateau
 
await stringFromTemplate(
  await request.get("https://example.org/some/template"),
  {
    FOO: "bar"
  }
);

File replacements

await stringFromTemplateFile(__dirname + "/cloudfront.template.json", {
  VIEWER_REQUEST_FUNCTION_ARN: viewerRequestFunctionArn,
  ORIGIN_RESPONSE_FUNCTION_ARN: originResponseFunctionArn,
  CALLER_REFERENCE: callerReference,
  STAGE,
  CNAME 
});

Recursive copy w/ replacements

await copyFromTemplateFiles(
  __dirname + "/../srcDir",
  "./**/*.txt",
  __dirname + "/../destDir",
  { BAR: "bar" }
);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    1
    • latest

Version History

Package Sidebar

Install

npm i var-sub

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

15.2 kB

Total Files

6

Last publish

Collaborators

  • joeflateau