Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@crumb/warehouse
Advanced tools
Simple and unified API for accessing browser storage. Supports sessionStorage, localStorage, and cookies.
Simple and unified API for accessing browser storage. Supports sessionStorage, localStorage, and cookies.
Warehouse is a simple and unified API used for accessing browser storage. Due to it's synchronous nature, Warehouse does not support asynchronous browser storage types such as IndexedDB or WebSQL. While this does prevent the use of other storage mechanisms, it greatly simplifies Warehouse for basic applications where synchronous storage mechanisms are sufficient.
# Yarn
yarn add @crumb/warehouse
# npm
npm install @crumb/warehouse
To start, create a new Warehouse
instance using the storage type you wish to use (i.e. sessionStorage, cookie).
import { createWarehouse } from '@crumb/warehouse'
const warehouse = createWarehouse('sessionStorage')
After the warehouse is created, you can store, retrieve, and delete items from the warehouse.
warehouse.put('foo', 'bar')
warehouse.get('foo') // 'bar'
warehouse.remove('foo')
Unlike the native browser APIs, Warehouse supports more than just string data by using JSON.stringify
and JSON.parse
when storing and retrieving items. For example, the code block below shows storing and retrieving an object.
If using TypeScript, you will notice that the example below shows how the get
method accepts a type argument which will be used as the return type.
interface User {
firstName: string
lastName: string
}
warehouse.put('foo', {
firstName: 'bar',
lastName: 'baz',
})
warehouse.get<User>('foo') // { firstName: 'bar', lastName: 'baz' }
To set a cookie expiration when creating cookies, simply add the expireDays
option when calling the put
method. If not provided, an expiration will not be added to the cookie and thus will use the browser's default expiration of "Session".
warehouse.put('foo', 'bar', { expireDays: 7 })
One useful feature of Warehouse is the ability to define a key prefix to be added to all items that are stored. This is especially helpful for organizing items if you have multiple applications storing items on the same domain.
const warehouse = createWarehouse('sessionStorage', {
prefix: 'my-app-name-',
})
While some applications may only use a single type of storage, your application may require storing items in multiple browser storage types. To do so, simply create a separate Warehouse
instance for each storage type you need.
The approach we recommend is to create a file to house all your instantiated warehouses (i.e. warehouses.js
) so individual files or components can import and use the warehouses as they have need.
// warehouses.js
export const localStorageWarehouse = createWarehouse('localStorage')
export const cookieWarehouse = createWarehouse('cookie')
// app.js
import { localStorageWarehouse } from './warehouses'
console.log(localStorageWarehouse.get('foo'))
FAQs
Simple and unified API for accessing browser storage. Supports sessionStorage, localStorage, and cookies.
We found that @crumb/warehouse 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.