Creating a library
This page describes how to create a library in Pen. It consists of the following steps:
- Create a library package.
- Publish the package.
Creating a library package
Library packages are packages imported and used by other packages.
To create it, you run a pen create --library command with your library's name (e.g. foo) in your terminal.
pen create --library foo
Then, you should see a foo directory in your current directory. When you go there, you should see a Foo.pen source file and a pen.json file for package configuration.
Foo.pen:
Add = \(x number, y number) number {
x + y
}
pen.json:
{
"type": "library",
"dependencies": {}
}
In this example, the Foo.pen file contains an Add function that adds two numbers. And the pen.json configuration file defines a package type of library and its dependencies of none.
Publishing a package
The easiest way to publish your library package is to push the package as a Git repository onto one of Git repository hosting services, such as GitHub.
git add .
git commit
git remote add origin ssh://git@github.com/your-name/foo
git push
Now, your package is ready for use by other packages!