File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 content ="c4Lab builds computational solutions for genomics, immunogenomics, and precision medicine at National Taiwan University. "
99 />
1010 < meta name ="robots " content ="index, follow " />
11+ < meta name ="google-site-verification " content ="tSaDTD0QDgmtcYQ4fwCHLghu-7J9kv_b7ri4QhoW24w " />
1112 < link rel ="canonical " href ="https://c4lab.github.io/ " />
1213 < meta property ="og:type " content ="website " />
1314 < meta property ="og:site_name " content ="c4Lab " />
Original file line number Diff line number Diff line change 11import "@testing-library/jest-dom/vitest" ;
2+
3+ function createInMemoryStorage ( ) : Storage {
4+ const values = new Map < string , string > ( ) ;
5+
6+ return {
7+ get length ( ) {
8+ return values . size ;
9+ } ,
10+ clear ( ) {
11+ values . clear ( ) ;
12+ } ,
13+ getItem ( key : string ) {
14+ return values . get ( key ) ?? null ;
15+ } ,
16+ key ( index : number ) {
17+ return Array . from ( values . keys ( ) ) [ index ] ?? null ;
18+ } ,
19+ removeItem ( key : string ) {
20+ values . delete ( key ) ;
21+ } ,
22+ setItem ( key : string , value : string ) {
23+ values . set ( String ( key ) , String ( value ) ) ;
24+ }
25+ } ;
26+ }
27+
28+ function hasStorageApi ( value : unknown ) : value is Storage {
29+ return (
30+ typeof value === "object" &&
31+ value !== null &&
32+ typeof ( value as Storage ) . getItem === "function" &&
33+ typeof ( value as Storage ) . setItem === "function" &&
34+ typeof ( value as Storage ) . removeItem === "function" &&
35+ typeof ( value as Storage ) . clear === "function" &&
36+ typeof ( value as Storage ) . key === "function"
37+ ) ;
38+ }
39+
40+ function ensureLocalStorageApi ( ) {
41+ if ( typeof window === "undefined" ) {
42+ return ;
43+ }
44+
45+ if ( hasStorageApi ( window . localStorage ) ) {
46+ return ;
47+ }
48+
49+ Object . defineProperty ( window , "localStorage" , {
50+ configurable : true ,
51+ value : createInMemoryStorage ( )
52+ } ) ;
53+ }
54+
55+ ensureLocalStorageApi ( ) ;
You can’t perform that action at this time.
0 commit comments