Readonly session store that provides read-only access to session values. Used for sharing session data with templates and other readonly contexts.
const readOnlyStore = new ReadOnlyValuesStore({ user: 'john', theme: 'dark' })const user = readOnlyStore.get('user')const hasTheme = readOnlyStore.has('theme') Copy
const readOnlyStore = new ReadOnlyValuesStore({ user: 'john', theme: 'dark' })const user = readOnlyStore.get('user')const hasTheme = readOnlyStore.has('theme')
Creates a new readonly values store
Initial session data or null
Returns true if the store is empty
Gets value for a given key
The key or key path to retrieve
Optional
Default value if key doesn't exist
store.get('username', 'guest')store.get(['user', 'preferences', 'theme'], 'light') Copy
store.get('username', 'guest')store.get(['user', 'preferences', 'theme'], 'light')
Checks if a value exists. Includes extra guards to check arrays for length.
The key or key path to check
Whether to check array length (default: true)
store.has('username') // Check if key existsstore.has(['user', 'roles']) // Check nested keystore.has('items', false) // Don't check array length Copy
store.has('username') // Check if key existsstore.has(['user', 'roles']) // Check nested keystore.has('items', false) // Don't check array length
Gets all values from the store
const allData = store.all() Copy
const allData = store.all()
Returns object representation of values
const obj = store.toObject() Copy
const obj = store.toObject()
Returns the store values as JSON-serializable data
const json = store.toJSON() Copy
const json = store.toJSON()
Returns string representation of the store
const str = store.toString() Copy
const str = store.toString()
Readonly session store that provides read-only access to session values. Used for sharing session data with templates and other readonly contexts.
Example