https://github.com/ticky/literal-toast
๐ Combines template literal values so you donโt have to
https://github.com/ticky/literal-toast
Last synced: over 1 year ago
JSON representation
๐ Combines template literal values so you donโt have to
- Host: GitHub
- URL: https://github.com/ticky/literal-toast
- Owner: ticky
- License: mit
- Created: 2016-10-20T05:22:47.000Z (over 9 years ago)
- Default Branch: develop
- Last Pushed: 2024-10-04T22:33:54.000Z (over 1 year ago)
- Last Synced: 2024-10-07T04:41:24.944Z (over 1 year ago)
- Language: JavaScript
- Size: 635 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ๐ Literal Toast
[](https://www.npmjs.com/package/literal-toast)  [](https://travis-ci.org/ticky/literal-toast) [](https://codecov.io/gh/ticky/literal-toast)
Helper for making template literal tags; combines template literal values so you don't have to
## Wait, what โ๏ธ
[Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) are a feature of ES6/ES2015 which allows processing of template literals (template strings).
This is a little helper for zipping the literals and substitutions so your tag can operate on or return the final value of the template string without reimplementing this logic itself.
## Usage
Spread the literals and substitutions from the template literal onto `literalToast`;
```javascript
import literalToast from 'literal-toast';
function lineReverse(literals, ...substitutions) {
return literalToast(literals, ...substitutions)
.split('\n')
.reverse()
.join('\n');
}
lineReverse`but it demonstrates what this does pretty simply.
This is a weird example,`;
// Returns:
// "This is a weird example,
// but it demonstrates what this does pretty simply."
```
The above example shows both the literals and substitutions for clarity, but if you don't use either parameter yourself, you can write it like this instead;
```javascript
function myTag(...literalValues) {
return literalToast(...literalValues) // your logic here
}
```