# posthtml-load-options

> Autoload Options for PostHTML

Latest version **1.0.0** (published 2016-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install posthtml-load-options
pnpm add posthtml-load-options
yarn add posthtml-load-options
bun add posthtml-load-options
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-11-14 |
| First published | 2016-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michael Ciniawky |
| Maintainers | michael-ciniawsky |
| Keywords | posthtml, posthtml-options |

## Links

- npm: https://www.npmjs.com/package/posthtml-load-options
- Repository: https://github.com/posthtml/posthtml-load-options
- Homepage: https://github.com/posthtml/posthtml-load-options#readme
- Issues: https://github.com/posthtml/posthtml-load-options/issues
- npm.io page: https://npm.io/package/posthtml-load-options

## Dependencies (1)

- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^2.1.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-11-14
- 1.0.0-alpha — 2016-06-10

## README

[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![code style][style]][style-url]
[![chat][chat]][chat-url]

<div align="center">
  <img width="140" height="120" title="Load Options" vspace="20"
    src="https://posthtml.github.io/posthtml-load-options/logo.svg"
  <a href="https://github.com/posthtml/posthtml">
    <img width="220" height="200" title="PostHTML" hspace="20"  src="http://posthtml.github.io/posthtml/logo.svg">
  </a>
  <h1>Load Options</h1>
  <p>Autoload Options for PostHTML<p>
</div>

<h2 align="center">Install</h2>

```bash
npm i -D posthtml-load-options
```

<h2 align="center">Usage</h2>

### `package.json`

Create a **`posthtml`** section in **`package.json`**.

```
Root
  |– client
  |– public
  |
  |- package.json
```

```json
{
  "dependencies": {
    "posthtml-sugarml": "^1.0.0"
  },
  "posthtml": {
    "parser": "posthtml-sugarss",
    "from": "path/to/src/file.html",
    "to": "path/to/dest/file.html"
  }
}
```

### `.posthtmlrc`

Create a **`.posthtmlrc`** file.

```
Root
  |– client
  |– public
  |
  |-.posthtmlrc
  |- package.json
```

```json
{
  "parser": "posthtml-sugarss",
  "from": "path/to/src/file.html",
  "to": "path/to/dest/file.html"
}
```

### `posthtml.config.js`

Create a **`posthtml.config.js`** file.

```
Root
  |– client
  |– public
  |
  |- posthtml.config.js
  |- package.json
```

```js
module.exports = (ctx) => {
  return {
    parser: ctx.ext ==='.sml' ? 'posthtml-sugarss' : false,
    from: 'path/to/src/file.html',
    to: 'path/to/dest/file.html'
  }
}
```

<h2 align="center">Options</h2>

**`parser`**:

```js
parser: 'posthtml-sugarss'
```

**`from`**:

```js
from: 'path/to/dest/file.html'
```

**`to`**:

```js
to: 'path/to/dest/file.html'
```

**`render`**:

```js
render: 'posthtml-jsx'
```

### Context

When using a function in `(posthtml.config.js)`, it's possible to pass context to `posthtml-load-options`, which will be evaluated before loading your options. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available.

<h2 align="center">Example</h2>

**posthtml.config.js**
```js
export default config = (ctx) => {
  return {
    parser: ctx.ext === '.sml' ? 'posthtml-sugarml' : false,
    from: 'client/index.html',
    to: 'public/index.html'
  }
}
```

### <img width="80" height="80" src="https://worldvectorlogo.com/logos/nodejs-icon.svg">

```js
import { dirname } from 'path'
import { readFileSync } from 'fs'

import posthtml from 'posthtml'
import optionsrc from 'posthtml-load-options'

const sml = readFileSync('./client/index.sml', 'utf8')

const ctx = { ext: dirname(sml) }

optionsrc(ctx).then((options) => {
  posthtml()
    .process(sml, options)
    .then((result) => console.log(result.html))
}))
```

<h2 align="center">Maintainer</h2>

<table>
  <tbody>
   <tr>
    <td align="center">
      <img width="150 height="150"
      src="https://avatars.githubusercontent.com/u/5419992?v=3&s=150">
      <br />
      <a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
    </td>
  </tr>
  <tbody>
</table>


[npm]: https://img.shields.io/npm/v/posthtml-load-options.svg
[npm-url]: https://npmjs.com/package/posthtml-load-options

[node]: https://img.shields.io/node/v/posthtml-load-options.svg
[node-url]: https://nodejs.org/

[deps]: https://david-dm.org/michael-ciniawsky/posthtml-load-options.svg
[deps-url]: https://david-dm.org/michael-ciniawsky/posthtml-load-options

[tests]: http://img.shields.io/travis/michael-ciniawsky/posthtml-load-options.svg
[tests-url]: https://travis-ci.org/michael-ciniawsky/posthtml-load-options

[cover]: https://coveralls.io/repos/github/michael-ciniawsky/posthtml-load-options/badge.svg?branch=master
[cover-url]: https://coveralls.io/github/michael-ciniawsky/posthtml-load-options?branch=master

[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/

[chat]: https://badges.gitter.im/posthtml/posthtml.svg
[chat-url]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"

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