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