# html-redirect

> Generate HTML redirection page

Latest version **0.3.0** (published 2015-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-redirect
pnpm add html-redirect
yarn add html-redirect
bun add html-redirect
```

Provides the command `html-redirect`.

## 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.3.0 |
| Published | 2015-03-16 |
| First published | 2014-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eugene Sharygin |
| Maintainers | eush77 |
| Keywords | html, redirect, redirection, stream, http, meta, http-equiv |

## Links

- npm: https://www.npmjs.com/package/html-redirect
- Repository: https://github.com/eush77/html-redirect
- Issues: https://github.com/eush77/html-redirect/issues
- npm.io page: https://npm.io/package/html-redirect

## Dependencies (6)

- [dent](https://npm.io/package/dent.md) ^0.2.0
- [trumpet](https://npm.io/package/trumpet.md) ^1.7.0
- [minimist](https://npm.io/package/minimist.md) ^1.1.1
- [duplexer2](https://npm.io/package/duplexer2.md) 0.0.2
- [escape-html](https://npm.io/package/escape-html.md) ^1.0.1
- [camelcase-keys](https://npm.io/package/camelcase-keys.md) ^1.0.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

- 0.3.0 (latest) — 2015-03-16
- 0.2.1 — 2014-11-10
- 0.2.0 — 2014-11-10
- 0.1.2 — 2014-10-02
- 0.1.1 — 2014-09-28
- 0.1.0 — 2014-09-28

## README

[![npm](https://nodei.co/npm/html-redirect.png)](https://nodei.co/npm/html-redirect/)

# html-redirect

[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]

[travis]: https://travis-ci.org/eush77/html-redirect
[travis-badge]: https://travis-ci.org/eush77/html-redirect.svg
[david]: https://david-dm.org/eush77/html-redirect
[david-badge]: https://david-dm.org/eush77/html-redirect.png

Generate HTML redirection page.

## Example

```js
htmlRedirect('http://example.com')
  .pipe(fs.createWriteStream('example1.html'));
```

example1.html:
```html
<!DOCTYPE html>
<html>
  <head>
    <title>(redirect)</title>
    <meta http-equiv="refresh" content="1;url=http://example.com/">
    <script>window.location.replace("http://example.com/");</script>
  </head>
  <body><a href="http://example.com/">Click me</a></body>
</html>
```

## API

### htmlRedirect(url, [options])

Returns a readable stream of HTML.

| Option      | Type    | Required? | Default |
| :---------- | :------ | :-------: | :------ |
| timeout     | number  | No        | `1`     |
| title       | string  | No        |         |
| placeholder | string  | No        |         |
| replaceBody | boolean | No        | `false` |

`options.timeout` is a timeout for meta-tag redirection. JS redirection will fire instantaneously regardless of the value of this option.

`options.title` is the value of `<title>`.

`options.placeholder` is either the text under default `<a>` or the whole `<body>` in HTML depending on `options.replaceBody`.

### htmlRedirect.createStream(url, [options])

Returns a transform stream. Body content &rarr; HTML page.

| Option      | Type    | Required? | Default |
| :---------- | :------ | :-------: | :------ |
| timeout     | number  | No        | `1`     |
| title       | string  | No        |         |

## CLI

```
Usage:  html-redirect [OPTION]... URL

Options:
  --title           Page title
  --placeholder     Text under <a> in the page body, or the page body itself
  --replace-body    If true, --placeholder replaces the whole body of a page
  --timeout         http-equiv refresh timeout
```

## More examples

### Set some options

```js
htmlRedirect('http://example.com', {
  timeout: 0,
  title: 'please wait...',
  placeholder: 'Your browser does not support redirection. Please click this link.'
}).pipe(fs.createWriteStream('example2.html'));
```

example2.html:
```html
<!DOCTYPE html>
<html>
  <head>
    <title>please wait...</title>
    <meta http-equiv="refresh" content="0;url=http://example.com/">
    <script>window.location.replace("http://example.com/");</script>
  </head>
  <body><a href="http://example.com/">Your browser does not support redirection. Please click this link.</a></body>
</html>
```

### Replace body

```js
htmlRedirect('http://example.com', {
  timeout: 3,
  title: 'please wait...',
  placeholder: 'Your browser does not support redirection. Please click <a href="http://example.com">this link</a>.',
  replaceBody: true
}).pipe(fs.createWriteStream('example3.html'));
```

example3.html:
```html
<!DOCTYPE html>
<html>
  <head>
    <title>please wait...</title>
    <meta http-equiv="refresh" content="3;url=http://example.com/">
    <script>window.location.replace("http://example.com/");</script>
  </head>
  <body>Your browser does not support redirection. Please click <a href="http://example.com">this link</a>.</body>
</html>
```

### Use it as a transform stream

example4.js:
```js
process.stdin
  .pipe(htmlRedirect.createStream('http://example.com/'))
  .pipe(process.stdout);
```

Try it in the console:
```
printf 'Contents from the <b>stdin</b>.' |node example.js
```

```
<!DOCTYPE html>
<html>
  <head>
    <title>(redirect)</title>
    <meta http-equiv="refresh" content="1;url=http://example.com/">
    <script>window.location.replace("http://example.com/");</script>
  </head>
  <body>Contents from the <b>stdin</b>.</body>
</html>
```

## Install

```shell
npm install html-redirect
```

## License

MIT

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