@@ -55,14 +55,17 @@ const getOptionsCode = function (options: Partial<Options>) {
55
55
v = `RRule.${ RRule . FREQUENCIES [ v as number ] } `
56
56
} else if ( k === 'dtstart' || k === 'until' ) {
57
57
const d = v as Date
58
- v = 'new Date(Date.UTC(' + [
59
- d . getUTCFullYear ( ) ,
60
- d . getUTCMonth ( ) ,
61
- d . getUTCDate ( ) ,
62
- d . getUTCHours ( ) ,
63
- d . getUTCMinutes ( ) ,
64
- d . getUTCSeconds ( )
65
- ] . join ( ', ' ) + '))'
58
+ v =
59
+ 'new Date(Date.UTC(' +
60
+ [
61
+ d . getUTCFullYear ( ) ,
62
+ d . getUTCMonth ( ) ,
63
+ d . getUTCDate ( ) ,
64
+ d . getUTCHours ( ) ,
65
+ d . getUTCMinutes ( ) ,
66
+ d . getUTCSeconds ( )
67
+ ] . join ( ', ' ) +
68
+ '))'
66
69
} else if ( k === 'byweekday' ) {
67
70
if ( Array . isArray ( v ) ) {
68
71
v = ( v as Weekday [ ] ) . map ( function ( wday ) {
@@ -111,13 +114,13 @@ const makeRows = function (dates: Date[]) {
111
114
states [ i ] = prevStates [ i ]
112
115
}
113
116
const cls = states [ i ] ? 'a' : 'b'
114
- return `<td class='${ cls } '>${ part } </td>`
117
+ return `<td class='${ cls } '>${ part } </td>`
115
118
} )
116
119
117
120
prevParts = parts
118
121
prevStates = states
119
122
120
- return `<tr><td>${ index + 1 } </td>${ cells . join ( '\n' ) } </tr>`
123
+ return `<tr><td>${ index + 1 } </td>${ cells . join ( '\n' ) } </tr>`
121
124
} )
122
125
123
126
return rows . join ( '\n\n' )
@@ -131,21 +134,39 @@ $(function () {
131
134
$tabs . find ( 'a' ) . removeClass ( 'active' )
132
135
$a . addClass ( 'active' )
133
136
$ ( '#input-types section' ) . hide ( )
134
- return $ ( `#input-types #${ id } ` ) . show ( ) . find ( 'input:first' ) . trigger ( 'focus' ) . trigger ( 'change' )
137
+ return $ ( `#input-types #${ id } ` )
138
+ . show ( )
139
+ . find ( 'input:first' )
140
+ . trigger ( 'focus' )
141
+ . trigger ( 'change' )
135
142
}
136
143
137
- $ ( '#input-types section' ) . hide ( ) . each ( function ( ) {
138
- $ ( '<a />' , {
139
- href : `#${ $ ( this ) . attr ( 'id' ) } `
140
- } ) . text ( $ ( this ) . find ( 'h3' ) . hide ( ) . text ( ) ) . appendTo ( $tabs ) . on ( 'click' , function ( ) {
141
- activateTab ( $ ( this ) )
142
- return false
144
+ $ ( '#input-types section' )
145
+ . hide ( )
146
+ . each ( function ( ) {
147
+ $ ( '<a />' , {
148
+ href : `#${ $ ( this ) . attr ( 'id' ) } `
149
+ } )
150
+ . text (
151
+ $ ( this )
152
+ . find ( 'h3' )
153
+ . hide ( )
154
+ . text ( )
155
+ )
156
+ . appendTo ( $tabs )
157
+ . on ( 'click' , function ( ) {
158
+ activateTab ( $ ( this ) )
159
+ return false
160
+ } )
143
161
} )
144
- } )
145
162
146
163
$ ( '.examples code' ) . on ( 'click' , function ( ) {
147
164
const $code = $ ( this )
148
- return $code . parents ( 'section:first' ) . find ( 'input' ) . val ( $code . text ( ) ) . trigger ( 'change' )
165
+ return $code
166
+ . parents ( 'section:first' )
167
+ . find ( 'input' )
168
+ . val ( $code . text ( ) )
169
+ . trigger ( 'change' )
149
170
} )
150
171
151
172
let init : string
@@ -169,44 +190,83 @@ $(function () {
169
190
let values = getFormValues ( $in . parents ( 'form' ) )
170
191
let options : Partial < Options > = { }
171
192
172
- for ( let k in values ) {
193
+ for ( const k in values ) {
173
194
const key = k as keyof Options
174
195
175
- let value : string | string [ ] | Date | Weekday | Weekday [ ] | number | number [ ] = values [ key ] !
196
+ let value = values [ key ]
176
197
if ( ! value ) {
177
198
continue
178
- } else if ( key === 'dtstart' || key === 'until' ) {
179
- const date = new Date ( Date . parse ( value + 'Z' ) )
180
- options [ key ] = date
181
- } else if ( key === 'byweekday' ) {
182
- if ( Array . isArray ( value ) ) {
183
- options [ key ] = value . map ( i => getDay ( parseInt ( i , 10 ) ) )
184
- } else {
185
- options [ key ] = getDay ( parseInt ( value , 10 ) )
186
- }
187
- } else if ( / ^ b y / . test ( key ) ) {
188
- if ( ! Array . isArray ( value ) ) {
189
- value = value . split ( / [ , \s ] + / )
190
- }
191
- value = value . filter ( v => v )
192
- options [ key ] = value . map ( n => parseInt ( n , 10 ) )
193
- } else if ( key === 'tzid' ) {
194
- options [ key ] = value as string
195
- } else {
196
- options [ key ] = parseInt ( value as string , 10 )
197
199
}
198
200
199
- if ( key === 'wkst' ) {
200
- options [ key ] = getDay ( parseInt ( value as string , 10 ) )
201
- }
201
+ switch ( key ) {
202
+ case 'dtstart' :
203
+ case 'until' :
204
+ const date = new Date ( Date . parse ( value + 'Z' ) )
205
+ options [ key ] = date
206
+ continue
207
+
208
+ case 'byweekday' :
209
+ if ( Array . isArray ( value ) ) {
210
+ options [ key ] = value . map ( i => getDay ( parseInt ( i , 10 ) ) )
211
+ } else {
212
+ options [ key ] = getDay ( parseInt ( value , 10 ) )
213
+ }
214
+ continue
215
+
216
+ case 'wkst' :
217
+ options [ key ] = getDay ( parseInt ( value as string , 10 ) )
218
+ continue
219
+
220
+ case 'interval' :
221
+ const i = parseInt ( value as string , 10 )
222
+ if ( i === 1 || ! value ) {
223
+ continue
224
+ }
225
+
226
+ options [ key ] = i
227
+ continue
228
+
229
+ case 'tzid' :
230
+ options [ key ] = value as string
231
+ continue
232
+
233
+ case 'byweekday' :
234
+ case 'byweekno' :
235
+ case 'byhour' :
236
+ case 'byminute' :
237
+ case 'bysecond' :
238
+ case 'byyearday' :
239
+ case 'bymonth' :
240
+ case 'bymonthday' :
241
+ case 'bysetpos' :
242
+ case 'bynmonthday' :
243
+ if ( ! Array . isArray ( value ) ) {
244
+ value = value . split ( / [ , \s ] + / )
245
+ }
246
+ value = value . filter ( v => v )
247
+ options [ key ] = value . map ( n => parseInt ( n , 10 ) )
248
+ continue
202
249
203
- if ( key === 'interval' ) {
204
- const i = parseInt ( value as string , 10 )
205
- if ( i === 1 || ! value ) {
250
+ case 'bynweekday' :
251
+ if ( ! Array . isArray ( value ) ) {
252
+ value = value . split ( / [ , \s ] + / )
253
+ }
254
+ value = value . filter ( v => v )
255
+ options [ key ] = [ value . map ( n => parseInt ( n , 10 ) ) ]
206
256
continue
207
- }
208
257
209
- options [ key ] = i
258
+ case 'byeaster' :
259
+ options [ key ] = parseInt ( value as string , 10 )
260
+ continue
261
+
262
+ case 'freq' :
263
+ case 'count' :
264
+ options [ key ] = parseInt ( value as string , 10 )
265
+ continue
266
+
267
+ default :
268
+ console . warn ( 'Unsupported key' , key )
269
+ continue
210
270
}
211
271
}
212
272
@@ -226,23 +286,33 @@ $(function () {
226
286
try {
227
287
rule = makeRule ( )
228
288
} catch ( e ) {
229
- $ ( '#init' ) . append ( $ ( '<pre class="error"/>' ) . text ( `=> ${ String ( e || null ) } ` ) )
289
+ $ ( '#init' ) . append (
290
+ $ ( '<pre class="error"/>' ) . text ( `=> ${ String ( e || null ) } ` )
291
+ )
230
292
return
231
293
}
232
294
233
295
const rfc = rule . toString ( )
234
296
const text = rule . toText ( )
235
- $ ( '#rfc-output a' ) . text ( rfc ) . attr ( 'href' , `#/rfc/${ rfc } ` )
236
- $ ( '#text-output a' ) . text ( text ) . attr ( 'href' , `#/text/${ text } ` )
297
+ $ ( '#rfc-output a' )
298
+ . text ( rfc )
299
+ . attr ( 'href' , `#/rfc/${ rfc } ` )
300
+ $ ( '#text-output a' )
301
+ . text ( text )
302
+ . attr ( 'href' , `#/text/${ text } ` )
237
303
$ ( '#options-output' ) . text ( getOptionsCode ( rule . origOptions ) )
238
304
if ( inputMethod === 'options' ) {
239
- $ ( '#options-output' ) . parents ( 'tr' ) . hide ( )
305
+ $ ( '#options-output' )
306
+ . parents ( 'tr' )
307
+ . hide ( )
240
308
} else {
241
- $ ( '#options-output' ) . parents ( 'tr' ) . show ( )
309
+ $ ( '#options-output' )
310
+ . parents ( 'tr' )
311
+ . show ( )
242
312
}
243
313
const max = 500
244
314
const dates = rule . all ( function ( date , i ) {
245
- if ( ! rule . options . count && ( i === max ) ) {
315
+ if ( ! rule . options . count && i === max ) {
246
316
return false // That's enough
247
317
}
248
318
return true
@@ -268,7 +338,9 @@ $(function () {
268
338
const method = match [ 1 ] // rfc | text
269
339
const arg = match [ 2 ]
270
340
activateTab ( $ ( `a[href='#${ method } -input']` ) )
271
- return $ ( `#${ method } -input input:first` ) . val ( arg ) . trigger ( 'change' )
341
+ return $ ( `#${ method } -input input:first` )
342
+ . val ( arg )
343
+ . trigger ( 'change' )
272
344
}
273
345
}
274
346
}
0 commit comments