Skip to content

Template helper to resolve the path to a file in node_modules. This is mostly useful during development.

License

Notifications You must be signed in to change notification settings

helpers/helper-resolve

Repository files navigation

helper-resolve NPM version NPM monthly downloads NPM total downloads Linux Build Status

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

Install with npm:

$ npm install --save helper-resolve

Usage

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'

Assemble example

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]);
  });
});

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(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 tests

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

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.7.0, on June 26, 2018.

About

Template helper to resolve the path to a file in node_modules. This is mostly useful during development.

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published