chat-delete-utils
v1.0.0
Published
A utility library for handling chat message and conversation deletion operations
Maintainers
Readme
Chat Delete Utils
A utility library for handling chat message and conversation deletion operations with comprehensive localStorage management.
Installation
npm install chat-delete-utilsUsage
import {
resetAfterBatchDelete,
resetAfterSingleDelete,
deleteConversationFromLocalStorage,
deleteAllConversationsFromLocalStorage,
deleteMessagesFromConversation,
clearAllChatData,
createReactiveObject,
conversationExistsInLocalStorage
} from 'chat-delete-utils';
// Create reactive objects
const messages = createReactiveObject([]);
const conversations = createReactiveObject([]);
const conversationId = createReactiveObject('');
const currentChat = createReactiveObject(-1);
// Reset after batch deletion
resetAfterBatchDelete(
{ value: 'Welcome to the chat!' },
conversations,
messages,
conversationId,
currentChat
);
// Reset after single deletion
resetAfterSingleDelete(
'conversation-123',
{ ok: true },
{ value: 'Welcome to the chat!' },
conversations,
messages,
conversationId,
currentChat
);
// Delete specific conversation from localStorage
deleteConversationFromLocalStorage('conversation-123');
// Delete all conversations
deleteAllConversationsFromLocalStorage();
// Delete specific messages from a conversation
deleteMessagesFromConversation('conversation-123', ['msg-1', 'msg-2']);
// Clear all chat data
clearAllChatData();
// Check if conversation exists
const exists = conversationExistsInLocalStorage('conversation-123');API Reference
Core Deletion Functions
resetAfterBatchDelete(PROMPT_MESSAGE, conversations, messages, conversationId, currentChat)- Reset state after batch deletionresetAfterSingleDelete(id, response, PROMPT_MESSAGE, conversations, messages, conversationId, currentChat)- Reset state after single deletion
localStorage Management
deleteConversationFromLocalStorage(conversationId)- Delete specific conversation from localStoragedeleteAllConversationsFromLocalStorage()- Delete all conversations from localStoragedeleteMessagesFromConversation(conversationId, messageIds)- Delete specific messages from a conversationclearAllChatData()- Clear all chat-related data from localStorageconversationExistsInLocalStorage(conversationId)- Check if conversation exists in localStorage
Utility Functions
createReactiveObject(value)- Create a simple reactive object (Vue compatibility)
Features
- Comprehensive Deletion: Support for both batch and single conversation deletion
- Local Storage Management: Complete localStorage operations for chat data
- State Reset: Proper state reset after deletion operations
- Error Handling: Robust error handling with detailed logging
- Vue Compatibility: Helper functions for Vue reactivity patterns
- Data Validation: Validation checks before performing operations
Use Cases
- Conversation Cleanup: Remove old or unwanted conversations
- Batch Operations: Delete multiple conversations at once
- Message Management: Remove specific messages from conversations
- Data Reset: Clear all chat data for testing or privacy
- Storage Optimization: Manage localStorage usage efficiently
Error Handling
All functions return boolean values indicating success/failure and include comprehensive error logging:
const success = deleteConversationFromLocalStorage('conversation-123');
if (!success) {
console.log('Deletion failed');
}Browser Support
This library requires modern browser features:
- ES6 Modules
- localStorage API
- Console API for error logging
License
MIT
