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: 8 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 (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T03:19:41.000Z (about 2 years ago)
- Last Synced: 2025-02-03T13:08:11.589Z (18 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
[](https://github.com/alenaksu/secchiojs/releases)
[](https://www.npmjs.com/package/secchiojs)
[](https://www.npmjs.com/package/secchiojs)
[](https://snyk.io/test/npm/secchiojs)
[](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.