Skip to content

Commit

Permalink
💡 Removed redundant comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Gaberov committed Jul 24, 2023
1 parent f34e6c8 commit 28bcb4a
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/utilities/localStorageService.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
import { debounce } from 'lodash';

// Create a record
export const createRecord = (key: string, value: string): { error?: string } | void => {
if (!key || !value) { return { error: 'Store to localStorage failed. Invalid key or value.' }; }
localStorage.setItem(key, value);
};

// Read a record
export const readRecord = (key: string): string | null => {
return localStorage.getItem(key);
};

// Update a record
export const updateRecord = (key: string, value: string): { error?: string } | void => {
if (!key || !value) { return { error: 'Store to localStorage failed. Invalid key or value.' }; }
localStorage.setItem(key, value);
};

// Delete a record
export const deleteRecord = (key: string): { error?: string } | void => {
if (!key) { return { error: 'Delete from localStorage failed. Invalid key.' }; }
localStorage.removeItem(key)
};

// Clear all
export const clearAll = (): void => localStorage.clear();

// Check for stored items
export const hasStoredItems = (): boolean => localStorage.length > 0;

// Check for support
export const isLocalStorageSupported = (): boolean => !!window.localStorage;

// Store (create or update) record to local storage with some delay (e.g. 1500 ms)
export const storeToLocalStorageDebounced = debounce((key: string, value: string): void => {
if (isLocalStorageSupported()) {
if (readRecord(key)) {
Expand All @@ -43,7 +35,6 @@ export const storeToLocalStorageDebounced = debounce((key: string, value: string
}
}, 1500, {leading: false});

// Store (create or update) record to local storage
export const storeToLocalStorage = (key: string, value: string): void => {
if (isLocalStorageSupported()) {
if (readRecord(key)) {
Expand Down

1 comment on commit 28bcb4a

@vercel
Copy link

@vercel vercel bot commented on 28bcb4a Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.