utility-toolkit
v0.0.3
Published
utility-toolkit is library for JavaScript and TypeScript that provides a set of useful functions for various tasks
Maintainers
Readme
utility-toolkit
utility-toolkit is library for JavaScript and TypeScript that provides a set of useful functions for various tasks.
Features
- TypeScript Support: utility-toolkit is written in TypeScript and provides full type definitions.
- CRUD Operations on Local Storage: Easily manage data in the browser's local storage with both synchronous and asynchronous support and error handling.
Installation
You can install utility-toolkit via npm:
npm install utility-toolkitUsage
Importing utility-toolkit
using require
const { setItemLS, getItemLS, removeItemLS, clearLS, setItemAsyncLS, getItemAsyncLS, removeItemAsyncLS, clearAsyncLS } = require('utility-toolkit');Using from
import { setItemLS, getItemLS, removeItemLS, clearLS, setItemAsyncLS, getItemAsyncLS, removeItemAsyncLS, clearAsyncLS } from 'utility-toolkit';CRUD Operations on Local Storage
utility-toolkit provides functions to create, read, update, and delete data in the local storage, with both synchronous and asynchronous methods.
Example
Here's a full example demonstrating the CRUD operations:
import { setItemLS, getItemLS, removeItemLS, clearLS, setItemAsyncLS, getItemAsyncLS, removeItemAsyncLS, clearAsyncLS } from 'utility-toolkit';
const user = {
username: 'john_doe',
email: '[email protected]',
preferences: {
theme: 'dark',
notifications: true
}
};
// Synchronous operations
setLS('user', user);
console.log(getLS('user')); // Outputs: { username: 'john_doe', email: '[email protected]', preferences: { theme: 'dark', notifications: true } }
removeLS('user');
clearLS();
// Asynchronous operations
await setAsyncLS('user', anotherUser);
console.log(await getAsyncLS('user')); // Outputs: { username: 'jane_doe', email: '[email protected]', preferences: { theme: 'light', notifications: false } }
await removeAsyncLS('user');
await clearAsyncLS();