startDate: string // ISO 8601
endDate: string // ISO 8601
+ originallyPublishedStartDate: string // ISO 8601
+ originallyPublishedEndDate: string // ISO 8601
+
nsfw: NSFWQuery
categoryOneOf: string
constructor (options?: {
startDate?: string
endDate?: string
+ originallyPublishedStartDate?: string
+ originallyPublishedEndDate?: string
nsfw?: NSFWQuery
categoryOneOf?: string
licenceOneOf?: string
this.startDate = options.startDate || undefined
this.endDate = options.endDate || undefined
+ this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined
+ this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
+
this.nsfw = options.nsfw || undefined
this.categoryOneOf = options.categoryOneOf || undefined
this.licenceOneOf = options.licenceOneOf || undefined
for (const k of Object.keys(obj)) {
if (k === 'sort') continue // Exception
- if (obj[k] !== undefined) return true
+ if (obj[k] !== undefined && obj[k] !== '') return true
}
return false
reset () {
this.startDate = undefined
this.endDate = undefined
+ this.originallyPublishedStartDate = undefined
+ this.originallyPublishedEndDate = undefined
this.nsfw = undefined
this.categoryOneOf = undefined
this.licenceOneOf = undefined
return {
startDate: this.startDate,
endDate: this.endDate,
+ originallyPublishedStartDate: this.originallyPublishedStartDate,
+ originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw,
categoryOneOf: this.categoryOneOf,
licenceOneOf: this.licenceOneOf,
return {
startDate: this.startDate,
endDate: this.endDate,
+ originallyPublishedStartDate: this.originallyPublishedStartDate,
+ originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw,
- categoryOneOf: this.categoryOneOf ? this.categoryOneOf.split(',') : undefined,
- licenceOneOf: this.licenceOneOf ? this.licenceOneOf.split(',') : undefined,
- languageOneOf: this.languageOneOf ? this.languageOneOf.split(',') : undefined,
- tagsOneOf: this.tagsOneOf ? this.tagsOneOf.split(',') : undefined,
- tagsAllOf: this.tagsAllOf ? this.tagsAllOf.split(',') : undefined,
+ categoryOneOf: this.intoArray(this.categoryOneOf),
+ licenceOneOf: this.intoArray(this.licenceOneOf),
+ languageOneOf: this.intoArray(this.languageOneOf),
+ tagsOneOf: this.intoArray(this.tagsOneOf),
+ tagsAllOf: this.intoArray(this.tagsAllOf),
durationMin: this.durationMin,
durationMax: this.durationMax,
sort: this.sort
}
}
+
+ size () {
+ let acc = 0
+
+ const obj = this.toUrlObject()
+ for (const k of Object.keys(obj)) {
+ if (k === 'sort') continue // Exception
+
+ if (obj[k] !== undefined && obj[k] !== '') acc++
+ }
+
+ return acc
+ }
+
+ private intoArray (value: any) {
+ if (!value) return undefined
+ if (Array.isArray(value)) return value
+
+ if (typeof value === 'string') return value.split(',')
+
+ return [ value ]
+ }
}