# typenovel

> A simple markup language to write novel with types.

Latest version **1.2.0** (published 2021-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install typenovel
pnpm add typenovel
yarn add typenovel
bun add typenovel
```

Provides the command `tnc`.

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-01-16 |
| First published | 2019-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 155 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 92 |
| Author | Watanabe Masaki |
| Maintainers | tategakibunko |
| Keywords | TypeNovel, novel, compiler, language, TypeScript, javascript |

## Links

- npm: https://www.npmjs.com/package/typenovel
- Repository: https://github.com/tategakibunko/TypeNovel
- Issues: https://github.com/tategakibunko/TypeNovel/issues
- npm.io page: https://npm.io/package/typenovel

## Dependencies (3)

- [moo](https://npm.io/package/moo.md) ^0.5.1
- [nearley](https://npm.io/package/nearley.md) ^2.20.1
- [commandpost](https://npm.io/package/commandpost.md) ^1.4.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-01-16
- 1.1.13 — 2019-11-10
- 1.1.12 — 2019-11-08
- 1.1.11 — 2019-11-08
- 1.1.10 — 2019-11-07
- 1.1.9 — 2019-11-05
- 1.1.8 — 2019-11-04
- 1.1.7 — 2019-11-04
- 1.1.6 — 2019-11-04
- 1.1.5 — 2019-11-03
- 1.1.4 — 2019-11-02
- 1.1.3 — 2019-10-24
- 1.1.2 — 2019-10-21
- 1.1.1 — 2019-10-13
- 1.1.0 — 2019-10-13
- … 4 more at https://npm.io/package/typenovel/versions

## README

# TypeNovel

A simple markup language to write novel with types.

## Example

This is what it looks like.

```javascript
@scene({
  season:"winter"
}){
  Finally, $season("Xmas") has come!
}
```

Output is here.

```html
<scene data-season="winter">
  Finally, <season>Xmas</season> has come!
</scene>
```

For more information, take a look at [Cheatsheet](https://github.com/tategakibunko/TypeNovel/tree/master/docs/Cheatsheet.md).

## Install

```bash
npm install -g typenovel
```

Then `/usr/local/bin/tnc` would be installed.

```bash
[foo@localhost] tnc --version
1.0.4
```

## Use compiler from your project

You can compile from source by `Tnc.fromString`.

```typescript
import { Tnc } from 'typenovel';

const result = Tnc.fromString('@scene(){ foo }', {
  format: 'html', // or 'text'
  minify: false
});

console.error(result.errors);
console.log(result.output);
```

Or you can compile from file by `Tnc.fromFile`.

```typescript
import { Tnc } from 'typenovel';

const result = Tnc.fromFile('sample.tn', {
  format: 'html',
  minify: false
});

console.error(result.errors);
console.log(result.output);
```

## Reader Application

Reader application is available for TypeNovel(compiler included).

Take a look at [TypeNovelReader](https://github.com/tategakibunko/TypeNovelReader).


## Motivation

### What is the difference between pro novelist and amature novelist?

I'm running a [novel posting platform](https://tb.antiscroll.com) over recent decades, and I always thought about differences between pro and amature.

I think that amature novelist sometimes lack some context description in their story, especially tend to lack the **time** description.

To confirm this feeling, I measured the scores how many times they wrote **time** in their novel, and gave them **quolity scores**.

The formula is simple.

[Total count of time written sentence] * [Entropy of time written sentence] / [Total sentence count]

For example, score of "Mon"('門' in Japanese) written by 'Natsume Soukeki (1867-1916)' is like this.

```bash
histgram: [30, 24, 33, 21, 29, 29, 30, 24, 24, 17]
score: 0.221913(total sentence size = 3879, total time sentences = 261, entropy = 3.298082)
```

In this way, I measured the average scores of many writers in my platform.

Here is scores of **amature** writers.

```
user1: average score:0.055084
user2: average score:0.057143
user3: average score:0.020505
user4: average score:0.071971
user5: average score:0.045247
user6: average score:0.042603
user7: average score:0.086316
user8: average score:0.051926
user9: average score:0.089533
```

And here is scores of **pro** writers.

```
pro1: average score:0.120076, Arthur Conan Doyle
pro2: average score:0.210235, Anton Pavlovich Chekhov
pro3: average score:0.124371, James Augustine Aloysius Joyce
pro4: average score:0.101132, Feodor Dostoyevsky
pro5: average score:0.138546, Nomura Kodou(野村胡堂)
pro6: average score:0.153463, Mori Ougai(森鴎外)
pro7: average score:0.148902, Christian Andersen
pro8: average score:0.110636, Natsume Souseki(夏目漱石)
pro9: average score:0.118976, Nakajima Atsushi(中島敦)
```

Clearly pro scores around `0.1`, but amature scores around `0.05`, difference is not so small.

So I thought "How can we fill the differences between pro and amature?".

In other words, "Can we fill the diffecence using some kind of technology?".

### My answer is "novel with type"

I think we can force all writers to fill enough information in their text, to use **typing**.

But what is the type of novel?

I think it's pair of **constraint** and **annotation**.

This is what it looks like.

```javascript
// block level tag starts with '@'
@scene({
  season: "winter", // constraint 'season'
  time: "7:00AM" // constraint 'time'
}){
  // annotation tag starts with '$'.
  // annotated constraint 'time(7:00AM)' as 'morning'
  I woke up at the $time("morning"). // I woke up at the morning.

  // annotated constraint 'season(winter)' as 'Xmas'
  Finally $season("Xmas")!
}
```

In this example, we have two constraints(`season` as "winter" and `time` as "7:00AM") for this scene block.

So we have to annotate them by writing **annotation** tag.

And we annotated them by `$time("morning")` and `$season("Xmas")`.

Now we annotated all constraints, let's compile this code!

```bash
[foo@localhost]$ tnc sample.tn
```

And you get html output like this.

```html
<scene data-season="winter" data-time="7:00AM">
  I woke up at the <time>morning</time>.
  "Finally <season>Xmas</season>!"
</scene>
```

This output is NLP(Natural Language Processing) or ML(Machine Leraning) friendly, so both platform and writers win!

Writers merit: **quality of novel**

Platform merit: **quality of data**

By the way, if we don't annotated our constraints, what happens?

Offcource, you'll get errors at the compilation time.

```bash
/Users/u1/sample.tn(line:1) 'season' is not annotated in this block!
/Users/u1/sample.tn(line:2) 'time' is not annotated in this block!
```

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