Exporting Generators

## Basic Overview

Aside from Importing Generators you can also Export your generators. The functionality of being able to export lists from different generators make Perchance's lists manageable since you can modularize the lists into multiple other generators and just import it into a main generator, reducing the number of lines in the main generator to a singular line. Aside from lists, functions that modify the text much like plugins do, also eases the generator maker's work to a singular line since all the nitty gritty stuff are imported.

## How to Export

Any generator can be imported. All of the lists, functions, and outputs of the imported generator are imported unless it is specified by the output specifier or `$output`.

An example from the Perchance Tutorial, you have a generator with the URL `/animal-lists` and the generator includes the following:

```
mammal
    kangaroo
    pig
    human

reptile
    lizard
    crocodile
    turtle

insect
    spider
    beetle
    ant

```
The exported lists are `mammal`, `reptile`, and `insect` lists. Upon importing, using `animalList = {import:animal-lists}` and calling `animalList`, it will return `mammal`, `reptile`, or `insect` as lists. So if we call `animalList.mammal` we can get kangaroo, pig, or human and so on with the other lists.

### Specifying Exports

This is where the `$output` property comes in. We can specify what part of our generator can be **imported**.

```
$output
    [mammal]
    [reptile]
    [insect]

```
The code above will set the output of the `{import:animal-lists}` to return any animal from the `mammal`, `reptile`, and `insect` lists **but** we cannot specify to get a `mammal`, `reptile`, or `insect` specifically.

#### Specified List/Property

To then specify a list to export **but not** all of the lists in the generator we can do something like this:

```
$output
    mammal = [mammal]
    property1 = 1

```
This will only output the `mammal` list but to access it after importing it will be `animalList.mammal` but when we try to get the `reptile` list, we won't be able to since it is not specified in the `$output`. Then to access the property, it will be `animalList.property1`.

#### Exporting Functions

Aside from lists, we can also output functions.

```
animal
 dog
 cat
 pig
 hen

$output
 getAnimal() => return "You got " + animal;

```
Upon calling `animalList.getAnimal()` it will return "You got cat" or other animals in the `animal` list. If we don't specify the function to be exported, and there is a function in our generator, when we import it, we can access the function by `animalList.getAnimal()`.

#### Output as a Function

To only export a singular function, much like plugins usually do, we can make the `$output` into a function like:

```
$output() =>
 return "You got" + animal;

```
Where when we call the imported function like `animalLists()` it will give the "You got dog" or other animals in the animal list. Since it is a function, we can also pass parameters.

```
$output(name) =>
 return name + " got a " + animal;

```
If we add "John" in the function like `animalList("John")`, it will output "John got a cat" and so on.

## Example

```
// animal-list Generator
animal
    dog
    cat
    hen
    pig

$output
    animal = [animal]
    getAnimal(name) => return name + " got a " + animal;

// Another Generator
animalList = {import:animal-list}

output
    [animalList.animal] [animalList.getAnimal("John")]
    // output:  [animal] John got a [animal]
    // where: [animal] can be dog, cat, hen, or pig.

```

Learn more stuff