# twine-parser

> Parse a Twine game from raw HTML or from a URL (philome.la support) into its passages and connecivity

Latest version **1.3.1** (published 2018-11-12) · 0 weekly downloads

## Install

```sh
npm install twine-parser
pnpm add twine-parser
yarn add twine-parser
bun add twine-parser
```

## 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.3.1 |
| Published | 2018-11-12 |
| First published | 2018-06-14 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Jack Preston |
| Maintainers | unwttng |
| Keywords | twine, gaming, analysis |

## Links

- npm: https://www.npmjs.com/package/twine-parser
- Repository: https://github.com/unwitting/twine-parser
- Homepage: https://github.com/unwitting/twine-parser#readme
- Issues: https://github.com/unwitting/twine-parser/issues
- npm.io page: https://npm.io/package/twine-parser

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.2
- [request](https://npm.io/package/request.md) ^2.87.0
- [cytoscape](https://npm.io/package/cytoscape.md) ^3.2.13
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.5

## Recent versions

- 1.3.1 (latest) — 2018-11-12
- 1.3.0 — 2018-11-12
- 1.2.0 — 2018-06-14
- 1.1.2 — 2018-06-14
- 1.1.1 — 2018-06-14
- 1.1.0 — 2018-06-14
- 1.0.0 — 2018-06-14

## README

# twine-parser

`twine-parser` parses a Twine game into a rich JS object containing
information about its passages and their connectivity via links.

It provides methods to parse raw HTML, a Twine game hosted at a given
URL and a shortcut for accessing games from philome.la's hosting.

## Installation and usage

```
npm install --save twine-parser
```

```
const {
    parseHTML,
    parseUrl,
    parsePhilomeLa,
    toCytoscapeGraph,
} = require('twine-parser')
```

## Interface

### parseHTML(html) -> ParsedGame

This method can be passed the raw HTML contents of a Twine game. You might
have read it from a local file or loaded it from the web yourself.

Returns a [parsed Twine game](#parsed-game-format), syncronously.

```
const parsedGame = parseHTML(html)
```

### parseURL(url) -> Promise(ParsedGame)

This method will load a Twine game hosted at the given URL and then parse it
as per `parseHTML`. Returns a promise for a [parsed game](#parsed-game-format).

```
const parsedGame = await parseURL(url)
```

### parsePhilomeLa(username, game) -> Promise(ParsedGame)

This method is a convenience for loading a Twine game hosted on
[philome.la](http://philome.la). Give the username of the creator and the
game's name (you can see it in the URL on the site) and you'll get a promise for
a [parsed game](#parsed-game-format).

```
const parsedGame = await parsePhilomeLa(username, game)
```

### toCytoscapeGraph(parsedGame) -> CytoscapeGraph

Takes a [parsed game](#parsed-game-format) from one of the other calls and
converts it to a cytoscape.js graph object.

## Parsed game format

```
{
    passages: [
        {
            pid: 1,
            name: "the first passage",
            text: "This is the bit where the wordy text is. [[Go forward|the next passage]]",
            rawLinks: [
                "[[Go forward|the next passage]]
            ],
            links: [
                {
                    text: "Go forward",
                    destination: {
                        name: "the next passage",
                        pid: 2
                    }
                }
            ],
            tags: [
                "first-tag",
                "second-tag"
            ]
        },
        {
            pid: 2,
            name: "the next passage",
            // ...
        },
        // ...
    ]
}
```

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