# metalsmith-define

> A Metalsmith plugin to define values in the metadata

Latest version **2.1.3** (published 2020-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalsmith-define
pnpm add metalsmith-define
yarn add metalsmith-define
bun add metalsmith-define
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2020-05-11 |
| First published | 2014-06-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Aymeric Beaumet |
| Maintainers | aymericbeaumet |
| Keywords | define, metalsmith, plugin |

## Links

- npm: https://www.npmjs.com/package/metalsmith-define
- Repository: https://github.com/aymericbeaumet/metalsmith-define
- npm.io page: https://npm.io/package/metalsmith-define

## Recent versions

- 2.1.3 (latest) — 2020-05-11
- 2.1.2 — 2019-09-02
- 2.1.1 — 2019-08-21
- 2.1.0 — 2019-08-19
- 2.0.1 — 2016-04-01
- 2.0.0 — 2016-03-30
- 1.0.0 — 2014-10-10
- 0.0.1 — 2014-06-12

## README

# metalsmith-define

[![travis](https://img.shields.io/travis/aymericbeaumet/metalsmith-define?style=flat-square&logo=travis)](https://travis-ci.org/aymericbeaumet/metalsmith-define)
[![github](https://img.shields.io/github/issues/aymericbeaumet/metalsmith-define?style=flat-square&logo=github)](https://github.com/aymericbeaumet/metalsmith-define/issues)
[![npm](https://img.shields.io/npm/v/metalsmith-define?style=flat-square&logo=npm)](https://www.npmjs.com/package/metalsmith-define)

This plugin enables you to define custom values in the metadata. Why you
would use it for is up to you, but here are some ideas:

- expose a node module (e.g.: Lodash) in the metadata to use it in a
  template
- expose `process.env` to your templates (`NODE_ENV`, etc)
- expose JSON files (e.g.: expose the `package.json` file similarly to how
  it's done in a classic Gruntfile)
- expose your own JavaScript modules (e.g., define custom helper functions)

## Install

```sh
npm install metalsmith-define
```

## Usage

### CLI

_metalsmith.json_

```json
{
  "plugins": {
    "metalsmith-define": {
      "production": true
    }
  }
}
```

### Node.js

```javascript
const metalsmith = require('metalsmith')
const metalsmithDefine = require('metalsmith-define')

metalsmith(__dirname).use(
  metalsmithDefine({
    _: require('underscore'),
    development: true,
    pkg: require('./package.json'),
    helpers: require('./helpers.js'),
  })
)
```

## API

### metalsmithDefine(options)

#### options

Type: `Enumerable` _(Array, Class, Map, Object, string, etc)_
Default: `{}`

This parameter will be iterated on all its key/value pairs either via:

- `{type}.prototype.entries` if the method exists (e.g.,
  [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)),
- or
  [`Object.entries`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
  for all the other types: Array, Object, etc

The pairs will be merged into the metadata object in the order in which they are
being iterated on.

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