Storage.from
Creates a Storage adapter from a custom implementation, optionally scoping all keys under a prefix.
All built-in storage adapters (.cookie, .idb, .localStorage, .memory) are built on top of Storage.from and share its key prefix option.
Usage
import { } from 'ox'
import { , } from 'accounts'
const = .({
() {
return .(..() ?? 'null')
},
(, ) {
..(, .())
},
() {
..()
},
})
const = .({ })Parameters
storage
- Type:
Storage - Required
The underlying storage implementation to wrap. Must provide getItem, setItem, and removeItem. Each method may return synchronously or as a Promise.
Use Json from ox for string-backed storage so values such as access-key spending limits round-trip with bigint fields.
import { } from 'ox'
import { } from 'accounts'
const = .({
() {
return .(..() ?? 'null')
},
(, ) {
..(, .())
},
() {
..()
},
})options.key
- Type:
string - Default:
'tempo'
Key prefix applied to every name passed through to the underlying storage. For example, with the default key, getItem('foo') reads from 'tempo.foo'.
import { } from 'ox'
import { } from 'accounts'
const = .(
{
() {
return .(..() ?? 'null')
},
(, ) {
..(, .())
},
() {
..()
},
},
{
: 'my-app',
},
)