async-tag
v0.2.0
Published
Resolves template literals tag values before applying a generic tag
Downloads
17,872
Maintainers
Readme
async-tag
Social Media Photo by Tobias Rademacher on Unsplash
Resolves template literals tag values before applying a generic tag.
import asyncTag from 'async-tag';
// or const asyncTag = require('asyncTag');
// or <script src="//unpkg.com/async-tag">
// example
const asyncRaw = asyncTag(String.raw);
// async values
asyncRaw`a${[
1,
[2, [Promise.resolve(3)], 4],
[5, 6]
]}${Promise.resolve(7)}c`
.then(result => {
console.assert(result === 'a1,2,3,4,5,67c')
});
// direct values
asyncRaw`a${'b'}c`
.then(result => {
console.assert(result === 'abc')
});
Compatibility
This module source code is written in a way that guarantees there won't be any code bloat once transpiled, without necessarily providing worse performance than native ES6+.
Both index.js and min.js target any client/server JavaScript engine, assuming there is support, or there is a polyfill, for:
Array.isArray(any)
to work with nested interpolationsPromise.all(array)
to resolve all interpolationsFunction.prototype.bind
to be sure both context and template are expected
Please note this module is pretty much done so, if there are not many updates in the long term, it's because it's 100% code covered and, for what it does, it won't likely need any change in the future.