Class “Module”
Represents a JavaScript module as outlined in the commonJS standard.
Type: | Module extends Object |
Constructor: | public |
Singleton: | No |
Namespace: | tabris |
Direct subclasses: | None |
JSX Support: | No |
See also:
Constructor
new Module(id, parent, content)
Parameter | Type | Description |
---|---|---|
id | string |
|
parent | Module | null |
|
content | ModuleLoader | object |
Methods
require(request)
Finds a module relative to the id of this module and returns the exports object of that module. Throws if no matching module can be found.
Parameter | Type | Description |
---|---|---|
request | string |
Returns: object
Static Methods
createLoader(url)
Loads the given JavaScript file from the given (local or http) url and wraps it as a module loader function.
Parameter | Type | Description |
---|---|---|
url | string |
Returns: ModuleLoader
createRequire(path)
Creates a “require” function that finds a module relative to the given path. If found the exports are returned. Throws if no matching module can be found.
Parameter | Type | Description |
---|---|---|
path | string |
An absolute path, beginning with “/”. The path does not have to point to an existing file. |
execute(code, url)
Evaluates the given JavaScript code and returns the result of the last expression. The url is used to identify the source in stack traces.
Parameter | Type | Description |
---|---|---|
code | string |
|
url | string |
Returns: unknown
getSourceMap(url)
Returns the source map object (decoded from base64 and parsed from JSON) for the JavaScript file of the given url. Returns null
if no source map can be found. This method only works with code side-loaded via the tabris CLI serve
command.
Parameter | Type | Description |
---|---|---|
url | string |
Returns: unknown
load(url)
Loads a text from the given (local or http) url and returns its content. File is expected to be utf-8 encoded. This is a blocking operation, in almost all cases it is preferable to use fetch()
or the file system API to read a text file.
Parameter | Type | Description |
---|---|---|
url | string |
Returns: string
readJSON(url)
Loads the JSON file from the given (local or http) url, parses it and returns the result. This is a blocking operation, in almost all cases it is preferable to use fetch()
or the file system API to obtain and parse a JSON file.
Parameter | Type | Description |
---|---|---|
url | string |
Returns: unknown
Properties
exports
Type: | object |
Settable: | No |
This property can only be set via constructor. Once set, it cannot change anymore.
id
Full id (path) of the module
Type: | string |
Settable: | No |
This property can only be set via constructor. Once set, it cannot change anymore.
parent
The module that first required this module
Type: | Module |
Settable: | No |
This property can only be set via constructor. Once set, it cannot change anymore.