# metalsmith-register-helpers

> A Metalsmith plugin for registering Handlebars helpers.

Latest version **0.4.1** (published 2020-03-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalsmith-register-helpers
pnpm add metalsmith-register-helpers
yarn add metalsmith-register-helpers
bun add metalsmith-register-helpers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2020-03-17 |
| First published | 2015-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Kenneth Ormandy |
| Maintainers | kennethormandy |
| Keywords | metalsmith, handlebars, helpers |

## Links

- npm: https://www.npmjs.com/package/metalsmith-register-helpers
- Repository: https://github.com/losttype/metalsmith-register-helpers
- Homepage: https://github.com/losttype/metalsmith-register-helpers#readme
- Issues: https://github.com/losttype/metalsmith-register-helpers/issues
- npm.io page: https://npm.io/package/metalsmith-register-helpers

## Dependencies (1)

- [extend](https://npm.io/package/extend.md) ^3.0.2

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2020-03-17
- 0.4.0 — 2017-10-17
- 0.3.0 — 2017-03-22
- 0.2.0 — 2016-06-23
- 0.1.2 — 2015-06-28
- 0.1.0 — 2015-05-08

## README

# metalsmith-register-helpers

A Metalsmith plugin for registering Handlebars helpers.

## CLI Usage

Install via npm and then add the `metalsmith-register-helpers` key to your `metalsmith.json` plugins, like so:

```json
{
  "plugins": {
    "metalsmith-register-helpers": {
      "directory": "path/to/helpers"
    }
  }
}
```

This will register all helpers in the specified directory, and use the first part of the filename as the helper name. As a simple (and admittedly contrived) example, you could add a helper that wraps everything in `<strong>` tags, stored in the file `strong.js`:

```js
module.exports = function (content) {
  return '<strong>' + content + '</strong>'
}
```

And then access it in your templates:

```html
<pre><code>{{ strong myJSONMetadata }}</code></pre>
```

## Adding Handlebars Helpers

There are lots of helpers you could try this with in the [Handlebars Helpers](https://github.com/assemble/handlebars-helpers) library. For example, add the `capitalizeFirst` helper into `_helpers/capitalizeFirst.js`:

```js
/**
 * capitalizeFirst.js
 * http://git.io/vUJU2
 */

module.exports = function (str) {
  if (str && typeof str === "string") {
    return str.charAt(0).toUpperCase() + str.slice(1)
  }
}
```

Now, you can access it in your templates:

```html
<h1>{{ capitalizeFirst "the lost typo devision." }}</h1>
```

You may also include multiple helpers in a single file:

```js
module.exports = {
  capitalizeFirst: function (str) {
    if (str && typeof str === "string") {
      return str.charAt(0).toUpperCase() + str.slice(1)
    }
  },
  json: function (context) {
    return JSON.parse(context);
  },
  someOtherHelper: function () {
    // Etc.
  }
}
```

## Adding `devDependencies` as helpers

If you’d prefer, this is another way to include helpers installed as `dependencies` in your `package.json` file into your Metalsmith project. For example, you can install the [Moment Handlebars helper](https://www.npmjs.com/package/helper-moment):

```sh
npm install --save helper-moment
```

Then, add it as a helper in `_helpers/moment.js`:

```js
var helperMoment = require('helper-moment');

module.exports = function (str, pattern){
  return helperMoment(str, pattern)
}
```

You can now access it in your template:

```html
<time date-time="{{ date }}">{{ moment date format="MMMM Do, YYYY"}}</time>
```

## License

[The MIT License (MIT)](LICENSE.md)

Copyright © 2015 [Kenneth Ormandy](http://kennethormandy.com)<br/>
Copyright © 2015 [Lin Clark](http://lin-clark.com/)

---
_Source: https://npm.io/package/metalsmith-register-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
