erland.ts
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

banner

Erland TypeScript

TypeScript client for Erland.

Usage

You can also define async callbacks.

Start Connection

// Construct the playground manager
const manager = new PlaygroundManager('ws://localhost:8080/');

// Connect to the playground and wait until
// playground is ready to receive messages
await manager.connect();

Create Playground

// Creates new playground named "example" for Erlang programming
// language. If it gives an error, returns it as a string
manager.create({
  name: 'example',
  env: 'erlang',
  callback: (response) => {
    if (response.type === 'error') {
      console.error('Found error:', response.data);
    }
  },
});

Update Playground

// Dependencies to use (playground uses hex.pm)
const dependencies = {
  surreal: 'v1.0.0',
};

// Create a file content
const content = 'main(_Args) -> io:format("WoW!~n").';

// Set our file content and dependencies
manager.update({
  name: 'example',
  content,
  dependencies,
  callback: (response) => {
    if (response.type === 'error') {
      console.error('Found error:', response.data);
    }
  },
});

Run Playground

manager.run({
  name: 'example',
  callback: (response) => {
    if (response.type === 'error') {
      console.log('Found error:', response.data);
    } else if (response.type === 'data') {
      // Output packet from playground
      console.error(response.data);
    }
  },
});

Remove Playground

// Tries to remove playground
manager.remove({
  name: 'example',
  callback: (response) => {
    if (response.type === 'error') {
      console.log('Found error:', response.data);
    } else {
      console.log('OK');
    }
  },
});

Contributing

You can always report bugs and request features via GitHub Issues.

For pull requests, make sure your code is well-formatted and at least can explain itself.

License

Erland.ts is licensed under the MIT License.

Package Sidebar

Install

npm i erland.ts

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

11.2 kB

Total Files

5

Last publish

Collaborators

  • tuhana