https://github.com/aneldev/dyna-template-string
The dyna-template-string engine for custom test templates and variables
https://github.com/aneldev/dyna-template-string
Last synced: 12 months ago
JSON representation
The dyna-template-string engine for custom test templates and variables
- Host: GitHub
- URL: https://github.com/aneldev/dyna-template-string
- Owner: aneldev
- License: mit
- Created: 2021-01-12T08:34:44.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-12T08:35:39.000Z (over 5 years ago)
- Last Synced: 2025-03-02T07:48:41.786Z (over 1 year ago)
- Language: JavaScript
- Size: 164 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dynaTemplateString
Works like [JS Template String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
The test is string, you don't use the ``` symbol and the variables are passed as a object.
# Example
```
dynaTemplateString({
text: 'Hello ${name}! How are you ${name} today?',
variables: {
name: 'John',
},
})
```
Returns:
```
Hello John! How are you John today?
```
If the variable is not passed in `variables` object the `${varName}` will remain on the output, indicating that this variable is missing.
For Instance
```
dynaTemplateString({
text: 'Hello ${salutation} ${firstName} ${lastName}.',
variables: {
salutation: 'Mr',
lastName: 'Smith',
// firstName is missing!
},
})
```
Returns:
```
Hello Mr ${firstName} Smith.
```
# API
```
export const dynaTemplateString = (
args: {
text: string;
variables: {
[variableName: string]: string;
};
},
): string
```