DataStore namespace
League Client does not store user data on disk, similar to incognito mode in web browsers. This namespace helps you to store user data on disk.
DataStore.set()
functionsince v1.0.1function set(key: string, data: any): Promise<void>
Asynchronously stores data associated with the specified key.
Parameters
key
(string) The key under which the data will be stored. Keys must be unique across all plugins to avoid conflicts.data
(any) The value to store. Supported types include:- Primitive types: string, number, boolean, null
- Collections: arrays, objects
All data is serialized into JSON format, so non-serializable types such as functions and runtime objects will be ignored.
Returns
A void Promise that resolves once the data is successfully stored.
Example
let my_num = 10
let my_str = 'hello'
DataStore.set('my_num', my_num)
DataStore.set('my_str', my_str)
Remarks
To avoid data conflicts, use unique and descriptive key names, preferably prefixed with your plugin’s identifier. For example, use plugin-name/user-settings
instead of generic names like settings
or data
.
For multiple data entries such as config or user settings, you should store them in an object.
let config = { a: 10, b: 'hello' }
DataStore.set('my-config', config)
DataStore.get()
functionsince v1.0.1function get<T = any>(key: string, fallback?: T): T
Retrieves stored data by key. If the key does not exist, the function will return undefined or an optional fallback value.
Parameters
key
(string) The key associated with the data.fallback
(T) (optional) A default value to return if the key does not exist.
Returns
The stored data, or the fallback value if the key is missing.
Example
console.log(DataStore.get('my_str'))
// some string
console.log(DataStore.get('key-does-not-exist'))
// undefined
Since v1.0.5, you can set fallback value for non-existent keys.
console.log(DataStore.get('key-does-not-exist', 1000))
// 1000
DataStore.has()
functionsince v1.0.1function has(key: string): boolean
Checks if a specific key exists in the storage.
Parameters
key
(string) The key to check.
Returns
A boolean value indicating whether the key exists.
Example
console.log(DataStore.has('my_num'))
console.log(DataStore.has('key-does-not-exist'))
DataStore.remove()
functionsince v1.0.1function remove(key: string): Promise<boolean>
Asynchronously removes a key-value pair from storage.
Parameters
key
(string) The key of the data to remove.
Returns
A boolean Promise that resolves to:
true
if the key was found and removed.false
if the key does not exist.
Example
await DataStore.remove('some-key')
DataStore.has('some-key') // -> false