MCPcopy Create free account
hub / github.com/algolia/docsearch / getLocalStorageSize

Function getLocalStorageSize

packages/docsearch-react/src/utils/storage.ts:4–16  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2 * Estimates the size of localStorage usage in bytes.
3 */
4export function getLocalStorageSize(): number {
5 if (typeof window === 'undefined' || !window.localStorage) {
6 return 0;
7 }
8
9 let total = 0;
10 for (const key in window.localStorage) {
11 if (window.localStorage.hasOwnProperty(key)) {
12 total += window.localStorage[key].length + key.length;
13 }
14 }
15 return total;
16}
17
18/**
19 * Attempts to free up localStorage space by removing DocSearch-related items

Callers 2

utils.test.tsFile · 0.90
manageLocalStorageQuotaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected