@yotoplay/twee2json
v1.1.0
Published
Convert Twine/Twee files to JSON format
Readme
twee2json
A TypeScript library for converting Twine/Twee files to JSON format.
Installation
npm install twee2jsonUsage
import { convertTweeToJson } from "twee2json";
const tweeContent = `:: StoryTitle
My Story
:: StoryData
{
"start": "Start",
"ifid": "12345678-1234-1234-1234-123456789012"
}
:: Start
This is the start of the story.
[[Go to next|Next]]
:: Next
This is the next passage.
[[Go back|Start]]`;
const result = convertTweeToJson(tweeContent);
console.log(result);API
convertTweeToJson(tweeContent: string): TweeJSON
Converts a Twee file content string to a structured JSON object.
Parameters
tweeContent(string): The content of a Twee file
Returns
A TweeJSON object with the following structure:
interface TweeJSON {
metadata: Metadata;
variables: { [key: string]: any };
passages: Passage[];
}Types
Metadata
interface Metadata {
title: string | undefined;
init: Init | null;
data?: StoryData | null;
}Passage
interface Passage {
name: string;
metadata: Metadata | null;
content: string;
choices: Choice[];
comments?: string[];
variables?: { [key: string]: any };
tags?: string[];
}Choice
interface Choice {
text: string;
link: string;
}Features
- Parses Twee file format
- Extracts story metadata
- Processes passages and their content
- Handles choices and links
- Extracts variables and datamaps
- Processes tags and comments
- Moves start node to the front of passages array
Development
# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Build the package
npm run build
# Lint code
npm run lint
# Format code
npm run format:fixLicense
MIT
