Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clo4/deno_substitute
Simple & flexible variable substitution for Deno. Perfect for environment variables.
https://github.com/clo4/deno_substitute
deno environment-variables envsubst substitution
Last synced: 15 days ago
JSON representation
Simple & flexible variable substitution for Deno. Perfect for environment variables.
- Host: GitHub
- URL: https://github.com/clo4/deno_substitute
- Owner: clo4
- Created: 2021-03-21T11:44:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-03-22T08:47:23.000Z (over 3 years ago)
- Last Synced: 2024-10-26T06:51:53.603Z (20 days ago)
- Topics: deno, environment-variables, envsubst, substitution
- Language: TypeScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deno_substitute
**Simple, familiar, fast-enough variable substitution.**
Perfect for environment variables, flexible enough for whatever.
## Usage
`substitute` substitutes variables using a function.
```typescript
import { substitute } from "https://deno.land/x/[email protected]/mod.ts";substitute("Welcome $HOME", Deno.env.get);
// => "Welcome /home/user"
substitute("Welcome $HOME", (s) => s.toLowerCase());
// => "Welcome home"
```It's strict by default but designed to recover from errors gracefully.
```typescript
substitute("Hello, ${}", (x) => x);
// NoNameError: Expected variable name at column 8
substitute("Hello, ${}", (x) => x, { strict: false });
// => "Hello, ${}"
```Bash and Windows CMD-style variables are both accepted, and can be disabled
individually.```typescript
substitute("$HOME ${HOME}", (x) => x.toLowerCase());
// => "home home"
substitute("$HOME ${HOME}", (x) => x.toLowerCase(), { dollar: false });
// => "$HOME ${HOME}"substitute("%USERPROFILE%", (x) => x.toLowerCase());
// => "userprofile"
substitute("%USERPROFILE%", (x) => x.toLowerCase(), { percent: false });
// => "%USERPROFILE%"
```You can use a literal $ or % by doubling it, like `"$$"` or `"%%"`.
## Contributing
I'll endeavour to keep it working but I probably won't be adding anything new
myself. It does what I need it to. I'm more than happy to accept and help out
with PRs.### Fair warning, though...
This code is extremely messy. The only goal when writing it was to make it work,
not to make it maintainable. Any negative side effects as a result of exposure
should be dealt with by a medical professional.