@@ -50,7 +50,7 @@ async function getIndex () {
50
50
lunr . Pipeline . registerFunction ( elixirTrimmerFunction , 'elixirTrimmer' )
51
51
lunr . Pipeline . registerFunction ( hyphenSearchFunction , 'hyphenSearch' )
52
52
53
- const cachedIndex = await loadIndex ( )
53
+ const cachedIndex = await loadIndex ( )
54
54
if ( cachedIndex ) { return cachedIndex }
55
55
56
56
const index = createIndex ( )
@@ -75,52 +75,50 @@ async function loadIndex () {
75
75
76
76
async function saveIndex ( index ) {
77
77
try {
78
- const serializedIndex = await compress ( index )
78
+ const serializedIndex = await compress ( index )
79
79
sessionStorage . setItem ( indexStorageKey ( ) , serializedIndex )
80
80
} catch ( error ) {
81
81
console . error ( 'Failed to save index: ' , error )
82
82
}
83
83
}
84
84
85
- async function compress ( index ) {
86
-
85
+ async function compress ( index ) {
87
86
const stream = new Blob ( [ JSON . stringify ( index ) ] , {
88
- type : 'application/json' ,
89
- } ) . stream ( ) . pipeThrough ( new CompressionStream ( 'gzip' ) ) ;
87
+ type : 'application/json'
88
+ } ) . stream ( ) . pipeThrough ( new window . CompressionStream ( 'gzip' ) )
90
89
91
90
const blob = await new Response ( stream ) . blob ( )
92
91
const buffer = await blob . arrayBuffer ( )
93
92
return b64encode ( buffer )
94
93
}
95
94
96
-
97
- async function decompress ( index ) {
95
+ async function decompress ( index ) {
98
96
const stream = new Blob ( [ b64decode ( index ) ] , {
99
- type : " application/json" ,
100
- } ) . stream ( ) . pipeThrough ( new DecompressionStream ( 'gzip' ) ) ;
97
+ type : ' application/json'
98
+ } ) . stream ( ) . pipeThrough ( new window . DecompressionStream ( 'gzip' ) )
101
99
102
100
const blob = await new Response ( stream ) . text ( )
103
101
return JSON . parse ( blob )
104
102
}
105
103
106
- function b64encode ( buffer ) {
107
- var binary = '' ;
108
- var bytes = new Uint8Array ( buffer ) ;
109
- var len = bytes . byteLength ;
110
- for ( var i = 0 ; i < len ; i ++ ) {
111
- binary += String . fromCharCode ( bytes [ i ] ) ;
112
- }
113
- return window . btoa ( binary ) ;
104
+ function b64encode ( buffer ) {
105
+ let binary = ''
106
+ const bytes = new Uint8Array ( buffer )
107
+ const len = bytes . byteLength
108
+ for ( let i = 0 ; i < len ; i ++ ) {
109
+ binary += String . fromCharCode ( bytes [ i ] )
110
+ }
111
+ return window . btoa ( binary )
114
112
}
115
113
116
- function b64decode ( str ) {
117
- const binary_string = window . atob ( str ) ;
118
- const len = binary_string . length ;
119
- const bytes = new Uint8Array ( new ArrayBuffer ( len ) ) ;
114
+ function b64decode ( str ) {
115
+ const binaryString = window . atob ( str )
116
+ const len = binaryString . length
117
+ const bytes = new Uint8Array ( new ArrayBuffer ( len ) )
120
118
for ( let i = 0 ; i < len ; i ++ ) {
121
- bytes [ i ] = binary_string . charCodeAt ( i ) ;
119
+ bytes [ i ] = binaryString . charCodeAt ( i )
122
120
}
123
- return bytes ;
121
+ return bytes
124
122
}
125
123
126
124
function indexStorageKey ( ) {
0 commit comments