Code Monkey home page Code Monkey logo

dune's Introduction

Dune

Dune is an open-source, cross-platform, shell around the V8 engine, written in Rust and capable of running JavaScript (dah) and TypeScript code out of the box.

Developed completely for fun and experimentation.

GitHub GitHub Workflow Status

Installation

Mac, Linux:

curl -fsSL https://raw.githubusercontent.com/aalykiot/dune/main/install.sh | sh

Windows

You have to manually download and unzip the release build.

A powershell installation script is coming soon.

From Source:

Clone the repo and build it using Cargo.

git clone https://github.com/aalykiot/dune.git && cd ./dune && cargo release

Make sure to create a .dune directory under your user.

Getting Started

A simple example.

import shortid from 'https://cdn.skypack.dev/shortid';

console.log(shortid()); //=> "lXN1aGba2"

Another example using the net module.

import net from 'net';

const server = net.createServer(async (socket) => {
  console.log('Got new connection!');
  await socket.write('Hello! ๐Ÿ‘‹\n');
  await socket.destroy();
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Server is listening on port 3000...');
});

The complete API reference is in the next section.

Target API

Globals

  • global: reference to the global object.
  • globalThis: same as global.
  • console: a subset of the WHATWG console.
  • TextEncoder / TextDecoder: WHATWG encoding API.
  • setTimeout / setInterval / clearTimeout / clearInterval: DOM style timers.
  • setImmediate / clearImmediate: node.js like immediate timers.
  • process: an object that provides info about the current dune process.

Process

  • argv: an array containing the command-line arguments passed when the dune process was launched.
  • cwd(): current working directory.
  • env: an object containing the user environment.
  • exit([code]): exits the program with the given code.
  • getActiveResourcesInfo(): an array of strings containing the types of the active resources that are currently keeping the event loop alive.
  • memoryUsage(): an object describing the memory usage.
  • pid: PID of the process.
  • platform: a string identifying the operating system platform.
  • uptime(): a number describing the amount of time (in seconds) the process is running.
  • version: the dune version.
  • versions: an object listing the version strings of dune and its dependencies.
  • binding(module): exposes modules with bindings to Rust.
  • kill(pid, [signal]): sends the signal to the process identified by pid.
  • stdout: points to system's stdout stream.
  • stdin: points to system's stdin stream.
  • stderr: points to system's stderr stream.

File System

This module should also include a Sync method for every async operation available.

  • copyFile(src, dest): copies src to dest.
  • createReadStream(path, [options]): creates a readable IO stream.
  • createWriteStream(path, [options]): creates a writable IO stream.
  • open(path, [mode]): asynchronous file open.
  • mkdir(path, [options]): creates a directory.
  • readFile(path, [options]): reads the entire contents of a file.
  • rmdir(path, [options]): deletes a directory (must be empty).
  • rm(path, [options]): removes files and directories.
  • stat(path): retrieves statistics for the file.
  • writeFile(String|Uint8Array , data, [options]): writes data to the file, replacing the file if it already exists.

File

  • fd: the numeric file descriptor.
  • close(): closes the file.
  • createReadStream(): creates a readable IO stream.
  • createWriteStream(): creates a writable IO stream.
  • read([size, [offset]]): reads data from the file.
  • stat(): retrieves statistics for the file.
  • write(String|Uint8Array, [offset]): writes data to the file.

Net

  • createServer([connectionListener]): Creates a new TCP server.
  • createConnection(options, [connectionListener]): Creates unix socket connection to a remote host.

Net.Server

Net.Server is a class extending EventEmitter.

  • listen(port, [host], [callback]): Begin accepting connections on the specified port and host.
  • close([callback]): Stops the server from accepting new connections and keeps existing connections.
  • address(): Returns the bound address.
  • getConnections(): Get the number of concurrent connections on the server.
  • Event: 'listening': Emitted when the server has been bound after calling server.listen.
  • Event: 'connection': Emitted when a new connection is made.
  • Event: 'close': Emitted when the server closes.
  • Event: 'error': Emitted when an error occurs.

Net.Socket

Net.Socket is a class extending EventEmitter.

  • connect(options, [connectionListener]): Opens the connection for a given socket.
  • setEncoding(encoding): Set the encoding for the socket.
  • write(data, [callback]): Sends data on the socket.
  • end([data]): Half-closes the socket. i.e., it sends a FIN packet.
  • destroy(): Closes and discards the TCP socket stream.
  • address(): Returns the bound address.
  • remoteAddress: The string representation of the remote IP address.
  • remotePort: The numeric representation of the remote port.
  • bytesRead: The amount of received bytes.
  • bytesWritten: The amount of bytes sent.
  • Event: 'connect': Emitted when a socket connection is successfully established.
  • Event: 'data': Emitted when data is received.
  • Event: 'end': Emitted when the other end of the socket sends a FIN packet.
  • Event: 'error': Emitted when an error occurs.
  • Event: 'close': Emitted once the socket is fully closed.

Performance Measurement

  • timeOrigin: specifies the millisecond timestamp at which the current process began.
  • now(): returns the millisecond timestamp, where 0 represents the start of the current process.

Assert

The assertion API is copied from: https://assert-js.norbert.tech/

  • true(value): asserts that value is equal to true.
  • false(value): asserts that value is equal to false.
  • instanceOf(value, class): asserts that value is an instance of specific class.
  • integer(value): asserts that value is valid integer.
  • number(value): asserts that value is valid number (integer, float).
  • oddNumber(value): asserts that value is odd number.
  • evenNumber(value): asserts that value is event number.
  • greaterThan(value, limit): asserts that number is greater than.
  • greaterThanOrEqual(value, limit): asserts that number is greater than or equal.
  • lessThan(value, limit): asserts that number is less than.
  • lessThanOrEqual(value, limit): asserts that number is less than or equal.
  • string(value): asserts that value is valid string.
  • boolean(value): asserts that value is valid boolean.
  • equal(actual, expected): asserts that value is equal to expected value.
  • objectEqual(actual, expected): asserts that value is equal to expected value.
  • object(value): asserts that value is valid object.
  • hasFunction(name, object): asserts that object has function.
  • hasProperty(name, object): asserts that object has property.
  • isFunction(fn): asserts that value is valid function.
  • array(value): asserts that value is valid array.
  • count(expected, arrayValue): asserts that array have specific number of elements.
  • notEmpty(arrayValue): asserts that array is not empty.
  • throws(fn, error): asserts that function throws expected exception.

License

This project is licensed under the MIT license.

dune's People

Contributors

aalykiot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.