{"_id":"@busthorne/inkjs","_rev":"2-e26d1d7569ea2ce241e53f188a75de8e","name":"@busthorne/inkjs","dist-tags":{"latest":"2.3.2-busthorne.0"},"versions":{"2.3.1-busthorne.0":{"name":"@busthorne/inkjs","version":"2.3.1-busthorne.0","author":{"name":"Yannick Lohse"},"license":"MIT","_id":"@busthorne/inkjs@2.3.1-busthorne.0","maintainers":[{"name":"badt","email":"badt@appar.at"}],"bin":{"inkjs-compiler":"bin/inkjs-compiler.js"},"dist":{"shasum":"ee47dce6bed52f4da4d8189d95dab0595ad870cd","tarball":"https://registry.npmjs.org/@busthorne/inkjs/-/inkjs-2.3.1-busthorne.0.tgz","fileCount":349,"integrity":"sha512-YRXsCSmwDtxAj5AU3kx71o3rNYK2iP/nLIQZ0y8sLlb3HKNTmcZ4wuhodFPDf+P30BbU2aAPLYkpqHwut5NATA==","signatures":[{"sig":"MEUCIGuziPua9eeFzzY9S8YF+E2o109n/iUm7Y48YFraOKemAiEAjA5j6c8HwrBsjsH2HflKBtGonx6QxqnkwN11HNungqM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6845437},"main":"dist/ink-full.js","type":"commonjs","types":"ink.d.ts","exports":{".":{"types":"./ink.d.mts","import":"./dist/ink.mjs","default":"./dist/ink.js"},"./full":{"types":"./ink.d.mts","import":"./dist/ink-full.mjs","default":"./dist/ink-full.js"},"./types":{"types":"./ink.d.ts","default":"./ink.js"},"./engine/*":{"types":"./engine/*.d.ts","default":"./engine/*.js"},"./compiler/*":{"types":"./compiler/*.d.ts","default":"./compiler/*.js"}},"gitHead":"5cbea96bbbe7272358288e9ddd20852954f23cd9","scripts":{"lint":"eslint 'src/**/*.ts'","test":"npm run build && npm run test:typescript && npm run test:javascript","build":"tsc -p ./ && rollup -c --bundleConfigAsCjs","watch":"tsc -p ./ && rollup -c -w --bundleConfigAsCjs","lint:fix":"npm run lint -- --fix","test:javascript":"npm run build && npm run test:javascript:dist && npm run test:javascript:legacy","test:typescript":"jest","test:compileFiles":"node src/tests/compile.js","test:javascript:dist":"INK_TEST=dist jest --config='jest.config.javascript.js'","test:javascript:legacy":"INK_TEST=legacy jest --config='jest.config.javascript.js'"},"_npmUser":{"name":"badt","email":"badt@appar.at"},"_npmVersion":"10.8.2","description":"A javascript port of inkle's ink scripting language (http://www.inklestudios.com/ink/)","directories":{},"_nodeVersion":"20.18.1","browserslist":"> 0.25%, not dead","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"glob":"10.3.12","jest":"29.7.0","tslib":"^2.6.3","eslint":"^8.56.0","rollup":"4.14.0","ts-jest":"29.1.2","ts-node":"^10.9.2","fs-extra":"11.2.0","prettier":"3.2.5","jest-diff":"29.7.0","typescript":"5.4.4","@babel/core":"7.26.0","@types/jest":"29.5.14","@types/node":"^20.12.5","remap-istanbul":"0.13.0","@babel/preset-env":"7.26.0","eslint-plugin-jsdoc":"48.2.3","@rollup/plugin-babel":"6.0.4","eslint-plugin-import":"2.29.1","@rollup/plugin-terser":"0.4.4","eslint-config-prettier":"9.1.0","eslint-plugin-prettier":"5.1.3","rollup-plugin-sourcemaps":"0.6.3","@typescript-eslint/parser":"7.5.0","rollup-plugin-typescript2":"0.36.0","eslint-plugin-prefer-arrow":"1.2.3","@rollup/plugin-node-resolve":"15.3.1","@typescript-eslint/eslint-plugin":"7.5.0"},"_npmOperationalInternal":{"tmp":"tmp/inkjs_2.3.1-busthorne.0_1737138886767_0.6976334365363988","host":"s3://npm-registry-packages-npm-production"}},"2.3.2-busthorne.0":{"name":"@busthorne/inkjs","version":"2.3.2-busthorne.0","description":"A javascript port of inkle's ink scripting language (http://www.inklestudios.com/ink/)","type":"commonjs","main":"dist/ink-full.js","types":"ink.d.ts","exports":{".":{"types":"./ink.d.mts","import":"./dist/ink.mjs","default":"./dist/ink.js"},"./full":{"types":"./ink.d.mts","import":"./dist/ink-full.mjs","default":"./dist/ink-full.js"},"./types":{"types":"./ink.d.ts","default":"./ink.js"},"./engine/*":{"types":"./engine/*.d.ts","default":"./engine/*.js"},"./compiler/*":{"types":"./compiler/*.d.ts","default":"./compiler/*.js"}},"scripts":{"test":"npm run build && npm run test:typescript && npm run test:javascript","test:typescript":"jest","test:javascript":"npm run build && npm run test:javascript:dist && npm run test:javascript:legacy","test:javascript:dist":"INK_TEST=dist jest --config='jest.config.javascript.js'","test:javascript:legacy":"INK_TEST=legacy jest --config='jest.config.javascript.js'","test:compileFiles":"node src/tests/compile.js","build":"tsc -p ./ && rollup -c --bundleConfigAsCjs","lint":"eslint 'src/**/*.ts'","lint:fix":"npm run lint -- --fix","watch":"tsc -p ./ && rollup -c -w --bundleConfigAsCjs"},"author":{"name":"Yannick Lohse"},"license":"MIT","bin":{"inkjs-compiler":"bin/inkjs-compiler.js"},"browserslist":"> 0.25%, not dead","devDependencies":{"@babel/core":"7.26.10","@babel/preset-env":"7.26.9","@rollup/plugin-babel":"6.0.4","@rollup/plugin-node-resolve":"15.3.1","@rollup/plugin-terser":"0.4.4","@types/jest":"29.5.14","@types/node":"^20.12.5","@typescript-eslint/eslint-plugin":"7.5.0","@typescript-eslint/parser":"7.5.0","eslint":"^8.56.0","eslint-config-prettier":"9.1.0","eslint-plugin-import":"2.29.1","eslint-plugin-jsdoc":"48.2.3","eslint-plugin-prefer-arrow":"1.2.3","eslint-plugin-prettier":"5.1.3","fs-extra":"11.2.0","glob":"10.3.12","jest":"29.7.0","jest-diff":"29.7.0","prettier":"3.2.5","remap-istanbul":"0.13.0","rollup":"4.14.0","rollup-plugin-sourcemaps":"0.6.3","rollup-plugin-typescript2":"0.36.0","ts-jest":"29.1.2","ts-node":"^10.9.2","tslib":"^2.6.3","typescript":"5.4.4"},"publishConfig":{"access":"public"},"_id":"@busthorne/inkjs@2.3.2-busthorne.0","gitHead":"3ef29df2d3fa9fa4753afbaede0634b25f381e80","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-YcEVW4dugbeHNd/Vha8tu+rpGMjI8/dTiE5jShK9FcJhnCTL0nqpqqvMIUiGHTag+yfXNTiYWqeEJ2X+l5LGeg==","shasum":"7f87ad9cbd77c74c233cd0d4a52418839e642845","tarball":"https://registry.npmjs.org/@busthorne/inkjs/-/inkjs-2.3.2-busthorne.0.tgz","fileCount":394,"unpackedSize":6916474,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHPtb3C7751sOHQFKhtVk7WOuqE9y+e/+wcrpBDm3p4FAiBQJ4LMXMGuTKjKtPmV6pkRokWh3TDJv2c4C3m3Bw3eUA=="}]},"_npmUser":{"name":"badt","email":"badt@appar.at"},"directories":{},"maintainers":[{"name":"badt","email":"badt@appar.at"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/inkjs_2.3.2-busthorne.0_1744473008445_0.4178599964222043"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-17T18:34:46.637Z","modified":"2025-04-12T15:50:08.839Z","2.3.1-busthorne.0":"2025-01-17T18:34:47.181Z","2.3.2-busthorne.0":"2025-04-12T15:50:08.660Z"},"author":{"name":"Yannick Lohse"},"license":"MIT","description":"A javascript port of inkle's ink scripting language (http://www.inklestudios.com/ink/)","maintainers":[{"name":"badt","email":"badt@appar.at"}],"readme":"# ![inkjs](media/inkjs.png)\n\n![build](https://github.com/y-lohse/inkjs/workflows/Build/badge.svg)\n[![npm](https://img.shields.io/npm/v/inkjs.svg)](https://www.npmjs.com/package/inkjs)\n[![codecov](https://codecov.io/gh/y-lohse/inkjs/branch/master/graph/badge.svg)](https://codecov.io/gh/y-lohse/inkjs)\n\nThis is a javascript port of inkle's [ink](https://github.com/inkle/ink), a scripting language for writing interactive narrative.\n\ninkjs is fully compatible with the original version, has zero dependency and works in all browsers and node.js. Please have a look at [the demo](http://yannick-lohse.fr/inkjs/)!\n\n## Table of content\n\n- [](#)\n\t- [Table of content](#table-of-content)\n\t- [Installation](#installation)\n\t- [Quickstart](#quickstart)\n\t- [Working with a JSON file](#working-with-a-json-file)\n\t- [Using node.js](#using-nodejs)\n\t\t- [Loading inkjs](#loading-inkjs)\n\t\t- [Loading a json file](#loading-a-json-file)\n\t\t- [Starting a story](#starting-a-story)\n\t- [Differences with the C# API](#differences-with-the-c-api)\n\t\t- [Getting and setting ink variables](#getting-and-setting-ink-variables)\n\t\t- [Getting the output text when calling `EvaluateFunction`](#getting-the-output-text-when-calling-evaluatefunction)\n\t- [Using TypeScript](#using-typescript)\n\t- [Compiler](#compiler)\n\t\t- [inkjs-compiler.js](#inkjs-compilerjs)\n\t\t- [online compiler](#online-compiler)\n\t\t- [Differences with the C# Compiler](#differences-with-the-c-compiler)\n\t- [Compatibility table](#compatibility-table)\n\n## Installation\n\nInstall using `npm install inkjs`.\n\nIf you are not using npm you can grab the latest release directly from [here](https://unpkg.com/inkjs). Simply include that file with a script tag and you'll be on your way!\n\nFor projects targeting older browsers that have no support for ES2015 features, a (heavier but) more backward compatible version is also exposed. Grab it by either:\n\n- `import ink from 'inkjs/dist/ink.js`\n- Directly downloading the file from [here](https://unpkg.com/inkjs@1.11.0/dist/ink.js)\n\n## Quickstart\n\nThe simplest way to get started with inkjs is to use the [serverless boilerplate](https://github.com/y-lohse/inkjs/blob/master/templates/browser_serverless/) in the [templates folder](https://github.com/y-lohse/inkjs/blob/master/templates/). Replace the placeholder story in `story.js` with your own and open `index.html`!\n\nHere's what happens behind the scenes: inkjs gives you access to a global object named `inkjs` which has a property called `Story`. This is the main class we interact with.\n\nWe simply create a new story by calling `var story = new inkjs.Story(storyContent);` — the variable `storyContent` is defined in the `story.js` file. After that, we can use `story.Continue()` and `story.currentChoices` as described in the [the official documentation](https://github.com/inkle/ink/blob/master/Documentation/RunningYourInk.md#getting-started-with-the-runtime-api).\n\n## Working with a JSON file\n\nIf you frequently need to update your story, pasting the content into `story.js` will probably get tedious. So another option is to dynamically load the JSON file for your story. Unfortunately, your browser won't let you do that because of [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS), which means you need a web server to do this. You could do this without much hassle with [node.js](https://www.npmjs.com/package/http-server) or [python](http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python) for example.\n\nOnce the server is running, use the [other boilerplate](https://github.com/y-lohse/inkjs/blob/master/templates/browser_with_server) and place your story content inside `story.json`. Behind the scenes, the only difference is that we load the JSON file via ajax before creating the story:\n\n```javascript\nfetch('story.json')\n\t.then(function (response) {\n\t\treturn response.text();\n\t})\n\t.then(function (storyContent) {\n\t\tstory = new inkjs.Story(storyContent);\n\t\tcontinueStory();\n\t});\n```\n\n## Using node.js\n\nYou can find some boilerplate code for node.js [here](https://github.com/y-lohse/inkjs/blob/master/templates/nodejs).\n\n### Loading inkjs\n\n#### require\n\nYou can require the module: \n```javascript \nvar Story = require('inkjs').Story;\n```\n\n#### import\nYou can use import style: \n```javascript\nimport { Story } from 'inkjs';\n```\n\n### Loading a json file\n\nYou can load the json file using a simple call to `require`:\n\n```javascript\nvar json = require('./ink_file.json');\n```\n\nYou can also load it using `fs`. In that case, please note that inklecate outputs a json file encoded **with** BOM, and node isn't very good at handling that.\n\n```javascript\nvar fs = require('fs');\nvar json = fs.readFileSync('./ink_file.json', 'UTF-8').replace(/^\\uFEFF/, ''); //strips the BOM\n```\n\n### Starting a story\n\nNow that you have a `Story` object and a json file, it's time to bring it all together:\n\n```javascript\nvar inkStory = new Story(json);\n\nconsole.log(inkStory.ContinueMaximally());\n//etc\n```\n\nFrom there on, you can follow [the official documentation](https://github.com/inkle/ink/blob/master/Documentation/RunningYourInk.md#getting-started-with-the-runtime-api).\n\n## Differences with the C# API\n\nThere are a few very minor API differences between ink C# and inkjs:\n\n### [Getting and setting ink variables](https://github.com/inkle/ink/blob/master/Documentation/RunningYourInk.md#settinggetting-ink-variables)\n\nOn platforms that do not support [ES2015 Proxies](https://kangax.github.io/compat-table/es6/) (basically node.js v5, IE 11, Safari 9 and everything below), you can't directly read and write variables to the story state. Instead you will have to use the `$` function:\n\n```javascript\n_inkStory.variablesState.$('player_health', 100);\n//instead of _inkStory.variablesState[\"player_health\"] = 100;\n\nvar health = _inkStory.variablesState.$('player_health');\n//instead of var health = _inkStory.variablesState[\"player_health\"];\n```\n\n### Getting the output text when calling `EvaluateFunction`\n\n`EvaluateFunction()` lets you evaluate an ink function from within your javascript. The \"normal\" call is the same than in C#:\n\n```javascript\nvar result = EvaluateFunction('my_ink_function', ['arg1', 'arg2']);\n//result is the return value of my_ink_function(\"arg1\", \"arg2\")\n```\n\nHowever, if you also wish to retrieve the text that `my_ink_function` output, you need to call it like this:\n\n```javascript\nvar result = EvaluateFunction('my_ink_function', ['arg1', 'arg2'], true);\n//now result is an object with two properties:\n// result.returned is the return value of my_ink_function(\"arg1\", \"arg2\")\n// result.output is the text that was written to the output while the function was evaluated\n```\n\n## Compiler\n\n### inkjs-compiler.js\n\n```shell\n$ node inkjs-compiler.js -h\n\nUsage: inkjs-compiler <options> <ink or json file>\n   -o <filename>:   Output file name\n   -c:              Count all visits to knots, stitches and weave points, not\n                    just those referenced by TURNS_SINCE and read counts.\n   -p:              Play mode (automatic if a json file is passed as argument)\n   -s:              Print stats about story including word count in JSON format\n   -k:              Keep inklecate running in play mode even after story is complete\n\n```\n\nIf you install the package globally it is available as the `inkjs-compiler` command.  \nAlternatively, you can call it using `npx inkjs`\n\n### online compiler\n\n```javascript\nconst inkjs = require(\"inkjs/full\") //the `full` submodule contains the Compiler\nconst story = new inkjs.Compiler(`Hello World`).Compile();\n// story is an inkjs.Story that can be played right away\n\nconst jsonBytecode = story.ToJson();\n// the generated json can be further re-used\n```\n\nYou can use this in combination with [Webpack and TypeScript](docs/working-with-typescript-and-webpack.md).\n\n### Differences with the C# Compiler\n\nSee [Differences with the C# Compiler](docs/compiler-differences.md).\n\n## Using TypeScript\n\nInkjs is also packaged to be usable with typescript imports, the main classes (`Story`, `InkList`, `Compiler`) are available under the `/types`submodule.\n\n```ts\nimport { Story, Compiler } from 'inkjs/types'; // shortcut\n\nlet story: Story;\nlet compiler: Compiler;\n```\n\nIt is also possible to import deeply nested classes if needed\n\n```ts\nimport { Story } from 'inkjs/engine/Story';\nimport { Compiler } from 'inkjs/compiler/Compiler';\n\nimport { Choice } from 'inkjs/engine/Choice'\nimport { Identifier } from 'inkjs/compiler/Parser/ParsedHierarchy/Identifier';\n\n```\n\n## Compatibility table\n\n| _inklecate_ version | _inkjs_ version | _json_ version |\n| :-----------------: | :-------------: | :------------: |\n|    0.3.5 – 0.4.0    |  1.0.0 – 1.1.0  |       18       |\n|    0.4.1 – 0.5.0    |  1.1.1 – 1.1.3  |                |\n|        0.5.1        |      1.2.0      |                |\n|        0.6.0        |      1.3.0      |                |\n|        0.6.1        |  1.4.0 – 1.4.1  |                |\n|        0.6.2        |      1.4.2      |                |\n|        0.6.3        |      1.4.3      |                |\n|        0.6.4        |  1.4.4 – 1.4.6  |                |\n|        0.7.0        |  1.5.0 – 1.5.1  |                |\n|        0.7.1        |      1.5.2      |                |\n|    0.7.2 – 0.7.4    |      1.6.0      |                |\n|    0.8.0 – 0.8.1    |  1.7.1 – 1.7.2  |                |\n|        0.8.2        |  1.8.0 – 1.9.0  |                |\n|        0.8.3        | 1.10.0 – 1.10.5 |                |\n|        0.9.0        |     1.11.0      |       19       |\n|        1.0.0        |  2.0.0 - 2.1.0  |       20       |\n|        1.1.1        |      2.2.*      |       21       |\n|        1.2.0        |      2.3.0      |                |\n","readmeFilename":"README.md"}