Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Use your localStorage as a reactive JSON store (usable via React hooks or without React)
yarn add jrestore
jrestore
not only converts your regular string-oriented localStorage
into a JSON storage, you can also subscribe to changes. It makes use of localStorage
in the background, so everything is persistent. It can be used with or without React.
import jrestore from 'jrestore'
jrestore.setItem('mykey', { a: 12, b: true })
console.log(
jrestore.getItem('mykey') // { a: 12, b: true }
)
jrestore.removeItem('mykey')
console.log(
jrestore.getItem('mykey') // undefined
)
jrestore.setItem('mykey', [1, 2, 3])
jrestore.clear() // removes all keys
console.log(
jrestore.getItem('mykey') // undefined
)
jrestore.setItem('mykey', 0) // mykey is set to 0
jrestore.setItem('mykey', value => value + 1) // mykey is set to 1
const listener = value => console.log('Value changed :', value)
jrestore.addListener('mykey', listener)
jrestore.setItem('mykey', -452) // Prints "Value changed : -452"
jrestore.setItem('mykey', [1, 2]) // Prints "Value changed : [1, 2]"
jrestore.setItem('mykey', arr => [...arr, 3]) // Prints "Value changed : [1, 2, 3]"
jrestore.clear() // Prints "Value changed : undefined"
jrestore.setItem('mykey', true) // Prints "Value changed : true"
jrestore.removeItem('mykey') // Prints "Value changed : undefined"
jrestore.removeListener('mykey', listener)
jrestore.setItem('mykey', -452) // Prints nothing
import React from 'react
import jrestore from 'jrestore'
jrestore.React = React // Don't forget !
const ComponentA = () => {
const counter = jrestore.useItem('counter') // reacts to changes
return (
<button onClick={() => jrestore.setItem('counter', counter + 1)}>
Increment {counter}
</button>
)
}
const ComponentB = () => {
const counter = jrestore.useItem('counter', 0) // default value, when the 'counter' is still unset
return (
<button onClick={() => jrestore.setItem('counter', counter + 1)}>
Increment {counter}
</button>
)
}
const ComponentC = () => (
<button onClick={() => jrestore.setItem('counter', counter => counter + 1)}>
Increment
</button>
)
const ComponentD = () => {
const object = jrestore.useItem('myobj', { a: 12, b: [true] })
if(!object)
return <b>Object was removed</b>
return (
<button onClick={() => jrestore.removeItem('myobj')}>
Remove
</button>
)
}
jrestore.prefix = 'myprefix' // A prefix for all your keys in the localStorage, choose a prefix unique to your app and your domain (defaults to an empty string)
jrestore.React = React // Your version of React (must support hooks), nothing set by default
jrestore.store = window.localStorage // The persistent storage, set by default
jrestore.serialize = JSON.stringify // The "JSON to string" converter, set by default
jrestore.deserialize = JSON.parse // The "string to JSON" converter, set by default
FAQs
Use your localStorage as a reactive JSON store (usable via React hooks or without React)
We found that jrestore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.