Private
constructorPrivate
Array of the arguments passed to the process. Under normal circumstances, this array contains a single entry with the absolute path to the .nro
file.
[ "sdmc:/switch/nxjs.nro" ]
String value of the entrypoint JavaScript file that was evaluated. If a main.js
file is present on the application's RomFS, then that will be executed first, in which case the value will be romfs:/main.js
. Otherwise, the value will be the path of the .nro
file on the SD card, with the .nro
extension replaced with .js
.
"romfs:/main.js"
"sdmc:/switch/nxjs.js"
A Map-like object providing methods to interact with the environment variables of the process.
Signals for the nx.js application process to exit. The "exit" event will be invoked once the event loop is stopped.
Contains the available fonts for use on the screen Canvas context.
By default, "system-ui"
is the only font available, which is the system font provided by the Switch operating system.
See the fonts application for an example of using custom fonts.
Inspects a given value and returns a string representation of it. The function uses ANSI color codes to highlight different parts of the output. It can handle and correctly output different types of values including primitives, functions, arrays, and objects.
The value to inspect.
Optional
opts: InspectOptionsOptions which may modify the generated string representation of the value.
A string representation of v
with ANSI color codes.
An Object containing the versions numbers of nx.js and all supporting C libraries.
Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Optional
options: boolean | AddEventListenerOptionsOptional
options: boolean | AddEventListenerOptionsChanges the current working directory to the specified path.
Switch.chdir('sdmc:/switch/awesome-app/images');
Creates a TCP connection to the specified address
.
Hostname and port number of the destination TCP server to connect to.
Optional
opts: SocketOptionsOptional
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault()
method was not invoked, and false otherwise.
Prints the string str
to the console, without a trailing newline.
You will usually want to use the console methods instead.
Invoking this method switches the application to text rendering mode, which clears any pixels previously drawn on the screen using the Canvas API.
Synchronously returns an array of the file names within path
.
for (const file of Switch.readDirSync('sdmc:/')) {
// … do something with `file` …
}
Returns a Promise which resolves to an ArrayBuffer
containing
the contents of the file at path
.
const buffer = await Switch.readFile('sdmc:/switch/awesome-app/state.json');
const gameState = JSON.parse(new TextDecoder().decode(buffer));
Synchronously returns an ArrayBuffer
containing the contents
of the file at path
.
const buffer = Switch.readFileSync('sdmc:/switch/awesome-app/state.json');
const appState = JSON.parse(new TextDecoder().decode(buffer));
Removes the event listener in target's event listener list with the same type, callback, and options.
Optional
options: boolean | EventListenerOptionsOptional
options: boolean | EventListenerOptionsVibrates the main gamepad for the specified number of milliseconds or pattern.
If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.
Provides a pattern of vibration and pause intervals. Each value indicates a number of milliseconds to vibrate or pause, in alternation. You may provide either a single value (to vibrate once for that many milliseconds) or an array of values to alternately vibrate, pause, then vibrate again.
// Vibrate for 200ms with the default amplitude/frequency values
Switch.vibrate(200);
// Vibrate 'SOS' in Morse Code
Switch.vibrate([
100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100,
]);
// Specify amplitude/frequency values for the vibration
Switch.vibrate({
duration: 500,
lowAmp: 0.2
lowFreq: 160,
highAmp: 0.6,
highFreq: 500
});
https://developer.mozilla.org/docs/Web/API/Navigator/vibrate
Synchronously writes the contents of data
to the file at path
.
const appStateJson = JSON.stringify(appState);
Switch.writeFileSync('sdmc:/switch/awesome-app/state.json', appStateJson);
Generated using TypeDoc
EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
See
https://developer.mozilla.org/docs/Web/API/EventTarget