# screenplay-js

> A modern Typescript, Foutain screenplay parser. Convert Final Draft (.fdx) files to Fountain, and then parse Fountain markdown to HTML.

Latest version **0.0.18** (published 2022-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install screenplay-js
pnpm add screenplay-js
yarn add screenplay-js
bun add screenplay-js
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.18 |
| Published | 2022-01-26 |
| First published | 2021-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 61.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Aaron Guernsey |
| Maintainers | guernseycreative |
| Keywords | Fountain, Final Draft, screenplay, screenwriting, fdx, script, markdown, parser |

## Links

- npm: https://www.npmjs.com/package/screenplay-js
- Repository: https://github.com/Guernsey-Creative/screenplay-js
- Homepage: https://github.com/Guernsey-Creative/screenplay-js#readme
- Issues: https://github.com/Guernsey-Creative/screenplay-js/issues
- npm.io page: https://npm.io/package/screenplay-js

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2

## 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.18 (latest) — 2022-01-26
- 0.0.17 — 2022-01-26
- 0.0.16 — 2021-10-19
- 0.0.15 — 2021-10-19
- 0.0.14 — 2021-10-18
- 0.0.13 — 2021-10-18
- 0.0.12 — 2021-10-16
- 0.0.11 — 2021-10-14
- 0.0.10 — 2021-10-14
- 0.0.9 — 2021-10-14
- 0.0.8 — 2021-10-14
- 0.0.7 — 2021-10-14
- 0.0.6 — 2021-10-14
- 0.0.5 — 2021-10-14
- 0.0.4 — 2021-10-14
- … 3 more at https://npm.io/package/screenplay-js/versions

## README

## About

ScreenplayJS is a [Fountain](https://fountain.io/) screenplay parser based on [fountain-js](https://github.com/mattdaly/Fountain.js) and [afterwriting-labs](https://github.com/ifrost/afterwriting-labs).

Have a screenplay written in Fountain and need it converted to an HTML format? ScreenplayJS can do just that. 

## Documentation
For more detailed info, check out the [documentation](https://friendly-brahmagupta-74d600.netlify.app/).

## Installation

```
npm install screenplay-js
```

```
yarn add screenplay-js
```

## How to Use

After parsing a screenplay file into text, ScreenplayJS can parse a string and return a [ScriptJSON object](#scriptjson).

```
import { FountainParser } from "screenplay-js";

// Read file as a string
const screenplay_string = yourFileReaderFunction(screenplay_file)

// Parse screenplay text
const script_json = FountainParser.parse(screenplay_string);
```

> For an example of reading a FDX file and other use cases read the [Use Cases and Examples section](#examples-and-use-cases).

## Updating Configuration

By default, ScreenplayJS parses Fountain tokens such as notes, boneyard, and draft date. It also omits returning a list of tokens. You can enable or disable parsing options in the global config or by passing in parameters to the `parse` function.

Globally enabling token parsing:

```
import { FountainParser } from "screenplay-js";

// Enable token parsing
FountainParser.options.tokens = true;

// Read file as a string
const screenplay_string = yourFileReaderFunction(screenplay_file)

// Parse screenplay text
const script_json = FountainParser.parse(screenplay_string);
```

Enabling token parsing on the function:

```
import { FountainParser } from "screenplay-js";

// Read file as a string
const screenplay_string = yourFileReaderFunction(screenplay_file)

// Add token parsing to an options object
const your_options = { tokens: true }

// Parse screenplay text
const script_json = FountainParser.parse(screenplay_string, your_options);
```

**Note**: It is acceptable to pass in a partial options object. ScreenplayJS will merge your
options in with the default config options.

## Default Config Options

| Option | Required | Default | Type | Description |
|--------|--------|--------|--------|--------|
| paginate | false | true | boolean | Whether to paginate the HTML results |
| lines_per_page | false | "loose" | string | How many approximate lines-per-page, [via FinalDraft](https://kb.finaldraft.com/s/article/How-many-lines-per-page-does-Final-Draft-write-and-what-are-my-line-spacing-options) |
| script_html | false | false | boolean | Whether to add a HTML string to the returned [ScriptJSON object](#scriptjson) |
| script_html_array | false | false | boolean | Whether to add an array of HTML strings to the returned [ScriptJSON object](#scriptjson) |
| notes | false | true | boolean | Whether to parse note tokens from a Fountain file |
| draft_date | false | true | boolean | Whether to parse the draft date token from a Fountain file |
| boneyard | false | true | boolean | Whether to parse boneyard tokens from a Fountain file |
| tokens | false | false | boolean | Whether to add a list of tokens in returned [ScriptJSON object](#scriptjson) |

## Outputs and Interfaces

ScreenplayJS has various interfaces that can be imported and extended within your project.

Example of importing the `IScriptJSON` interface.

> For more about Interfaces read [TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/interfaces.html)

```
import { IScriptJSON } from 'screenplay-js'
```

### ScriptJSON

| Field | Type | Description |
|--------|--------|--------|
| **title** | `string` | Title of the script. |
| **credit** | `string` | Attribution of the script, i.e. 'Written by'. |
| **authors** | `Array<string>` | Authors of the script |
| **source** | `string` | Source of the script, i.e. 'Story by...' |
| **notes** | `string` | Additional information about the script. |
| **draft_date** | `string` | Date of draft in a string format. |
| **date** | `string` | Published date of the script. |
| **contact** | `string` | Contact information of the authors. |
| **copyright** | `string` | Copyright year of the script. |
| **scenes** | `Array<string>` | The parsed scenes of a script. |
| **title_page_html** | `string` | The HTML of the script title page. |
| **script_html** | `string` | The HTML of the parsed script. |
| **script_pages** | `IScriptPage[]` | The parsed script broken into pages. Each page is represented by the array index. |
| **script_pages_html** | `Array<Array<string>>` | The HTML of the parsed script pages. |
| **script_html_array** | `Array<string>` | The HTML for the parsed script. |

### Token

```
IToken {
  type?: string,
  text?: string,
  scene_number?: number,
  depth?: number
}
```

### ScriptPage

```
IScriptPage {
  _id: string;
  html: string;
}
```

### Parser Options

```
IParserOptions {
  paginate: boolean,
  lines_per_page: 'none' | 'loose' | 'normal' | 'tight' | 'very_tight',
  script_html: boolean,
  script_html_array: boolean,
  notes: boolean,
  draft_date: boolean
  boneyard: boolean,
  tokens: boolean,
}
```

## Examples and Use Cases

### GuernseyBros

ScreenplayJS is used in the [GuernseyBros](https://www.guernseybros.com/) project. You can read their latest sketches, 
spec scripts, or feature length screenplays on their website. 

GuernseyBros uses VueJS, Nuxt, and ScreenplayJS to parse 
Fountain scripts into HTML, providing mobile responsive scripts and screenplays.

### Uploading and Converting a FDX File to Fountain

An example of how to upload a Final Draft (FDX) file to Fountain screenplay format can be found in the 
exaples directory under the [fdx-to-fountain sub-directory](https://github.com/Guernsey-Creative/screenplay-js/tree/main/examples/fdx-to-fountain).

> This example is a TypeScript example written in VueJS. Feel free to copy-and-paste or convert it to the language
> of your choosing.

### Additional Examples

More examples will be added in the future. Check them out in the [example directory](https://github.com/Guernsey-Creative/screenplay-js/tree/main/examples)!

## License

MIT

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