Function init

  • Creates, initializes, and returns a SettingsManager for the given settings namespace. If a manager for the namespace already exists, then that instance will be returned. Use this function rather than creating instances of SettingsManager directly.

    Settings are stored synchronously in the window, and updates are dispatched asynchronously to the file system. See SettingsManager for more information on how this works.

    Here's an example of how to use this in a plugin:

    import { settings } from "replugged";

    const defaultSettings = {
    hello: "world",
    };

    const cfg = await settings.init<{ hello: string; something: string }, "something">(
    "dev.replugged.Example",
    { something: "everything" },
    );

    export function start() {
    cfg.set("hello", "world");
    console.log(cfg.get("hello")); // world

    cfg.get("hello", "world"); // "world" will be used if there is no value for hello
    cfg.get("something"); // "everything" will be used if there is no value for something
    }

    Type Parameters

    • T extends Record<string, Jsonifiable>

      Type definition for the settings to manage in the namespace. This will be an object with strings as keys, and JSON-serializable values.

    • D extends string | number | symbol = never

      Keys in T that will always have a value. These keys will not be nullable.

    Parameters

    • namespace: string

      Namespace to manage. A namespace is an ID (for example, the ID of a plugin) that uniquely identifies it. All settings are grouped into namespaces. Settings for a namespace are stored in settings/NAMESPACE.json within the Replugged data folder.

    • Optional defaultSettings: Partial<T>

      Default values for the settings in the namespace. These will be used if no value is set for a setting. Using the fallback parameter of get() will override these defaults.

    Returns Promise<SettingsManager<T, D>>

    Manager for the namespace.

Generated using TypeDoc