Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builtin module #168

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions builtin/array.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
init(data: [any]){}

function contains(data: any): boolean;

function index(data: any): integer;

function length(): integer;

function get(index: integer): $type;

function join(sep: string): string;

function full(data: any): [ $type ];

function shift(): $type;

function pop(): $type;

function push(data: any): integer;

function unshift(data: any): integer;

function concat(data: any): [ $type ];

function sort(order: string): [ $type ];

function append(data: any, index: integer): void;

function remove(data: any): void;
13 changes: 13 additions & 0 deletions builtin/bytes.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
init(data: bytes){}

function toString(): string;

function toHex(): string;

function toBase64(): string;

function length(): integer;

function toJSON(): string;

static function from(data: string, type: string): bytes;
41 changes: 41 additions & 0 deletions builtin/crypto.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* HmacSHA1 Signature
* @param stringToSign string
* @param secret string
* @return signed bytes
*/
static function HmacSHA1Sign(stringToSign: string, secret: string): bytes;


/**
* HmacSHA256 Signature
* @param stringToSign string
* @param secret string
* @return signed bytes
*/
static function HmacSHA256Sign(stringToSign: string, secret: string): bytes;


/**
* HmacSM3 Signature
* @param stringToSign string
* @param secret string
* @return signed bytes
*/
static function HmacSM3Sign(stringToSign: string, secret: string): bytes;


/**
* SHA256withRSA Signature
* @param stringToSign string
* @param secret string
* @return signed bytes
*/
static function SHA256withRSASign(stringToSign: string, secret: string): bytes;

/**
* MD5 Signature
* @param stringToSign string
* @return signed bytes
*/
static function MD5Sign(stringToSign: string): bytes;
33 changes: 33 additions & 0 deletions builtin/date.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
init(date: string) {}

function format(format: string): string;

function unix(): integer;

function diff(unit: string, date: $Date): integer;

function UTC(): string;

function add(unit: string, timeLong: integer): $Date;

function sub(unit: string, timeLong: integer): $Date;

function hour(): integer;

function minute(): integer;

function second(): integer;

function dayOfYear(): integer;

function dayOfMonth(): integer;

function dayOfWeek(): integer;

function weekOfYear(): integer;

function weekOfMonth(): integer;

function month(): integer;

function year(): integer;
6 changes: 6 additions & 0 deletions builtin/entry.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
init(key: string, value: any) {}

function key(): string;

function value(): $type;

18 changes: 18 additions & 0 deletions builtin/env.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This is a env module
*/

/**
* Get environment variable according to the key
* @param key the name of environment variable
* @return environment variable
*/
static function get(key: string): string;

/**
* Get environment variable according to the key
* @param key the name of environment variable
* @param value the value of environment variable
* @return void
*/
static function set(key: string, value: string) throws: void;
19 changes: 19 additions & 0 deletions builtin/file.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
init(path: string) {}

function path(): string;

function length(): integer;

function createTime(): $Date;

function modifyTime(): $Date;

function read(size: number): bytes;

function write(data: bytes): void;

static async function createReadStream(path: string): readable;

static async function createWriteStream(path: string): writable;

static async function exists(path: string): boolean;
19 changes: 19 additions & 0 deletions builtin/form.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Format a map to form string, like a=a%20b%20c
* @return the form string
*/
static function toFormString(val: object): string;

/**
* Gets a boundary string
* @return the random boundary string
*/
static function getBoundary(): string;

/**
* Give a form and boundary string, wrap it to a readable stream
* @param form The form map
* @param boundary the boundary string
* @return the readable from file form
*/
static function toFileForm(form: object, boundary: string): readable;
11 changes: 11 additions & 0 deletions builtin/json.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Parse it by JSON format
* @return the parsed result
*/
static function parseJSON(val: string): any;

/**
* Stringify a value by JSON format
* @return the JSON format string
*/
static function stringify(val: any): string;
43 changes: 43 additions & 0 deletions builtin/logger.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This is a console module
*/

/**
* Console val with log level into stdout
* @param val the printing string
* @return void
* @example \[LOG\] tea console example
*/
static function log(val: string): void;

/**
* Console val with info level into stdout
* @param val the printing string
* @return void
* @example \[INFO\] tea console example
*/
static function info(val: string): void;

/**
* Console val with warning level into stdout
* @param val the printing string
* @return void
* @example \[WARNING\] tea console example
*/
static function warning(val: string): void;

/**
* Console val with debug level into stdout
* @param val the printing string
* @return void
* @example \[DEBUG\] tea console example
*/
static function debug(val: string): void;

/**
* Console val with error level into stderr
* @param val the printing string
* @return void
* @example \[ERROR\] tea console example
*/
static function error(val: string): void;
9 changes: 9 additions & 0 deletions builtin/map.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
init(data: any){}

function length(): integer;

function keySet(): [ string ];

function entries(): [ entry[ $type ] ];

function toJSON(): string;
23 changes: 23 additions & 0 deletions builtin/number.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
init(data: number){}

function parseInt(): integer;

function parseLong(): long;

function parseFloat(): float;

function parseDouble(): double;

function itol(): long;

function ltoi(): integer;

static function random(): number;

static function floor(num: number): integer;

static function round(num: number): integer;

static function min(a: number, b: number): number;

static function max(a: number, b: number): number;
28 changes: 28 additions & 0 deletions builtin/stream.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
init(){}

function read(size: number): bytes;

function write(data: bytes): void;

function pipe(rs: writable): void;

/**
* Read data from a readable stream, and compose it to a bytes
* @param stream the readable stream
* @return the bytes result
*/
static async function readAsBytes(stream: readable): bytes;

/**
* Read data from a readable stream, and parse it by JSON format
* @param stream the readable stream
* @return the parsed result
*/
static async function readAsJSON(stream: readable): any ;

/**
* Read data from a readable stream, and compose it to a string
* @param stream the readable stream
* @return the string result
*/
static async function readAsString(stream: readable): string;
42 changes: 42 additions & 0 deletions builtin/string.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
init(data: string){}

function split(sep: string, limit: number): [ string ];

function replace(oldStr: string, newStr: string, count: integer): string;

function contains(substr: string): boolean;

function length(): integer;

function hasPrefix(prefix: string): boolean;

function hasSuffix(substr: string): boolean;

function index(substr: string): integer;

function toLower(): string;

function toUpper(): string;

function subString(start: integer, end: integer): string;

function equals(actual: string): boolean;

function trim(): string;

/**
* @param encoding string, eg: UTF-8
* @return result bytes
*/

function toBytes(encoding: string): bytes;

function empty(): boolean;

function parseInt(): integer;

function parseLong(): long;

function parseFloat(): float;

function parseDouble(): double;
27 changes: 27 additions & 0 deletions builtin/url.dara
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
init(url: string) {}

function format(type: string): string;

function path(): string;

function pathname(): string;

function protocol(): string;

function hostname(): string;

function hash(): string;

function search(): string;

function href(): string;

function auth(): string;

static function parse(url: string): $URL;

static function urlEncode(url: string): string;

static function percentEncode(raw: string): string;

static function pathEncode(path: string): string;
Loading