Private
constructorPrivate
[ "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 instance of Canvas that will result in drawing to the screen.
The width
and height
properties are set to the Switch screen resolution.
Calling the getContext('2d')
method on this canvas switches to canvas rendering mode. When in this mode, avoid using any console methods, as they will switch back to text rendering mode.
An Object containing the versions numbers of nx.js and all supporting C libraries.
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
.
Optional
opts: SocketOptionsDispatches 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));
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
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.