@budibase/handlebars-helpers
Version:
More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
62 lines (54 loc) • 1.65 kB
JavaScript
var util = require('./utils/handlebarsUtils');
var helpers = module.exports;
const micromatch = require('micromatch');
/**
* Returns an array of strings that match the given glob pattern(s).
* Options may be passed on the options hash or locals.
*
* ```handlebars
* {{match (readdir 'foo') '*.js'}}
* {{match (readdir 'foo') (toRegex '\\.js$')}}
* ```
* @param {Array|String} `files`
* @param {Array|String} `patterns` One or more glob patterns.
* @param {Object} `locals`
* @param {Object} `options`
* @return {Array} Array of matches
* @api public
*/
helpers.match = function(files, patterns, locals, options) {
var opts = util.options(this, locals, options);
if (typeof patterns === 'string') {
patterns = patterns.split(/, */);
}
return micromatch(files, patterns, opts);
};
/**
* Returns true if a filepath contains the given pattern.
* Options may be passed on the options hash or locals.
*
* ```handlebars
* {{isMatch 'foo.md' '*.md'}}
* <!-- results in: true -->
* ```
*
* @param {String} `filepath`
* @param {String} `pattern`
* @param {Object} `options`
* @return {Boolean}
* @api public
*/
helpers.isMatch = function(files, patterns, locals, options) {
var opts = util.options(this, locals, options);
return micromatch.isMatch(files, patterns, opts);
};
/**
* Alias for micromatch helper. Deprecated in v0.9.0.
*/
helpers.mm = function() {
console.log('the {{mm}} helper is depcrecated and will be removed');
console.log('in handlebars-helpers v1.0.0, please use the {{match}}');
console.log('helper instead.');
return helpers.match.apply(this, arguments);
};
;