Skip to content

Commit

Permalink
add local typedef for ical.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkrives committed May 8, 2024
1 parent b5851da commit 0016f28
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 0 deletions.
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/* Emit */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"typeRoots": ["./types"],

/* Interop Constraints */
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
250 changes: 250 additions & 0 deletions types/ical.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
declare module 'ical.js' {
function parse(input: string): unknown[]

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class helpers {
public static updateTimezones(vcal: Component): Component
}

class Component {
public static fromString(str: string): Component

public name: string

constructor(jCal: unknown[] | string, parent?: Component)

public toJSON(): unknown[]

public getFirstSubcomponent(name?: string): Component | null

public getAllSubcomponents(name?: string): Component[]

public getFirstPropertyValue<T = unknown>(name?: string): T

public getFirstProperty(name?: string): Property

public getAllProperties(name?: string): Property[]

public addProperty(property: Property): Property

public addPropertyWithValue(
name: string,
value: string | number | object,
): Property

public updatePropertyWithValue(
name: string,
value: string | number | object,
): Property

public removeAllProperties(name?: string): boolean

public addSubcomponent(component: Component): Component
}

export class Event {
public uid: string
public summary: string
public startDate: Time
public endDate: Time
public description: string
public location: string
public attendees: Property[]

public component: Component

public constructor(
component?: Component | null,
options?: {
strictExceptions: boolean
exceptions: (Component | Event)[]
},
)

public isRecurring(): boolean

public iterator(startTime?: Time): RecurExpansion
}

export class Property {
public name: string
public type: string

constructor(jCal: unknown[] | string, parent?: Component)

public getFirstValue<T = unknown>(): T

public getValues<T = unknown>(): T[]

public setParameter(name: string, value: string | string[]): void

public setValue(value: string | object): void

public setValues(values: (string | object)[]): void

public toJSON(): unknown
}

interface TimeJsonData {
year?: number
month?: number
day?: number
hour?: number
minute?: number
second?: number
isDate?: boolean
}

export class Time {
public static fromString(str: string): Time

public static fromJSDate(aDate: Date | null, useUTC: boolean): Time

public static fromData(aData: TimeJsonData): Time

public static now(): Time

public isDate: boolean
public timezone: string
public zone: Timezone

public year: number
public month: number
public day: number
public hour: number
public minute: number
public second: number

constructor(data?: TimeJsonData)

public compare(aOther: Time): number

public clone(): Time

public convertToZone(zone: Timezone): Time

public adjust(
aExtraDays: number,
aExtraHours: number,
aExtraMinutes: number,
aExtraSeconds: number,
aTimeOpt?: Time,
): void

public addDuration(aDuration: Duration): void

public subtractDateTz(aDate: Time): Duration

public toUnixTime(): number

public toJSDate(): Date

public toJSON(): TimeJsonData

public toString(): string
}

export class Duration {
public days: number
}

export class RecurExpansion {
public complete: boolean

public next(): Time
}

export class Timezone {
public static utcTimezone: Timezone
public static localTimezone: Timezone

public static convert_time(
tt: Time,
fromZone: Timezone,
toZone: Timezone,
): Time

public tzid: string
public component: Component

constructor(
data:
| Component
| {
component: string | Component
tzId?: string
location?: string
tzNames?: string
latitude?: number
longitude?: number
},
)
}

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class TimezoneService {
public static get(tzid: string): Timezone | null

public static has(tzid: string): boolean

public static register(tzid: string, zone: Timezone | Component)

public static remove(tzid: string): Timezone | null
}

export type FrequencyValues =
| 'YEARLY'
| 'MONTHLY'
| 'WEEKLY'
| 'DAILY'
| 'HOURLY'
| 'MINUTELY'
| 'SECONDLY'

export enum WeekDay {
SU = 1,
MO,
TU,
WE,
TH,
FR,
SA,
}

export class RecurData {
public freq?: FrequencyValues
public interval?: number
public wkst?: WeekDay
public until?: Time
public count?: number
public bysecond?: number[] | number
public byminute?: number[] | number
public byhour?: number[] | number
public byday?: string[] | string
public bymonthday?: number[] | number
public byyearday?: number[] | number
public byweekno?: number[] | number
public bymonth?: number[] | number
public bysetpos?: number[] | number
}

export class RecurIterator {
public next(): Time
}

export class Recur {
constructor(data?: RecurData)

public until: Time | null
public freq: FrequencyValues
public count: number | null

public clone(): Recur

public toJSON(): Omit<RecurData, 'until'> & {until?: string}

public iterator(startTime?: Time): RecurIterator

public isByCount(): boolean
}
}

0 comments on commit 0016f28

Please sign in to comment.