### Install Dependencies and Start Development Server Source: https://github.com/assemblyscript/website/blob/main/README.md Installs project dependencies and starts a local development server for the AssemblyScript website. ```sh npm install npm start ``` -------------------------------- ### Install AssemblyScript Compiler Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Install the AssemblyScript compiler as a development dependency. ```sh npm install --save-dev assemblyscript ``` -------------------------------- ### Start Web Server for Module Directory Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Start a local web server to serve the module directory and its contents, defaulting to `index.html`. ```sh npm start ``` -------------------------------- ### Install and Run http-server Source: https://github.com/assemblyscript/website/blob/main/src/examples/interference.md Install the http-server package and use it to serve your project locally, which can resolve issues with browsers restricting local fetch requests. ```bash npm install --save-dev http-server http-server . -o -c-1 ``` -------------------------------- ### startsWith Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Tests if the string starts with the specified string. If specified, `start` indicates the position at which to begin searching, acting as the start of the string. ```APIDOC ## startsWith ### Description Tests if the string starts with the specified string. If specified, `start` indicates the position at which to begin searching, acting as the start of the string. ### Method Signature ```ts function startsWith(search: string, start?: i32): bool ``` ``` -------------------------------- ### Initialize a New Node.js Project Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Use this command to initialize a new Node.js project before installing AssemblyScript. ```sh npm init ``` -------------------------------- ### indexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Gets the first index of the specified search string within the string, or -1 if not found. If specified, `start` indicates the position at which to begin searching. ```APIDOC ## indexOf ### Description Gets the first index of the specified search string within the string, or `-1` if not found. If specified, `start` indicates the position at which to begin searching. ### Method Signature ```ts function indexOf(search: string, start?: i32): i32 ``` ``` -------------------------------- ### Console Timer Start Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/console.md Starts a new timer using the specified label. This is the first step in measuring elapsed time. ```typescript function time(label?: string): void ``` -------------------------------- ### Importing ESM Bindings Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Example of how to import generated ESM bindings in JavaScript. ```javascript import * as myModule from "./build/mymodule.js" ``` -------------------------------- ### Compiling with Configuration File Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Example command to compile AssemblyScript using a specified configuration file and target. ```sh asc --config asconfig.json --target release ``` -------------------------------- ### trimStart / trimLeft Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Removes white space characters from the start of the string, returning the resulting string. ```APIDOC ## trimStart / trimLeft ### Description Removes white space characters from the start of the string, returning the resulting string. ### Method Signature ```ts function trimStart(): string function trimLeft(): string ``` ``` -------------------------------- ### Instantiate Module with Raw Bindings and Custom Imports Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md This example shows how to provide specific imports for a raw-bound WebAssembly module, mapping module paths to imported objects. ```javascript import { instantiate } from "./module.js" import * as other from "./otherfile.js" export const { export1, export2, ... } = await instantiate(await WebAssembly.compileStreaming(fetch("./module.wasm")), { "./otherfile.js": other }) ``` -------------------------------- ### Example 1: Using Array Created in WebAssembly Source: https://github.com/assemblyscript/website/blob/main/src/examples/arrays.md Demonstrates creating an array in WebAssembly, pinning it, randomizing its values, computing its sum, and unpinning it. Uses runtime helpers like `__pin`, `__unpin`, and `__getArray`. ```javascript ``` -------------------------------- ### getUTCMinutes() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the minute according to universal time. ```APIDOC ## getUTCMinutes(): i32 ### Description Gets the minute according to universal time. ### Returns (i32) - The minute (0-59). ``` -------------------------------- ### AssemblyScript Class Usage Source: https://github.com/assemblyscript/website/blob/main/src/examples/snippets.md Demonstrates defining and using classes with static properties and methods, as well as instance methods. Ensure the runtime is set to 'stub' for this example. ```assemblyscript #!runtime=stub class Animal { static ONE: i32 = 1; static add(a: i32, b: i32): i32 { return a + b + Animal.ONE; } two: i16 = 2; // 6 instanceSub(a: T, b: T): T { return a - b + Animal.ONE; } // tsc does not allow this } export function staticOne(): i32 { return Animal.ONE; } export function staticAdd(a: i32, b: i32): i32 { return Animal.add(a, b); } export function instanceTwo(): i32 { let animal = new Animal(); return animal.two; } export function instanceSub(a: f32, b: f32): f32 { let animal = new Animal(); return animal.instanceSub(a, b); } ``` ```html ``` -------------------------------- ### console.time Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/console.md Starts a new timer with a specified label. This is used to measure the duration of operations. ```APIDOC ## console.time ### Description Starts a new timer using the specified `label`. ### Signature ```ts function time(label?: string): void ``` ### Parameters - **label** (string, optional) - The label for the timer. ``` -------------------------------- ### AssemblyScript Configuration File (asconfig.json) Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md An example of an AssemblyScript configuration file, typically named 'asconfig.json'. It allows for defining compilation options, entry files, targets, and extending other configuration files. ```json { "extends": "./path/to/other/asconfig.json", // (optional) base config "entries": [ // (optional) entry files, e.g. "./assembly/index.ts" ], "options": { // common options, e.g. "importTable": true }, "targets": { // (optional) targets "release": { // additional options for the "release" target, e.g. "optimize": true, "outFile": "myModule.release.wasm" }, "debug": { // additional options for the "debug" target, e.g. "debug": true, "outFile": "myModule.debug.wasm" } } } ``` -------------------------------- ### includes Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Tests if the string includes the search string. If specified, `start` indicates the position at which to begin searching. ```APIDOC ## includes ### Description Tests if the string includes the search string. If specified, `start` indicates the position at which to begin searching. ### Method Signature ```ts function includes(search: string, start?: i32): bool ``` ``` -------------------------------- ### getUTCDate() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the day of the month according to universal time. ```APIDOC ## getUTCDate(): i32 ### Description Gets the day of the month according to universal time. ### Returns (i32) - The day of the month (1-31). ``` -------------------------------- ### AssemblyScript Editor Component Example Source: https://github.com/assemblyscript/website/blob/main/README.md Demonstrates the usage of the custom editor component with AssemblyScript code. The first line can include compiler options like optimization level, runtime variant, and enabled features. ```editor #!optimize=size&runtime=none&noAssert&explicitStart&enable=simd,reference-types export function add(a: i32, b: i32): i32 { return a + b } #!html ``` -------------------------------- ### Import AssemblyScript Module in Node.js Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Example of how to import a compiled AssemblyScript module as an ES module in a Node.js environment. ```js import * as myModule from "myModule"; ``` -------------------------------- ### Plain Object Binding Example Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Demonstrates how plain objects without constructors or non-public fields are copied to JavaScript objects. ```typescript class PlainObject { field: string; } export function getObject(): PlainObject { return { field: "hello world" }; } ``` -------------------------------- ### getUTCMonth() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the (zero indexed) month according to universal time. ```APIDOC ## getUTCMonth(): i32 ### Description Gets the (zero indexed) month according to universal time. ### Returns (i32) - The month (0-11). ``` -------------------------------- ### heap.alloc Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/heap.md Allocates a chunk of memory of at least the specified size. Returns the starting memory address of the allocated chunk. ```APIDOC ## heap.alloc ### Description Allocates a chunk of memory of at least the specified size. ### Signature ```typescript function heap.alloc(size: usize): usize ``` ### Parameters #### Path Parameters - **size** (usize) - Required - The minimum size of the memory chunk to allocate. ### Returns - **usize** - The starting memory address of the allocated chunk. ``` -------------------------------- ### substring Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Gets the part of the string in between `start` inclusive and `end` exclusive as a new string. ```APIDOC ## substring ### Description Gets the part of the string in between `start` inclusive and `end` exclusive as a new string. ### Method Signature ```ts function substring(start: i32, end?: i32): string ``` ``` -------------------------------- ### Type Inference and Assignability Example in AssemblyScript Source: https://github.com/assemblyscript/website/blob/main/src/types.md Demonstrates how AssemblyScript handles type inference and assignability between different integer and float types. Note that implicit conversions occur based on value range and type. ```typescript var i8val: i8 = -128 // 0x80 var u8val: u8 = i8val // becomes 128 (0x80) var i16val: i16 = i8val // becomes -128 through sign-extension (0xFF80) var u16val: u16 = i8val // becomes 65408 through masking (0xFF80) var f32val: f32 = i8val // becomes -128.0 ``` -------------------------------- ### Including AssemblyScript Compiler in Web Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Shows how to include the AssemblyScript compiler for use in web browsers by referencing the 'web.js' script. This setup allows for compilation directly within the browser environment. ```html ``` -------------------------------- ### Console Timer End Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/console.md Logs the current value of a timer started with `console.time` and then discards the timer. This is typically used to get the final elapsed time. ```typescript function timeEnd(label?: string): void ``` -------------------------------- ### Scaffold a New AssemblyScript Project Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Use the `asinit` utility to quickly set up a new AssemblyScript project structure and configuration files in the current directory. ```sh npx asinit . ``` -------------------------------- ### AssemblyScript Class Extension Source: https://github.com/assemblyscript/website/blob/main/src/examples/snippets.md Illustrates extending existing classes and general Object-Oriented Programming (OOP) concepts in AssemblyScript. This example requires the 'stub' runtime. ```assemblyscript #!runtime=stub class BaseClass { static staticProp: i32 = 24; instanceProp: i32; constructor(value: i32) { this.instanceProp = value; } add(a: i32, b: i32): i32 { return a + b; } } class ExtendedClass extends BaseClass { extendedProp: i32; constructor(extendedValue: i32) { super(1); this.extendedProp = extendedValue; } add(a: i32): i32 { return super.add(a, this.extendedProp + super.instanceProp); } } export function getStaticProp(): i32 { return ExtendedClass.staticProp; } export function overloadAdd(value: i32): i32 { let extendedClass = new ExtendedClass(value); return extendedClass.add(24); } ``` ```html ``` -------------------------------- ### lastIndexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Gets the last index of the specified search string within the string, or -1 if not found. If specified, `start` indicates the position at which to begin searching from right to left. ```APIDOC ## lastIndexOf ### Description Gets the last index of the specified search string within the string, or `-1` if not found. If specified, `start` indicates the position at which to begin searching from right to left. ### Method Signature ```ts function lastIndexOf(search: string, start?: i32): i32 ``` ``` -------------------------------- ### asinit Command Syntax and Options Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Provides syntax and options for the `asinit` command, including non-interactive usage with the `-y` flag. ```sh asinit directory [options] SYNTAX asinit directory [options] EXAMPLES asinit . asinit ./newProject -y OPTIONS --help, -h Prints this help message. --yes, -y Answers all questions with their default option for non-interactive usage. ``` -------------------------------- ### Build the AssemblyScript Website Source: https://github.com/assemblyscript/website/blob/main/README.md Builds the static site for deployment to the 'dist' directory. ```sh npm run build ``` -------------------------------- ### Get UTC Milliseconds Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the millisecond according to universal time. ```typescript getUTCMilliseconds(): i32 ``` -------------------------------- ### Equivalent C Memory Access Source: https://github.com/assemblyscript/website/blob/main/src/introduction.md A C code snippet showing equivalent memory manipulation to the AssemblyScript example, for comparison. ```c *(ptr + 2) = *ptr + *(ptr + 1) ``` -------------------------------- ### Static Memory Allocation Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Functions to get pointers to static memory chunks, either zeroed or pre-initialized. ```APIDOC ## memory.data(size: i32, align?: i32): usize ### Description Gets a pointer to a zeroed static chunk of memory of the given size. Alignment defaults to 16. Arguments must be compile-time constants. ### Method `memory.data(size: i32, align?: i32): usize` ### Parameters - **size** (i32) - The size of the memory chunk in bytes. - **align** (i32, optional) - The alignment requirement for the memory chunk. Defaults to 16. ### Return Value - **usize** - A pointer to the allocated static memory. ## memory.data(values: T[], align?: i32): usize ### Description Gets a pointer to a pre-initialized static chunk of memory. Alignment defaults to the size of `T`. Arguments must be compile-time constants. ### Method `memory.data(values: T[], align?: i32): usize` ### Parameters - **values** (T[]) - An array of values to pre-initialize the memory with. - **align** (i32, optional) - The alignment requirement for the memory chunk. Defaults to the size of type `T`. ### Return Value - **usize** - A pointer to the pre-initialized static memory. ``` -------------------------------- ### Get UTC Seconds Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the second according to universal time. ```typescript getUTCSeconds(): i32 ``` -------------------------------- ### DataView Constructor Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/dataview.md Constructs a new DataView on the specified buffer and region. The buffer is the ArrayBuffer to use, byteOffset is the offset in bytes from the start of the buffer, and byteLength is the length in bytes of the view. If byteOffset or byteLength are not provided, the entire buffer is used. ```APIDOC ## Constructor ### Signature ```ts new DataView(buffer: ArrayBuffer, byteOffset?: i32, byteLength?: i32) ``` ### Parameters * **buffer** (ArrayBuffer) - The ArrayBuffer to create the DataView on. * **byteOffset** (i32, optional) - The offset in bytes from the start of the buffer. * **byteLength** (i32, optional) - The length in bytes of the view. ``` -------------------------------- ### Get UTC Minutes Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the minute according to universal time. ```typescript getUTCMinutes(): i32 ``` -------------------------------- ### Get UTC Hours Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the hour according to universal time. ```typescript getUTCHours(): i32 ``` -------------------------------- ### AssemblyScript Switch Case Example Source: https://github.com/assemblyscript/website/blob/main/src/examples/snippets.md Demonstrates switch case statements in AssemblyScript. Note that switch conditions are implicitly converted to u32, and strings are not yet supported. Cases can use braces or not, and fall-through is supported. ```typescript #!runtime=stub export function switchSurprise(a: i32): i32 { let response = -1; // Using a mix of braces and not using braces // to show that both syntaxes are supported here. switch (a) { case 1: response = 100; break; case 2: { response = 200; break; } case 3: // Fall Through to the next case case 4: response = 400; break; default: { response = 0; } } return response; } ``` ```javascript ``` -------------------------------- ### Get Date Timestamp Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the UTC timestamp of this date in milliseconds. ```typescript getTime(): i64 ``` -------------------------------- ### Instantiate Module with Raw Bindings Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Use this when you have a pre-compiled WebAssembly module and need to instantiate it directly. Imports must be provided manually. ```javascript import { instantiate } from "./module.js" const exports = await instantiate(await WebAssembly.compileStreaming(fetch("./module.wasm")), { /* imports */ }) ``` -------------------------------- ### Get UTC Date Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the day of the month according to universal time. ```typescript getUTCDate(): i32 ``` -------------------------------- ### Configuration File and Target Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Specify a configuration file using `--config` or set the target configuration with `--target`. CLI arguments take precedence over configuration file settings. ```sh --config Configuration file to apply. CLI arguments take precedence. --target Configuration file target to use. Defaults to 'release'. ``` -------------------------------- ### Get UTC Month Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the zero-indexed month according to universal time. ```typescript getUTCMonth(): i32 ``` -------------------------------- ### padStart Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Pads the string with the contents of another string, possibly multiple times, until the resulting string reaches the specified length, returning the resulting string. ```APIDOC ## padStart ### Description Pads the string with the contents of another string, possibly multiple times, until the resulting string reaches the specified length, returning the resulting string. ### Method Signature ```ts function padStart(length: i32, pad: string): string ``` ``` -------------------------------- ### Get UTC Full Year Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the full year according to universal time. ```typescript getUTCFullYear(): i32 ``` -------------------------------- ### Static Type Checking Example Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Demonstrates using static type checks like `isString` within generic functions to enable branch elimination and compile-time type specialization. ```typescript function add(a: T, b: T): T { return a + b // addition if numeric, string concatenation if a string } function add(a: T, b: T): T { if (isString()) { // eliminated if T is not a string return parseInt(a) + parseInt(b) } else { // eliminated if T is a string return a + b } } ``` -------------------------------- ### Conditional Compilation with SIMD Feature Flag Source: https://github.com/assemblyscript/website/blob/main/src/concepts.md This example demonstrates how to use the `ASC_FEATURE_SIMD` flag for conditional compilation, providing a SIMD-optimized path and a fallback. ```typescript if (ASC_FEATURE_SIMD) { // compute with SIMD operations } else { // fallback without SIMD operations } ``` -------------------------------- ### Get UTC Day of Week Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the day of the week according to universal time, where 0 represents Sunday. ```typescript getUTCDay(): i32 ``` -------------------------------- ### at Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Gets the UTF-16 code unit at the specified position as a single character string. Allows for positive and negative integers. Negative integers count back from the last string character. ```APIDOC ## at ### Description Gets the UTF-16 code unit at the specified position as a single character string. This method allows for positive and negative integers. Negative integers count back from the last string character. ### Method Signature ```ts function at(pos: i32): string ``` ``` -------------------------------- ### process.env Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/process.md Map of variables in the binary's user environment. ```APIDOC ## process.env ### Description Map of variables in the binary's user environment. ### Type Map ``` -------------------------------- ### WebAssembly Instructions in AssemblyScript Source: https://github.com/assemblyscript/website/blob/main/src/introduction.md Illustrates how common WebAssembly instructions can be represented in AssemblyScript, including generic variants. ```typescript i32.ctz(...) // ctz(...) f64.reinterpret_i64(...) // reinterpret(...) i64.load32_u(...) // load(...) ... ``` -------------------------------- ### Get Static Memory Pointer (Values) Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Gets a pointer to a pre-initialized static chunk of memory. Alignment defaults to the size of T. Arguments must be compile-time constants. ```typescript function memory.data(values: T[], align?: i32): usize ``` -------------------------------- ### Serve Distribution Files Source: https://github.com/assemblyscript/website/blob/main/README.md Serves the built distribution files, useful for testing the production build locally. ```sh npm run serve ``` -------------------------------- ### Initialize Array with Default Values Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md When creating an array of a non-nullable reference type, ensure all elements are initialized before access to avoid errors. This example initializes a string array. ```typescript var arr = new Array(10) // arr[0]; // would error 😢 for (let i = 0; i < arr.length; ++i) { arr[i] = "" } arr[0]; // now it works 😊 ``` -------------------------------- ### Get Static Memory Pointer (Size) Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Gets a pointer to a zeroed static chunk of memory of the given size. Alignment defaults to 16. Arguments must be compile-time constants. ```typescript function memory.data(size: i32, align?: i32): usize ``` -------------------------------- ### process.argv Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/process.md Array of command line arguments passed to the binary upon instantiation. ```APIDOC ## process.argv ### Description Array of command line arguments passed to the binary upon instantiation. ### Type string[] ``` -------------------------------- ### ArrayBuffer.byteLength Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/arraybuffer.md Gets the length of the ArrayBuffer in bytes. ```APIDOC ## ArrayBuffer.byteLength ### Description The buffer's length, in bytes. ### Returns - **i32** - The length of the buffer in bytes. ``` -------------------------------- ### getUTCMilliseconds() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the millisecond according to universal time. ```APIDOC ## getUTCMilliseconds(): i32 ### Description Gets the millisecond according to universal time. ### Returns (i32) - The millisecond (0-999). ``` -------------------------------- ### Map Usage - AssemblyScript Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/map.md Demonstrates how to use Map, including handling non-existent keys. Accessing a non-existent key will cause an error, so check with `Map#has` first. ```typescript var map = new Map() // Because `undefined` cannot be represented if a key is not found, this will error: var str = map.get(1) // ERROR // The error can be avoided by first making sure that the key exists, so this works: var str: string | null = map.has(1) ? map.get(1) : null // OK ``` -------------------------------- ### Compiler Version and Help Flags Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Use the `--version` or `-v` flag to print the compiler's version and exit. Use `--help` or `-h` to display the help message and exit. ```sh --version, -v Prints just the compiler's version and exits. --help, -h Prints this message and exits. ``` -------------------------------- ### getUTCSeconds() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the second according to universal time. ```APIDOC ## getUTCSeconds(): i32 ### Description Gets the second according to universal time. ### Returns (i32) - The second (0-59). ``` -------------------------------- ### Programmatic Compiler Usage (Node.js) Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Demonstrates how to use the AssemblyScript compiler programmatically within a Node.js environment. It shows how to pass command-line options and additional API options to the 'asc.main' function. ```js import asc from "assemblyscript/asc"; const { error, stdout, stderr, stats } = await asc.main([ // Command line options "myModule.ts", "--outFile", "myModule.wasm", "--optimize", "--sourceMap", "--stats" ], { // Additional API options stdout?: ..., stderr?: ..., readFile?: ..., writeFile?: ..., listFiles?: ..., reportDiagnostic?: ..., transforms?: ... }); if (error) { console.log("Compilation failed: " + error.message); console.log(stderr.toString()); } else { console.log(stdout.toString()); } ``` -------------------------------- ### getUTCHours() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the hour according to universal time. ```APIDOC ## getUTCHours(): i32 ### Description Gets the hour according to universal time. ### Returns (i32) - The hour (0-23). ``` -------------------------------- ### getTime() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the UTC timestamp of this date in milliseconds. ```APIDOC ## getTime(): i64 ### Description Gets the UTC timestamp of this date in milliseconds. ### Returns (i64) - The UTC timestamp in milliseconds. ``` -------------------------------- ### Constructor Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md Constructs a new array with an optional initial capacity. ```APIDOC ## new Array(capacity?: i32) ### Description Constructs a new array. ### Parameters #### Path Parameters - **capacity** (i32) - Optional - The initial capacity of the array. ``` -------------------------------- ### Compile AssemblyScript to WebAssembly Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Compile your AssemblyScript code to WebAssembly using the `asbuild` command defined in `package.json`. ```sh npm run asbuild ``` -------------------------------- ### getUTCFullYear() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the full year according to universal time. ```APIDOC ## getUTCFullYear(): i32 ### Description Gets the full year according to universal time. ### Returns (i32) - The full year. ``` -------------------------------- ### process.platform Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/process.md String representing the operating system platform for which the binary was compiled. Always `wasm`. ```APIDOC ## process.platform ### Description String representing the operating system platform for which the binary was compiled. Always `wasm`. ### Type string ``` -------------------------------- ### process.arch Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/process.md String representing the CPU architecture for which the binary was compiled. Either `wasm32` or `wasm64`. ```APIDOC ## process.arch ### Description String representing the CPU architecture for which the binary was compiled. Either `wasm32` or `wasm64`. ### Type string ``` -------------------------------- ### TypedArray byteOffset field Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md The offset in bytes from the start of the backing buffer. ```typescript readonly byteOffset: i32 ``` -------------------------------- ### console.timeLog Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/console.md Logs the current value of a timer that was previously started with `console.time`. ```APIDOC ## console.timeLog ### Description Logs the current value of a timer previously started with `console.time`. ### Signature ```ts function timeLog(label?: string): void ``` ### Parameters - **label** (string, optional) - The label of the timer to log. ``` -------------------------------- ### Run AssemblyScript Project Tests Source: https://github.com/assemblyscript/website/blob/main/src/getting-started.md Execute the generated test cases for your AssemblyScript module using `npm test`. ```sh npm test ``` -------------------------------- ### Get Name of Type Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Returns the name of a given type as a string. ```typescript function nameof(value?: T): string ``` -------------------------------- ### Specify Output Files Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Define output file names for WebAssembly binary (`--outFile` or `-o`) and text format (`--textFile` or `-t`). ```sh --outFile, -o Specifies the WebAssembly output file (.wasm). --textFile, -t Specifies the WebAssembly text output file (.wat). ``` -------------------------------- ### size Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/set.md Gets the current number of unique values stored in the set. ```APIDOC ## size ### Description The current number of unique values in the set. ### Type ```typescript readonly size: i32 ``` ``` -------------------------------- ### Calling AssemblyScript Exports from JavaScript Source: https://github.com/assemblyscript/website/blob/main/src/concepts.md Demonstrates how to call exported functions from an AssemblyScript module within a JavaScript host environment after instantiation. ```javascript const { instance: { exports } } = await WebAssembly.instantiateStreaming(...) console.log(exports.add(1, 2)) ``` -------------------------------- ### includes Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md Tests if the array includes the specified value, optionally providing a starting index. ```APIDOC ## includes ### Description Tests if the array includes the specified value, optionally providing a starting index. ### Signature ```ts function includes(value: T, fromIndex?: i32): bool ``` ``` -------------------------------- ### Constructor Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md Constructs a new typed array view with a new backing buffer and all values initialized to zero. ```APIDOC ## new TypedArray(length: i32) ### Description Constructs a new typed array view with a new backing buffer and all values initialized to zero. See `wrap` below for wrapping a raw buffer. ### Parameters #### Path Parameters - **length** (i32) - Required - The length of the typed array. ``` -------------------------------- ### includes Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Tests if the array includes the specified value, optionally providing a starting index. ```APIDOC ## includes ### Description Determines whether an array includes a certain value among its entries, returning true or false as appropriate. ### Parameters #### Path Parameters - **value** (T) - Required - The value to search for. - **fromIndex** (i32) - Optional - The index to start the search from. ``` -------------------------------- ### Specify Entry File for Compilation Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Provide the entry file name as a non-option argument to the `asc` compiler. Multiple entry files can be specified to create a single WebAssembly module with combined exports. ```sh asc entryFile.ts ``` -------------------------------- ### includes Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md Tests if the array includes the specified value, optionally providing a starting index. ```APIDOC ## includes ### Description Tests if the array includes the specified value, optionally providing a starting index. ### Method `Array.prototype.includes(value: T, fromIndex?: i32): bool` ``` -------------------------------- ### v128 Constructor Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Initializes a 128-bit vector from sixteen 8-bit integer values. Arguments must be compile-time constants. ```APIDOC ## v128 Constructor ### Description Initializes a 128-bit vector from sixteen 8-bit integer values. Arguments must be compile-time constants. ### Signature ```typescript function v128(a: i8, ... , p: i8): v128 ``` ### Parameters * **a** (i8) - The first 8-bit integer value. * **...p** (i8) - The remaining 8-bit integer values (up to 16 total). ### Returns * **v128** - A 128-bit vector initialized with the provided values. ``` -------------------------------- ### trim Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Removes white space characters from both the start and the end of the string, returning the resulting string. ```APIDOC ## trim ### Description Removes white space characters from both the start and the end of the string, returning the resulting string. ### Method Signature ```ts function trim(): string ``` ``` -------------------------------- ### instantiate Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Instantiates a new instance of type `T` using the specified constructor arguments. ```APIDOC ## instantiate(...args: auto[]): T ### Description Instantiates a new instance of `T` using the specified constructor arguments. ### Signature ```typescript function instantiate(...args: auto[]): T ``` ``` -------------------------------- ### Update index.html for Streaming Instantiation Source: https://github.com/assemblyscript/website/blob/main/src/examples/interference.md Modify the instantiation logic in index.html to use WebAssembly.instantiateStreaming for direct loading, bypassing the loader when no managed objects are exchanged. ```javascript WebAssembly.instantiateStreaming(fetch('./build/optimized.wasm'), { JSMath: Math }).then(({ exports }) => { ``` -------------------------------- ### copyWithin Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Copies a region of an array's values over the respective values starting at the target location. ```APIDOC ## copyWithin ### Description Copies a portion of the array to another location within the same array. ### Parameters #### Path Parameters - **target** (i32) - Required - The index to which the copied values will be assigned. - **start** (i32) - Required - The index from which to start copying values. - **end** (i32) - Optional - The index at which to stop copying values (exclusive). ``` -------------------------------- ### copyWithin Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md Copies a region of an array's values over the respective values starting at the target location. ```APIDOC ## copyWithin ### Description Copies a region of an array's values over the respective values starting at the target location. ### Method `Array.prototype.copyWithin(target: i32, start: i32, end?: i32): this` ``` -------------------------------- ### Constructor Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Constructs a new static array with a specified fixed length. ```APIDOC ## new StaticArray(length: i32) ### Description Constructs a new static array. ### Parameters #### Path Parameters - **length** (i32) - Required - The fixed length of the static array. ``` -------------------------------- ### Enable Source Maps and Debug Information Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Generate source maps with `--sourceMap` for easier debugging. Embed debug symbols in binaries using the `--debug` flag. ```sh --sourceMap Enables source map generation. Optionally takes the URL used to reference the source map from the binary file. --debug Enables debug information in emitted binaries. ``` -------------------------------- ### lastIndexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Gets the last index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## lastIndexOf ### Description Returns the last index at which a given element can be found in the array, or -1 if it is not present. ### Parameters #### Path Parameters - **value** (T) - Required - The value to search for. - **fromIndex** (i32) - Optional - The index to start the search from. ``` -------------------------------- ### Convert to ISO String Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Returns a string in simplified extended ISO 8601 format. ```typescript toISOString(): string ``` -------------------------------- ### lastIndexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md Gets the last index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## lastIndexOf ### Description Gets the last index where the specified value can be found in the array. Returns `-1` if not found. ### Signature ```ts function lastIndexOf(value: T, fromIndex?: i32): i32 ``` ``` -------------------------------- ### indexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md Gets the first index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## indexOf ### Description Gets the first index where the specified value can be found in the array. Returns `-1` if not found. ### Signature ```ts function indexOf(value: T, fromIndex?: i32): i32 ``` ``` -------------------------------- ### Manual Optimization and Shrink Levels Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Fine-tune optimization and code shrinking. `--optimizeLevel` ranges from 0-3, and `--shrinkLevel` ranges from 0-2 (with 's' for 1 and 'z' for 2). Use `--converge` to re-optimize until no further improvements are made. ```sh --optimizeLevel How much to focus on optimizing code. [0-3] --shrinkLevel How much to focus on shrinking code size. [0-2, s=1, z=2] --converge Re-optimizes until no further improvements can be made. ``` -------------------------------- ### indexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Gets the first index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## indexOf ### Description Returns the first index at which a given element can be found in the array, or -1 if it is not present. ### Parameters #### Path Parameters - **value** (T) - Required - The value to search for. - **fromIndex** (i32) - Optional - The index to start the search from. ``` -------------------------------- ### padEnd Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Pads the string with the contents of another string, possibly multiple times, until the resulting string reaches the specified length, returning the resulting string. ```APIDOC ## padEnd ### Description Pads the string with the contents of another string, possibly multiple times, until the resulting string reaches the specified length, returning the resulting string. ### Method Signature ```ts function padEnd(length: i32, pad: string): string ``` ``` -------------------------------- ### lastIndexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md Gets the last index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## lastIndexOf ### Description Gets the last index where the specified value can be found in the array. Returns `-1` if not found. ### Method `Array.prototype.lastIndexOf(value: T, fromIndex?: i32): i32` ``` -------------------------------- ### indexOf Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/array.md Gets the first index where the specified value can be found in the array. Returns `-1` if not found. ```APIDOC ## indexOf ### Description Gets the first index where the specified value can be found in the array. Returns `-1` if not found. ### Method `Array.prototype.indexOf(value: T, fromIndex?: i32): i32` ``` -------------------------------- ### charCodeAt Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/string.md Gets the UTF-16 code unit at the specified position as a number. Returns -1 if out of bounds. ```APIDOC ## charCodeAt ### Description Gets the UTF-16 code unit at the specified position as a number. Returns `-1` if out of bounds. ### Method Signature ```ts function charCodeAt(pos: i32): i32 ``` ``` -------------------------------- ### ESM Bindings File Structure Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Shows the expected file structure when using `--bindings esm`, where the JavaScript bindings file is adjacent to the WebAssembly binary. ```plaintext build/mymodule.js build/mymodule.wasm ``` -------------------------------- ### Generate Bindings Source: https://github.com/assemblyscript/website/blob/main/src/compiler.md Generate JavaScript and TypeScript bindings using `--bindings` or `-b`. Use `esm` for ESM integration or `raw` for a simplified instantiate function export. ```sh --bindings, -b Specifies the bindings to generate (.js + .d.ts). esm JavaScript bindings & typings for ESM integration. raw Like esm, but exports just the instantiate function. Useful where modules are meant to be instantiated multiple times or non-ESM imports must be provided. ``` -------------------------------- ### getUTCDay() Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/date.md Gets the day of the week in the specified date according to universal time, where 0 represents Sunday. ```APIDOC ## getUTCDay(): i32 ### Description Gets the day of the week in the specified date according to universal time, where 0 represents Sunday. ### Returns (i32) - The day of the week (0-6). ``` -------------------------------- ### process.time Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/process.md Obtains the system's current time of day, in milliseconds since Unix epoch. ```APIDOC ## process.time(): i64 ### Description Obtains the system's current time of day, in milliseconds since Unix epoch. ### Returns i64 - The current time in milliseconds since Unix epoch. ``` -------------------------------- ### fill Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/typedarray.md Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array. ```APIDOC ## fill ### Description Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array. ### Signature ```ts function fill(value: T, start?: i32, end?: i32): this ``` ``` -------------------------------- ### v128.load_ext Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/globals.md Creates a vector by loading lanes of a specified integer type and extending them to the next larger type. ```APIDOC ## v128.load_ext ### Description Loads a value of the specified integer type `TFrom` from memory, extends each lane to the next larger integer type, and places the result into a 128-bit vector. ### Signature ```typescript function v128.load_ext(ptr: usize, immOffset?: usize, immAlign?: usize): v128 ``` ### Parameters * **TFrom** - The source integer type to load from memory (e.g., i8, u8, i16, u16, i32, u32). * **ptr** (usize) - The memory address from which to load the data. * **immOffset** (usize, optional) - An optional immediate offset to apply to the pointer. * **immAlign** (usize, optional) - An optional immediate alignment value for the memory access. ### Returns * **v128** - A 128-bit vector containing the extended loaded values. ### Supported Types and Instructions | TFrom | Instruction |-------|------------- | i8 | v128.load8x8_s | u8 | v128.load8x8_u | i16 | v128.load16x4_s | u16 | v128.load16x4_u | i32 | v128.load32x2_s | u32 | v128.load32x2_u ``` -------------------------------- ### fill Source: https://github.com/assemblyscript/website/blob/main/src/stdlib/staticarray.md Replaces the values of the array from `start` inclusive to `end` exclusive in place with the specified value, returning the array. ```APIDOC ## fill ### Description Fills all the elements of an array from a start index to an end index with a static value. ### Parameters #### Path Parameters - **value** (T) - Required - The value to fill the array with. - **start** (i32) - Optional - The index to start filling at (inclusive). - **end** (i32) - Optional - The index to stop filling at (exclusive). ```