
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
@locmod/local-storage
Advanced tools
Use this package to control localStorage
and sessionStorage
.
It handles all possible errors and provides a fallback in form of MemoryStorage
.
This package works only on client side and will throw an error if you use try to use it on server-side. More info in SSR section.
Import default export from local-storage
package and use directly.
import React, { useEffect, useMemo } from 'react'
import localStorage from 'local-storage'
const StoragePage = () => {
if (__SERVER) {
return null
}
const { value = 1, lastUpdate } = localStorage.getSessionItem<{ value: number, lastUpdate: string }>('counter') || {}
useEffect(() => {
localStorage.setSessionItem('counter', { value: value + 1, lastUpdate: (new Date).toISOString() })
}, [])
return (
<div>Local storage: {value}, lastUpdate: {lastUpdate}</div>
)
}
export default StoragePage
If you just want to update localStorage item, please read the previous value inside callback:
useEffect(() => {
const { value = 1 } = localStorage.getSessionItem<{ value: number }>('counter') || {}
localStorage.setSessionItem('counter', { value: value + 1, lastUpdate: (new Date).toISOString() })
}, [])
If your page depends on localStorage we can't render it on the server side, because of unknown state. So you should disable component's render on server side:
const StoragePage = () => {
if (__SERVER) {
return <StoragePageSkeleton />
}
// client side rendering
const { value = 1, lastUpdate } = localStorage.getSessionItem<{ value: number, lastUpdate: string }>('counter') || {}
return (
...
)
}
Return item from localStorage
by key. You can pass types for the value.
const counter = localStorage.getItem<number>('counter')
Library doesn't provide default values. You need to do it by your own.
const { step = 0, finished = false } = localStorage.getItem<{ step: number, finished: boolean }>('data') || {}
Saves value to localStorage
by key. You can save primitives and objects.
localStorage.setItem<number>('counter', 42)
localStorage.setItem<{ value: number, lastUpdate: string }>('data', {
value: 2,
lastUpdate: new Date().toISOString(),
})
localStorage.updateItem<{ value: number, lastUpdate: string }>('data', (currItem) => ({
value: currItem.value + 1,
lastUpdate: new Date().toISOString(),
}))
Removes item from localStorage
by key.
localStorage.removeItem('data')
Returns key list stored in localStorage
. It can be useful for removing items by prefixes.
const keys = localStorage.getKeys()
// keys = [ 'counter', 'data' ]
The same as getItem
but for sessionStorage
.
The same as setItem
but for sessionStorage
.
The same as setItem
but for sessionStorage
.
The same as removeItem
but for sessionStorage
.
The same as getKeys
but for sessionStorage
.
FAQs
local, session and memory storage manager
We found that @locmod/local-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.