Class SwitchClass

EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.

Hierarchy

Constructors

Properties

argv: string[]

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.

Example

[ "sdmc:/switch/nxjs.nro" ]
entrypoint: string

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.

Example

"romfs:/main.js"

Example

"sdmc:/switch/nxjs.js"
env: Env

A Map-like object providing methods to interact with the environment variables of the process.

exit: (() => never)

Type declaration

    • (): never
    • Signals for the nx.js application process to exit. The "exit" event will be invoked once the event loop is stopped.

      Returns never

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.

Demo

See the fonts application for an example of using custom fonts.

inspect: {
    custom: symbol;
    (v, opts?): string;
} = inspect

Type declaration

    • (v, opts?): string
    • 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.

      Parameters

      • v: unknown

        The value to inspect.

      • Optional opts: InspectOptions

        Options which may modify the generated string representation of the value.

      Returns string

      A string representation of v with ANSI color codes.

  • custom: symbol
version: Versions

An Object containing the versions numbers of nx.js and all supporting C libraries.

Methods

  • 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.

    Type Parameters

    • K extends keyof SwitchEventHandlersEventMap

    Parameters

    • type: K
    • listener: ((ev) => any)
        • (ev): any
        • Parameters

          • ev: SwitchEventHandlersEventMap[K]

          Returns any

    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Parameters

    • type: string
    • listener: EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Changes the current working directory to the specified path.

    Parameters

    Returns void

    Example

    Switch.chdir('sdmc:/switch/awesome-app/images');
    
  • Creates a TCP connection to the specified address.

    Type Parameters

    • Host extends string

    • Port extends string

    Parameters

    • address: SocketAddress | `${Host}:${Port}`

      Hostname and port number of the destination TCP server to connect to.

    • Optional opts: SocketOptions

      Optional

    Returns Socket

  • Returns the current working directory as a URL string with a trailing slash.

    Returns string

    Example

    "sdmc:/switch/"
    
  • Parameters

    Returns Server

  • Prints the string str to the console, without a trailing newline.

    You will usually want to use the console methods instead.

    Parameters

    • str: string

    Returns void

    Note

    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.

    Parameters

    Returns string[]

    Example

    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.

    Parameters

    Returns Promise<ArrayBuffer>

    Example

    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.

    Parameters

    Returns ArrayBuffer

    Example

    const buffer = Switch.readFileSync('sdmc:/switch/awesome-app/state.json');
    const appState = JSON.parse(new TextDecoder().decode(buffer));
  • Removes the file or directory specified by path.

    Parameters

    Returns Promise<void>

  • Removes the event listener in target's event listener list with the same type, callback, and options.

    Type Parameters

    • K extends keyof SwitchEventHandlersEventMap

    Parameters

    • type: K
    • listener: ((ev) => any)
        • (ev): any
        • Parameters

          • ev: SwitchEventHandlersEventMap[K]

          Returns any

    • Optional options: boolean | EventListenerOptions

    Returns void

  • Parameters

    • type: string
    • listener: EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Performs a DNS lookup to resolve a hostname to an array of IP addresses.

    Parameters

    • hostname: string

    Returns Promise<string[]>

    Example

    const ipAddresses = await Switch.resolveDns('example.com');
    
  • Returns a Promise which resolves to an object containing information about the file pointed to by path.

    Parameters

    Returns Promise<Stats>

  • Vibrates 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.

    Parameters

    • pattern: number | Vibration | (number | Vibration)[]

      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.

    Returns boolean

    Example

    // 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
    });

    See

    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);

    Parameters

    • path: PathLike
    • data: string | BufferSource

    Returns void

Generated using TypeDoc