open-index/open-npm huggingface dataset:
npm package: @jamen/html-to-hyperapp
Description: Parse HTML into JSON that resembles HyperApp nodes.
Author: Jamen Marz
Latest version: 0.1.0


# html-to-hyperapp

Convert HTML to Hyperapp JSON

## Install

```sh
npm i html-to-hyperapp
```

Or use the CLI utility:

```sh
npx html-to-hyperapp input.html output.json
```

## Usage

### `htmlToHyperapp(input, output)`

Takes an input stream and output stream, where HTML comes from the input and JSON is written to the output.

```js
htmlToHyperapp(
    fs.createReadStream('./input.html'),
    fs.createWriteStream('./output.json')
)
```

### `html-to-hyperapp [input] [output]`

Performs the function over files or stdio.

```sh
$ html-to-hyperapp input.html output.json
$ cat input.html | html-to-hyperapp > output.json
```
npm package: @jamen/http-reload
Description: An autoreload interface that works purely over HTTP.
Author: Jamen Marz
Latest version: 1.1.0


# @jamen/http-reload

An autoreload interface that works purely over HTTP.

## Install

```sh
npm i @jamen/http-reload
```

## Usage

### `createReloader(options)`

Create a reloader.  The available options are:

- `pollUrl`: The URL for the request that indicates when to update.  Defaults to `/__request_poll`
- `scriptUrl`: The URL of the script which polls for the update. Defaults to `/__request.js`
- `reloadScript`: Script file which gets used on the front-end. Defaults to an internal script, see [lib/inject.js][1]

```js
let reloader = createReloader({
    pollUrl: '/__request_poll',
    scriptUrl: '/__request.js',
    reloadScript: './lib/inject.js'
})
```

### `reloader.handlePoll(request, response)`

Handles a poll request (associated with `options.pollUrl`).  Returns true if the request was a poll and was handled, otherwise false.

```js
createServer((request, response) => {
    // ...
    if (reloader.handlePoll(request, response)) {
        return // work passed off to reloader.  quit
    }
})
```

### `reloader.handleScript(request, response)`

Handles a poll script request (associated with `options.scriptUrl`).  Returns true if the request was for the script and was handled, otherwise false.

```js
createServer((request, response) => {
    // ...
    if (reloader.handleScript(request, response)) {
        return // work passed off to reloader.  quit
    }
})
```

### `reloader.transformHtml()`

Transform an HTML stream so that it uses the reload script.

```js
fs.createReadStream('/tmp/foo.html')
.pipe(reloader.transformHtml())
.pipe(response)
```

Also see [`@jamen/http-static`][2]

### `reloader.send(message, status?)`

Send a reload or error message to all polling connections.  The status is an HTTP status code that defaults to `200`.

```js
watcher(inputDir, file => {
    reloader.send(message)
})

readdir('/tmp/foo.txt', err => {
    reloader.send(err, 500)
})
```

[1]: lib/inject.js
[2]: https://npmjs.com/@jamen/http-static
npm package: @jamen/http-static
Description: Function to read, write, and cache files on `http.Server`.
Author: Jamen Marz
Latest version: 0.2.0


# http-static

Function that creates static endpoints. Persists a certain amount of file contents in memory and purges the least used files first. Replaces `fs.createReadStream` easy.

## Install

```
npm i @jamen/http-static
```

## Usage

### `createStatic(options)`

Create static cache and functions.  The options available are:

- `cacheThreshold`: A threshold in bytes for how much file contents to cache in memory. Defaults to `0x500000` (5MiB).  Use `0` to disable cache.
- `gzip`: Automatically create `.gz` files associated with each file in memory.  Defaults to `false`.

```js
let static = createStatic({ cacheThreshold: 0xFFFF })
```

### `static.readStream(file)`

A replacement for `fs.createReadStream` to keep frequently used files in memory, which can be streamed to an HTTP response object:

```js
let static = createStatic()

createServer((request, response) => {
    // ...
    static.readStream(file).pipe(response)
})
```

**Note:** Because the files are cached in memory, changes on disk wont take effect unless the cache is removed (see below) or the cache is disabled (set `cacheThreshold` to zero).

### `static.removeCache(file)`

Removes a file from the cache.  This is necessary if, for example, the file changed and you want to view the updates.

```js
let static = createStatic()

// Read from disk
static.readStream('/tmp/foo.txt').pipe(...)

// Read cache from the previous read
static.readStream('/tmp/foo.txt').pipe(...)

// Remove cache
static.removeCache('/tmp/foo.txt')

// Read from disk again
static.readStream('/tmp/foo.txt').pipe(...)
```

### `static.setContentType(file, response)`

A function to set the response content type (using the map below).

### `extToMime`

An object mapping extensions to MIMEs, generated from [`mime-db`][1].

**Note for contributors:** This file is automatically generated from a script.  To update it, run:

```sh
node scripts/create-ext-to-mime.js > lib/ext-to-mime.json
```

[1]: https://npmjs.com/mime-db