Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alenaksu/secchiojs
Enhanced Web Storage API
https://github.com/alenaksu/secchiojs
localstorage sessionstorage storage store webstorage
Last synced: 23 days ago
JSON representation
Enhanced Web Storage API
- Host: GitHub
- URL: https://github.com/alenaksu/secchiojs
- Owner: alenaksu
- Created: 2019-11-08T14:36:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T03:19:41.000Z (almost 2 years ago)
- Last Synced: 2024-10-10T11:18:51.095Z (29 days ago)
- Topics: localstorage, sessionstorage, storage, store, webstorage
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/secchiojs
- Size: 450 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# secchiojs
[![GitHub release](https://img.shields.io/github/v/release/alenaksu/secchiojs.svg)](https://github.com/alenaksu/secchiojs/releases)
[![npm](https://badgen.net/npm/v/secchiojs)](https://www.npmjs.com/package/secchiojs)
[![downloads](https://badgen.net/npm/dt/secchiojs)](https://www.npmjs.com/package/secchiojs)
[![Known Vulnerabilities](https://snyk.io/test/npm/secchiojs/badge.svg)](https://snyk.io/test/npm/secchiojs)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/secchiojs/master/LICENSE)Enhanced Web Storage API
## Install
you can install the package through [npm](https://npmjs.com/) runnig:
```bash
npm install secchiojs
```## Usage
### Typescript
```ts
import { getBucket } from 'secchiojs';type UserPrefs = {
name: string;
email: string;
mode: number;
};const [getPrefs, updatePrefs, deletePrefs] = getBucket(
'user-prefs',
{
version: 1,
defaultValue: {},
storage: localStorage,
expire: 3600,
}
);const userPrefs = getPrefs();
updatePrefs({
...userPrefs,
mode: 2,
});deletePrefs();
```### Javascript
```js
import { getBucket } from 'secchiojs';const [getPrefs, updatePrefs, deletePrefs] = getBucket('user-prefs', {
version: 1,
defaultValue: {},
storage: localStorage,
expire: 3600,
});const userPrefs = getPrefs();
updatePrefs({
...userPrefs,
mode: 2,
});deletePrefs();
```## API
### getBucket
#### Parameters
- `name` **string** The name of the bucket. It will be used as key when saving into the storage.
- `options` **BucketOptions** The bucket options.#### Returns
The function returns an array containing get, set and remove methods.
```ts
export type Bucket = [
// get
() => T,// set
(value: T) => void,// remove
() => void
];
```### BucketOptions
- `storage?` **Storage** An instance of a storage implementing the Web Storage interface (eg. localStorage, sessionStorage).
- `version?` **number** The version of the bucket.
- `expire?` **number** A number that indicates the expiration of the data. Default is 0, which means no expiration.
- `defaultValue?` **any** The default value returned if the data doesn't exist, or is expired or is from a different verision.