# treelang

> Graph tree mini language for graph generation

Latest version **0.0.4** (published 2021-07-27) · MIT license · 0 weekly downloads

## Install

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

Provides the command `tree`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-07-27 |
| First published | 2020-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 28.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Aexol |
| Maintainers | aexol-studio |
| Keywords | graph, language, tree |

## Links

- npm: https://www.npmjs.com/package/treelang
- Repository: https://github.com/aexol/treelang
- Homepage: https://github.com/aexol/treelang#readme
- Issues: https://github.com/aexol/treelang/issues
- npm.io page: https://npm.io/package/treelang

## Dependencies (2)

- [pegjs](https://npm.io/package/pegjs.md) ^0.10.0
- [stdio](https://npm.io/package/stdio.md) ^2.1.1

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2021-07-27
- 0.0.3 — 2021-07-27
- 0.0.2 — 2021-07-27
- 0.0.1 — 2020-10-23

## README

# TreeLang

:smile: Let's welcome new serialisation format. The only role of the format is to hold the structure without data and types.

If you think graph, there are no arrays there there are only nodes and connections.

Deserialisation is up to you also

## Why?

World is moving towards graph sourced systems.

## Example

So assume we have a file `model.treelang` with the following contnent:

Structure

```
{
    Pizzas{
        Margerita{
            price{
                8
            }
        }
        Capriciosa{
            price{
                10
            }
        }
    }
    Ingredients{
        Tomatoe{
            price{
                2
            }
        }
        Dough{
            price{
                5
            }
        }
        Cheese{
            price{
                3
            }
        }
        Ham{
            price{
                3
            }
        }
    }
}
```

That's `34` bytes

### Deserialization

So this graph code could be deserialized as using pseudocode

```
code = Treelang.parse("model.treelang")(`
    Pizzas
`)
```

```json
{
  "Pizzas": {
    "Margheita": {
      //...Margherita content
    },
    "Capriciosa": {
      // ...Capriciosa content
    }
  }
}
```

To define the same structure in json it takes `59` bytes. Of course you can deserialise it in other way this is just an example.

As we can see the size of that .graph file differs from .json file and its only 67% of size

### Real world usage - Tests

```
Webpage{
    Pages{
        Home{
            menuButton
            heading1
            heading2
            testimonials{
                Jerry
                John
                Patricia
            }
        }
        About{
            menuButton
            Team{
                Jennifer
                Eve
                Tom
                Robert
            }
        }
        Contact{
            menuButton
            form{
                email
                message
                send
            }
        }
    }
}
```

Now using some testing framework I can bind exact string values to my elements and click them without writting this creepy structure:

```json
{
  "Webpage": {
    "Pages": {
      "Home": {
        "menuButton": "menuButton",
        "heading1": "heading1",
        "heading2": "heading2",
        "testimonials": {
          "Jerry": "Jerry",
          "John": "John",
          "Patricia": "Patricia"
        }
      },
      "About": {
        "menuButton": "menuButton",
        "Team": {
          "Jennifer": "Jennifer",
          "Eve": "Eve",
          "Tom": "Tom",
          "Robert": "Robert"
        }
      },
      "Contact": {
        "menuButton": "menuButton",
        "form": {
          "email": "email",
          "message": "message",
          "send": "send"
        }
      }
    }
  }
}
```

### Import files

index.treelang

```
Webpage{
    Main{
        *menu
    }
}
```

menu.treelang

```
about
home
```

#### Import index

index.treelang

```
Webpage{
    Main{
        *menu
    }
}
```

menu/index.treelang

```
about
home
*burger
```

menu/burger.treelang

```
cars
planes
motorcycles
```

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