https://github.com/chaysen/chrome-storage-ts-utility
A TypeScript utility for interacting with Chrome's local storage.
https://github.com/chaysen/chrome-storage-ts-utility
chrome-extension chrome-storage chrome-storage-api local-storage typescript
Last synced: 2 months ago
JSON representation
A TypeScript utility for interacting with Chrome's local storage.
- Host: GitHub
- URL: https://github.com/chaysen/chrome-storage-ts-utility
- Owner: Chaysen
- License: mit
- Created: 2023-09-28T17:13:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-09T13:37:04.000Z (10 months ago)
- Last Synced: 2025-02-14T14:51:09.217Z (4 months ago)
- Topics: chrome-extension, chrome-storage, chrome-storage-api, local-storage, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/chrome-storegae-ts
- Size: 58.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChromeStorageTS
[](https://github.com/Chaysen/chrome-storage-ts-utility/actions/workflows/nodejs.yml)
[](https://badge.fury.io/js/chrome-storegae-ts)A TypeScript utility for interacting with Chrome's local storage in a type-safe manner.
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [Contributing](#contributing)
- [License](#license)## Installation
```bash
npm install chrome-storage-ts --save
```
## Usage```typescript
import { ChromeStorageTS } from 'chrome-storage-ts';const initialStorage = {
key1: 'value1',
key2: 'value2',
};const storageInstance = new ChromeStorageTS(initialStorage, 'local'); // 'local' is the default storage type
// Update a key in the storage
storageInstance.updateStorageKeyValue('key1', 'newValue');// ... other operations
```
## API
### ChromeStorageTS
- **constructor(storage: ChromeStorageObject, storageType: StorageTypes = 'local')**
Initializes the storage instance with the provided storage object and specifies the type of- **resetChromeStorage(): Promise**
Resets the Chrome storage to its initial state by setting all keys to undefined.- **updateStorageKeyValue(setting: string, value: any): Promise**
Updates a specific key in the Chrome storage with the provided value.- **getStorageKeyValue(key: string, cb: Function): Promise**
Retrieves the value associated with a specific key from the Chrome storage.- **getStorageKeysValue(keys: Array, cb: Function): Promise**
Retrieves the values associated with multiple keys from the Chrome storage.- **addListenerChromeStorageValue(key: string, cb: Function): Promise**
Adds a listener to detect changes to a specific key in the Chrome storage.- **addListenerChromeStorageValues(keys: Array, cb: Function): Promise**
Adds a listener to detect changes to multiple keys in the Chrome storage.## Contributing
- Fork the repository.
- Create your feature branch (git checkout -b feature/YourFeature).
- Commit your changes (git commit -am 'Add some feature').
- Push to the branch (git push origin feature/YourFeature).
- Open a pull request.
## License
This project is licensed under the MIT License. See the LICENSE file for details.