# API

**Kind**: interface | **Module**: [App Preferences](https://docs.interop.io/desktop/reference/javascript/app%20preferences/index.md) | **Access**: `io.prefs`

**Source**: https://docs.interop.io/desktop/reference/javascript/app preferences/api/index.html

App Preferences API.

## Methods

### clear

Removes the user preferences for the current app.

```ts
() => Promise<void>
```

**Returns**: `Promise<void>`

### clearAll

Removes all preferences stored for the current user.

```ts
() => Promise<void>
```

**Returns**: `Promise<void>`

### clearFor

Removes the user preferences for a specified app.

```ts
(app: string) => Promise<void>
```

**Parameters**

- **`app`** (`string`, required)
  Name of the app whose user preferences to remove.

**Returns**: `Promise<void>`

### get

Retrieves the user preferences for the current app.

```ts
(app?: string) => Promise<AppPreferences | undefined>
```

**Parameters**

- **`app`** (`string`, optional)
  Name of the app for which to retrieve the user preferences.

**Returns**: `Promise<AppPreferences | undefined>`

### getAll

Retrieves all preferences stored for the current user.

```ts
() => Promise<{ all: AppPreferences[]; }>
```

**Returns**: `Promise<{ all: AppPreferences[]; }>`

### set

Replaces the user preferences for the current app. All existing properties will be removed and replaced with the ones supplied in the `data` object.

```ts
(data: Data, options?: { app: string }) => Promise<void>
```

**Parameters**

- **`data`** (`Data`, required)
  Data to replace the existing user preferences.
- **`options`** (`{ app: string }`, optional)
  Object with an `app` property that accepts an app name as a value. Can be used to target a specific app whose user preferences to replace.

**Returns**: `Promise<void>`

### setFor

Replaces the user preferences of a specified app. All existing properties will be removed and replaced with the ones supplied in the `data` object.

```ts
(app: string, data: Data) => Promise<void>
```

**Parameters**

- **`app`** (`string`, required)
  Name of the app whose user preferences to replace.
- **`data`** (`Data`, required)
  Data to replace the existing user preferences.

**Returns**: `Promise<void>`

### subscribe

Subscribes for changes to the user preferences of the current app.

```ts
(callback: (prefs: AppPreferences) => void) => () => void
```

**Parameters**

- **`callback`** (`(prefs: AppPreferences) => void`, required)
  Callback function that will be invoked once with the initial user preferences and after that on every change of the user preferences.

**Returns**: `() => void`

### subscribeFor

Subscribes for changes to the user preferences of a specified app.

```ts
(app: string, callback: (prefs: AppPreferences) => void) => () => void
```

**Parameters**

- **`app`** (`string`, required)
  Name of the app to which to subscribe.
- **`callback`** (`(prefs: AppPreferences) => void`, required)
  Callback function that will be invoked once with the initial user preferences and after that on every change of the user preferences.

**Returns**: `() => void`

### update

Updates the preferences for the current app. The properties specified in the `data` object will be merged with the existing user preferences.
Other existing properties will remain intact, and non-existent ones will be added.

```ts
(data: Data, options?: { app: string }) => Promise<void>
```

**Parameters**

- **`data`** (`Data`, required)
  Data to be merged with the existing user preferences.
- **`options`** (`{ app: string }`, optional)
  Object with an `app` property that accepts an app name as a value. Can be used to target a specific app whose user preferences to update.

**Returns**: `Promise<void>`

### updateFor

Updates the preferences for a specified app. The properties specified in the `data` object will be merged with the existing user preferences.
Other existing properties will remain intact, and non-existent ones will be added.

```ts
(app: string, data: Data) => Promise<void>
```

**Parameters**

- **`app`** (`string`, required)
  Name of the app whose user preferences to update.
- **`data`** (`Data`, required)
  Data to be merged with the existing user preferences.

**Returns**: `Promise<void>`

## Related types

- [AppPreferences](https://docs.interop.io/desktop/reference/javascript/app%20preferences/apppreferences/index.md)
- [Data](https://docs.interop.io/desktop/reference/javascript/app%20preferences/data/index.md)
