Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
template-utils
Advanced tools
Readme
Utils for Template, and Template-based applications.
Install with npm
npm i template-utils --save
(Table of contents generated by [verb])
var utils = require('template-utils');
Vinyl file loader. Used in plugins to load vinyl
files onto app.views
.
Params
file
{Object}: Vinyl file objectreturns
{Object}: Template objectConvert a Vinyl file object to a non-vinyl template object.
Params
file
{Object}: Vinyl file objectreturns
{Object}: Object with properties expected by Template or Template appsExample
var template = utils.toTemplate(file);
Convert a template
object to a Vinyl file object.
Params
file
{Object}: Object with properties expected by Templatereturns
{Object}: Vinyl file objectExample
var file = utils.toVinyl(template);
Returns true if a file is a vinyl file object.
Params
file
{Object}: Object to test.Vinyl
{Object}: Optionally pass an instance of [vinyl]returns
{Boolean}: Returns true if it's a vinyl file.Example
var file = utils.isVinyl(file);
Push a collection of templates into the stream as vinyl files.
Params
collection
{Object}: Template collectionstream
{Stream}: Stream to push the files intoExample
module.exports = function myPlugin(app) {
var id = app.getTask();
// create a template type for vinyl files and assign the `task` loader
if (!app.hasOwnProperty(id)) {
app.create(id, ['task']);
}
return through.obj(function (file, enc, cb) {
// Convert vinyl file to template and add to collection
app[id](file);
cb();
}, function (cb) {
// Get the cached template and push into stream
app.pushToStream(id, this);
cb();
});
};
Bind a thisArg
to all the functions on the target
array of object.
Params
target
{Object|Array}: Object or Array with functions as values that will be bound.thisArg
{Object}: Object to bind to the functionsreturns
{Object|Array}: Object or Array with bound functions.Get the basename of a file path, excluding extension.
Params
fp
{String}ext
{String}: Optionally pass the extension.Example
utils.basename('a/b/c.hbs');
//=> 'c'
Rename a filepath to use as the key for caching templates.
Params
fp
{String}opts
{String}: Optionally pass options.cwd
.Example
utils.renameKey('a/b/c/d/e/f.md', {last: 2});
//=> 'e/f.md'
utils.renameKey('a/b/c/d/e/f.md', {last: 3});
//=> 'c/d/e/f.md'
utils.renameKey('a/b/c/d/e/f.md', {last: 1, ext: false});
//=> 'f'
Get the extension from a string or from the first string in an array of file paths.
Params
val
{String|Array}: Filepath or array of filepathsExample
utils.getExt('a/b/c.hbs');
//=> '.hbs'
utils.getExt(['a/b/c.hbs', 'x/y/z.hbs']);
//=> '.hbs'
Ensure file extensions are formatted properly for lookups.
Params
ext
{String}: File extensionreturns
{String}Example
utils.formatExt('hbs');
//=> '.hbs'
utils.formatExt('.hbs');
//=> '.hbs'
Strip the dot from a file extension
Params
ext
{String}: extensionreturns
{String}Example
utils.stripDot('.hbs');
//=> 'hbs'
Sanitize an array of extensions before converting them to regex.
This is used by the extensionRe()
util for creating
a regex to match the given file extensions.
Params
extensions
{Array}: Array of file extensionsreturns
{Array}Creates a regex to match only the file extensions of registered engines.
This is used by the default middleware to prevent unregistered extensions from being processed.
Params
str
{String}returns
{RegExp}Cast value
to an array.
Params
value
{Array|String}returns
{Array}Example
utils.arrayify('abc');
//=> ['abc']
utils.arrayify(['abc']);
//=> ['abc']
Adjust markdown heading levels.
Adds one heading level next to all markdown headings to make them correct within the scope of the inheriting document. Headings in fenced code blocks are skipped.
Params
str
{String}: Markdown string with headings to format.returns
{String}Example
utils.heading(str);
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2014-2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on May 10, 2015.
FAQs
Utils for [Template], and Template-based applications.
We found that template-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).