# ffn-parser

> A collection of functions to help parse pages off of FanFiction.net

Latest version **0.0.11** (published 2024-10-20) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2024-10-20 |
| First published | 2021-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 258.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Arne 'TigeR' Linck |
| Maintainers | amur-tiger |
| Keywords | fanfiction, parser |

## Links

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

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.11 (latest) — 2024-10-20
- 0.0.10 — 2024-10-20
- 0.0.9 — 2024-05-30
- 0.0.8 — 2024-03-22
- 0.0.7 — 2022-02-20
- 0.0.6 — 2021-04-26
- 0.0.5 — 2021-03-25
- 0.0.4 — 2021-03-10
- 0.0.3 — 2021-02-19
- 0.0.2 — 2021-02-15
- 0.0.1 — 2021-02-13

## README

# FanFiction.net Parser

<a href="https://github.com/amur-tiger/ffn-parser/actions/workflows/ci.yml">
<img src="https://github.com/amur-tiger/ffn-parser/actions/workflows/ci.yml/badge.svg" alt="CI" />
</a>

<a href="https://www.npmjs.com/package/ffn-parser">
<img alt="License" src="https://img.shields.io/npm/v/ffn-parser" />
</a>

<a href="https://github.com/amur-tiger/ffn-parser/issues">
<img alt="License" src="https://img.shields.io/github/issues/amur-tiger/ffn-parser" />
</a>

<a href="https://github.com/amur-tiger/ffn-parser/blob/master/LICENSE.md">
<img alt="License" src="https://img.shields.io/github/license/amur-tiger/ffn-parser" />
</a>

<hr />

Since [fanfiction.net](https://www.fanfiction.net) does not have an API, information about stories hosted there
can only be retrieved by scraping the webpages themselves. Unfortunately, bits of information are sometimes
formatted differently or are just thrown together, making it very hard to extract the needed information.

This library aims to provide a set of functions to parse the webpages and extract the information in a
machine-readable format.

⚠ This library follows semantic versioning. It is not stable yet, meaning that newer versions may break
backwards-compatibility at any time.

## Installation

Install this library via `npm` or `yarn`.

```shell
npm install ffn-parser
```

## Usage

This library does not download any pages from [fanfiction.net](https://www.fanfiction.net). You must download
these pages yourself using any library of your choice. Please note that fanfiction.net is rate limited. Do not
download too many pages at once and wait the indicated amount of time if you hit the limit.

```typescript
import { parseStory } from "ffn-parser";

// the id of the story you want to analyze
const storyId = 1;

const response = await fetch(`https://www.fanfiction.net/s/${storyId}`);
const html = await response.text();
const template = document.createElement("template");
template.innerHTML = html;

// info contains all the extracted information
const info = await parseStory(template.content);
```

Since this library needs to analyze the DOM of the page, a way to create DOM elements is needed. You might need
to install a tool like [JSDOM](https://github.com/jsdom/jsdom) if you want to use this library on NodeJS.

For now, three functions are provided.

* `parseStory`, which can be used on story pages like in the example above to extract information about a story.
* `parseFollows`, which can be used on the alerts and favorites list in the user settings.
* `parseStoryList`, which can be used on lists of stories such as when searching for crossovers or exploring the stories in a community.

The latter two functions do not provide as much information about a story as `parseStory`, since the HTML pages they
parse do not contain any more information.

This library also provides full Typescript support. The returned types are the best place to inspect what
information the functions extract - or just execute them and see what happens.

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