Fixed getItem() with a default value
This commit is contained in:
+4
-5
@@ -4,10 +4,9 @@ export function setItem(k: string, v: string): void {
|
|||||||
export function getItem(k: string): string | null
|
export function getItem(k: string): string | null
|
||||||
export function getItem(k: string, defaultValue: any): string
|
export function getItem(k: string, defaultValue: any): string
|
||||||
export function getItem(k: string, defaultValue?: any): string | null {
|
export function getItem(k: string, defaultValue?: any): string | null {
|
||||||
try {
|
const val = localStorage.getItem(k)
|
||||||
return localStorage.getItem(k) ?? null
|
if (defaultValue !== undefined && val === null) {
|
||||||
}
|
return defaultValue
|
||||||
catch (e) {
|
|
||||||
return defaultValue ?? null
|
|
||||||
}
|
}
|
||||||
|
return val
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user