@@ -14,7 +14,7 @@ interface SisyphusOptions {
14
14
timeout : number ;
15
15
autoRelease : boolean ;
16
16
onSave : ( arg0 : Sisyphus ) => void ;
17
- onBeforeRestore : ( arg0 : Sisyphus ) => boolean | void ;
17
+ onBeforeRestore : ( arg0 : Sisyphus ) => boolean | undefined ;
18
18
onRestore : ( arg0 : Sisyphus ) => void ;
19
19
onRelease : ( arg0 : Sisyphus ) => void ;
20
20
}
@@ -60,7 +60,7 @@ export class Sisyphus {
60
60
this . bindSaveData ( ) ;
61
61
}
62
62
63
- findFieldsToProtect ( target : HTMLFormElement ) : Array < Element > {
63
+ findFieldsToProtect ( target : HTMLFormElement ) : Element [ ] {
64
64
return Array . of ( ...target . elements ) . filter ( ( el : Element ) => {
65
65
if (
66
66
el instanceof HTMLInputElement &&
@@ -87,7 +87,7 @@ export class Sisyphus {
87
87
return (
88
88
( this . options . locationBased ? this . href : "" ) +
89
89
this . getFormIdAndName ( target ) +
90
- ( field . getAttribute ( "name" ) || "" ) +
90
+ ( field . getAttribute ( "name" ) ?? "" ) +
91
91
this . options . customKeySuffix
92
92
) ;
93
93
}
@@ -126,26 +126,28 @@ export class Sisyphus {
126
126
*/
127
127
saveAllData ( ) {
128
128
for ( const target of this . targets ) {
129
- let multiCheckboxCache : { [ key : string ] : boolean } = { } ;
129
+ const multiCheckboxCache : Record < string , boolean > = { } ;
130
130
131
131
for ( const field of this . findFieldsToProtect ( target ) ) {
132
132
if ( this . getExcludeFields ( ) . includes ( field ) || ! field . getAttribute ( "name" ) ) {
133
133
continue ;
134
134
}
135
135
const prefix = this . getPrefix ( target , field ) ;
136
136
const fieldType = field . getAttribute ( "type" ) ;
137
- // @ts -ignore
137
+ // @ts -expect-error All field objects are some kind of input field with value.
138
138
let value : string | string [ ] | boolean = field . value ;
139
139
140
140
if ( field instanceof HTMLInputElement && fieldType === "checkbox" ) {
141
- if ( field . name . indexOf ( "[" ) !== - 1 ) {
141
+ if ( field . name . includes ( "[" ) ) {
142
142
if ( multiCheckboxCache [ field . name ] ) {
143
143
return ;
144
144
}
145
- let tempValue : string [ ] = [ ] ;
146
- $ ( "[name='" + field . name + "']:checked" ) . each ( function ( ) {
147
- tempValue . push ( field . value ) ;
148
- } ) ;
145
+ const tempValue : string [ ] = [ ] ;
146
+ for ( const partField of document . querySelectorAll ( "[name='" + field . name + "']:checked" ) ) {
147
+ if ( partField instanceof HTMLInputElement ) {
148
+ tempValue . push ( partField . value ) ;
149
+ }
150
+ }
149
151
value = tempValue ;
150
152
multiCheckboxCache [ field . name ] = true ;
151
153
} else {
@@ -200,24 +202,24 @@ export class Sisyphus {
200
202
field instanceof HTMLInputElement &&
201
203
field . type === "checkbox" &&
202
204
resque !== "false" &&
203
- field . name . indexOf ( "[" ) === - 1
205
+ ! field . name . includes ( "[" )
204
206
) {
205
207
field . checked = true ;
206
208
} else if (
207
209
field instanceof HTMLInputElement &&
208
210
field . type === "checkbox" &&
209
211
resque === "false" &&
210
- field . name . indexOf ( "[" ) === - 1
212
+ ! field . name . includes ( "[" )
211
213
) {
212
214
field . checked = false ;
213
215
} else if ( field instanceof HTMLInputElement && field . type === "radio" ) {
214
216
if ( field . value === resque ) {
215
217
field . checked = true ;
216
218
}
217
- } else if ( field instanceof HTMLInputElement && field . name . indexOf ( "[" ) === - 1 ) {
219
+ } else if ( field instanceof HTMLInputElement && ! field . name . includes ( "[" ) ) {
218
220
field . value = resque ;
219
221
} else {
220
- // @ts -ignore
222
+ // @ts -expect-error Definitely an input field with a value, but not known by type
221
223
field . value = resque . split ( "," ) ;
222
224
}
223
225
}
@@ -236,7 +238,8 @@ export class Sisyphus {
236
238
*/
237
239
saveToBrowserStorage ( key : string , value : any , fireCallback ?: boolean ) {
238
240
// if fireCallback is undefined it should be true
239
- fireCallback = fireCallback === undefined ? true : fireCallback ;
241
+ fireCallback = fireCallback ?? true ;
242
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
240
243
localStorage . setItem ( key , value + "" ) ;
241
244
if ( fireCallback && value !== "" ) {
242
245
this . options . onSave ( this ) ;
0 commit comments