# @analytics/remote-storage-utils

> Storage utilities for cross domain localStorage access, with permissions

Latest version **0.4.24** (published 2025-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @analytics/remote-storage-utils
pnpm add @analytics/remote-storage-utils
yarn add @analytics/remote-storage-utils
bun add @analytics/remote-storage-utils
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.4.24 |
| Published | 2025-08-07 |
| First published | 2020-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 114 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2664 |
| Author | David Wells |
| Maintainers | davidwells |
| Keywords | analytics, analytics-project, analytics-util, storage, remote, cross-domain, localStorage, persistance |

## Links

- npm: https://www.npmjs.com/package/@analytics/remote-storage-utils
- Repository: https://github.com/DavidWells/analytics
- Homepage: https://github.com/DavidWells/analytics#readme
- npm.io page: https://npm.io/package/@analytics/remote-storage-utils

## Dependencies (3)

- [cross-storage](https://npm.io/package/cross-storage.md) ^1.0.0
- [analytics-utils](https://npm.io/package/analytics-utils.md) ^1.1.1
- [@analytics/type-utils](https://npm.io/package/@analytics/type-utils.md) ^0.6.4

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.4.24 (latest) — 2025-08-07
- 0.4.23 — 2025-08-06
- 0.4.22 — 2024-12-12
- 0.4.21 — 2024-12-11
- 0.4.20 — 2023-05-27
- 0.4.19 — 2023-05-27
- 0.4.18 — 2022-03-18
- 0.4.17 — 2022-02-05
- 0.4.16 — 2022-01-03
- 0.4.15 — 2022-01-02
- 0.4.14 — 2021-12-12
- 0.4.13 — 2021-10-24
- 0.4.12 — 2021-10-17
- 0.4.11 — 2021-08-27
- 0.4.10 — 2021-08-05
- … 18 more at https://npm.io/package/@analytics/remote-storage-utils/versions

## README

<!--
title: Remote Storage Utils
pageTitle: RemoteStorage Utils
description: Utility library for cross domain localStorage access.
-->

# Analytics Remote Storage Utils

Utilities for cross domain localStorage access.

## Basic Usage

```js
import RemoteStorage from '@analytics/remote-storage-utils'

// Connect to remote storage domain
const storage = new RemoteStorage('https://remote-site.com/storage.html')

// Get item
storage.getItem('the_remote_local_storage_key').then((value) => {
  console.log('value', value)
})

// Set item
storage.setItem({
  key: 'the_remote_local_storage_key',
  value: 'foobar'
}).then(() => {
  console.log('Value set')
})
```

## API

### `getItem`

Get localStorage from another domain

```js
import { RemoteStorage } from '@analytics/remote-storage-utils'

const remoteStorage = new RemoteStorage('https://remote-site.com/storage.html')

remoteStorage.getItem('the_remote_local_storage_key').then(() => {
  console.log('remote value is', value)
})
```

### `getRemoteItem`

You can also use the standalone `getRemoteItem` function with a cross storage client instance passed into it.

```js
import { getRemoteItem, CrossStorageClient } from '@analytics/remote-storage-utils'

// Create an instance to use in standalone functions
const storageInstance = new CrossStorageClient('https://remote-site.com/storage.html')

const localStorageKeys = [
  'the_remote_local_storage_key',
  'another_remote_local_storage_key',
  'xyz',
]

getRemoteItem(localStorageKeys, storageInstance).then((values) => {
  console.log('remote values', values)
})
```

### `setItem`

Set a localStorage value in remote domain

```js
import { RemoteStorage } from '@analytics/remote-storage-utils'

const remoteStorage = new RemoteStorage('https://remote-site.com/storage.html')

remoteStorage.setItem('the_remote_local_storage_key', 'foobar').then(() => {
  console.log('remote value stored')
})
```

You can also use the standalone `setRemoteItem` function with a cross storage client instance passed into it.

```js
import { setRemoteItem, CrossStorageClient } from '@analytics/remote-storage-utils'

// Create an instance to use in standalone functions
const storageInstance = new CrossStorageClient('https://remote-site.com/storage.html')

// Set remote value
setRemoteItem({
  key: 'foobar',
  value: JSON.stringify(userId)
}, storageInstance)

// Handler if values are different
function customConflictResolver(localValue, remoteValue) {
  if (localValue === remoteValue) {
    // Return empty to abort setting remote value
    return
  }
  if (remoteValue === 'cool') {
    // Return empty to abort setting remote value
    return
  }
  // Return value to set in remote
  return 'this-value-will-be-set'
}

setRemoteItem({
  key: 'baz',
  value: 123,
  resolve: customConflictResolver
}, crossStorage)
```

---
_Source: https://npm.io/package/@analytics/remote-storage-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
