# API

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

**Source**: https://docs.interop.io/browser/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>` - Promise that resolves when the user preferences for the current app have been removed.

### clearAll

Removes all preferences stored for the current user.

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

**Returns**: `Promise<void>` - Promise that resolves when all preferences stored for the current user have been removed.

### 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>` - Promise that resolves when the user preferences for a specified app have been removed.

### get

Retrieves the user preferences for the current app.

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

**Parameters**

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

**Returns**: `Promise<AppPreferences>` - Promise that resolves with the user preferences for the current app.

### getAll

Retrieves all preferences stored for the current user.

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

**Returns**: `Promise<{ all: AppPreferences[] }>` - Promise that resolves with all preferences stored for the current user.

### 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: any, options?: { app: string }) => Promise<void>
```

**Parameters**

- **`data`** (`any`, 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>` - Promise that resolves when the user preferences for the current app have been replaced.

### 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: any) => Promise<void>
```

**Parameters**

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

**Returns**: `Promise<void>` - Promise that resolves when the user preferences of a specified app have been replaced.

### subscribe

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

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

**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**: `UnsubscribeFunction` - Unsubscribe function.

### subscribeFor

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

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

**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**: `UnsubscribeFunction` - Unsubscribe function.

### 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: any, options?: { app: string }) => Promise<void>
```

**Parameters**

- **`data`** (`any`, 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>` - Promise that resolves when the preferences for the current app have been updated.

### 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: any) => Promise<void>
```

**Parameters**

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

**Returns**: `Promise<void>` - Promise that resolves when the preferences for a specified app have been updated.

## Related types

- [AppPreferences](https://docs.interop.io/browser/reference/javascript/app%20preferences/apppreferences/index.md)
- [UnsubscribeFunction](https://docs.interop.io/browser/reference/javascript/search/unsubscribefunction/index.md)
