2
0
mirror of https://github.com/iconify/iconify.git synced 2024-10-24 01:22:04 +00:00
iconify/packages/core/src/browser-storage/count.ts

25 lines
612 B
TypeScript
Raw Normal View History

2022-06-28 19:11:15 +00:00
import { browserCacheCountKey } from './config';
2022-06-29 10:41:56 +00:00
import { getStoredItem, setStoredItem } from './item';
import type { BrowserStorageInstance } from './types';
2022-06-28 19:11:15 +00:00
/**
* Change current count for storage
*/
export function setBrowserStorageItemsCount(
2022-06-29 10:41:56 +00:00
storage: BrowserStorageInstance,
2022-06-28 19:11:15 +00:00
value: number
2022-06-28 20:53:58 +00:00
): true | undefined {
2022-06-29 10:41:56 +00:00
return setStoredItem(storage, browserCacheCountKey, value.toString());
2022-06-28 19:11:15 +00:00
}
/**
* Get current count from storage
*/
export function getBrowserStorageItemsCount(
storage: typeof localStorage
): number {
2022-06-29 10:41:56 +00:00
return (
parseInt(getStoredItem(storage, browserCacheCountKey) as string) || 0
);
2022-06-28 19:11:15 +00:00
}