Templates helper to resolve the path to a file in node_modules. This is mostly useful during development.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.
Install with npm:
$ npm install --save helper-resolve
const resolve = require('helper-resolve');
const Handlebars = require('handlebars');
handlebars.registerHelper('resolve', function (name, key) {
return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
handlebars.compile('<script src=\"{{resolve "jquery" "main"}}\"></script>')();
//=> '<script src="node_modules/jquery/dist/jquery.js"></script>'
handlebars.compile('{{resolve "jquery" "homepage"}}')();
//=> 'http://jquery.com'
Register the helper with assemble v0.6.x to use with any template engine:
const assemble = require('assemble');
assemble.helper('resolve', function (name, key) {
return resolve.sync(fp)[typeof key === 'string' ? key : 'main'];
});
async helper
assemble.asyncHelper('resolve', function (name, key, cb) {
if (typeof key === 'function') {
cb = key;
key = 'main';
}
resolve(name, function (err, res) {
cb(null, res[key]);
});
});
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.7.0, on June 26, 2018.