Class SwitchClass

Hierarchy

Constructors

  • Private

    Returns SwitchClass

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
screen: Canvas

An instance of Canvas that will result in drawing to the screen.

The width and height properties are set to the Switch screen resolution.

Note

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.

version: Versions

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

Methods

  • 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 specified by the hostname and port.

    Parameters

    • connectOpts: ConnectOpts

      Object containing the port number and hostname (defaults to 127.0.0.1) to connect to.

    Returns Promise<number>

    Promise that is fulfilled once the connection has been successfully established.

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

    Returns string

    Example

    "sdmc:/switch/"
    
  • 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.

    MDN Reference

    Parameters

    Returns boolean

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

  • Parameters

    • fd: number
    • buffer: BufferSource

    Returns Promise<number>

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

  • 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

  • Parameters

    • fd: number
    • data: string | BufferSource

    Returns Promise<number>

  • 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