npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

template-utils

v0.6.2

Published

Utils for [Template], and Template-based applications.

Downloads

1,406

Readme

template-utils NPM version Build Status

Utils for Template, and Template-based applications.

Install

Install with npm

npm i template-utils --save

Table of contents

(Table of contents generated by [verb])

Usage

var utils = require('template-utils');

API

.loaders.file

Vinyl file loader. Used in plugins to load vinyl files onto app.views.

Params

  • file {Object}: Vinyl file object
  • returns {Object}: Template object

.toTemplate

Convert a Vinyl file object to a non-vinyl template object.

Params

  • file {Object}: Vinyl file object
  • returns {Object}: Object with properties expected by Template or Template apps

Example

var template = utils.toTemplate(file);

.toVinyl

Convert a template object to a Vinyl file object.

Params

  • file {Object}: Object with properties expected by Template
  • returns {Object}: Vinyl file object

Example

var file = utils.toVinyl(template);

.isVinyl

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

.pushToStream

Push a collection of templates into the stream as vinyl files.

Params

  • collection {Object}: Template collection
  • stream {Stream}: Stream to push the files into

Example

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

.bindAll

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 functions
  • returns {Object|Array}: Object or Array with bound functions.

.basename

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'

.renameKey

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'

.getExt

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 filepaths

Example

utils.getExt('a/b/c.hbs');
//=> '.hbs'

utils.getExt(['a/b/c.hbs', 'x/y/z.hbs']);
//=> '.hbs'

.formatExt

Ensure file extensions are formatted properly for lookups.

Params

  • ext {String}: File extension
  • returns {String}

Example

utils.formatExt('hbs');
//=> '.hbs'

utils.formatExt('.hbs');
//=> '.hbs'

.stripDot

Strip the dot from a file extension

Params

  • ext {String}: extension
  • returns {String}

Example

utils.stripDot('.hbs');
//=> 'hbs'

.exts

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 extensions
  • returns {Array}

.extensionRe

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}

.arrayify

Cast value to an array.

Params

  • value {Array|String}
  • returns {Array}

Example

utils.arrayify('abc');
//=> ['abc']

utils.arrayify(['abc']);
//=> ['abc']

.headings

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

Related projects

  • middleware-utils: Utils for Template middleware.
  • template: Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… more

Running tests

Install dev dependencies:

npm i -d && npm test

Contributing

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

Author

Jon Schlinkert

License

Copyright (c) 2014-2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 10, 2015.