-
Notifications
You must be signed in to change notification settings - Fork 247
/
index.d.ts
208 lines (193 loc) · 6.97 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
declare module 'date-holidays' {
export namespace HolidaysTypes {
export interface Country {
/** IANA country code */
country: string;
/** short code of state (ISO 3166-2) */
state?: string;
/** short code of region */
region?: string;
}
export type HolidayType = 'public' | 'bank' | 'optional' | 'school' | 'observance' | string;
export interface Options {
/** languages using ISO 639-1 shortcodes */
languages?: string | string[];
/** timezone, e.g. America/New_York */
timezone?: string;
/**
* holiday types; priority is in ascending order (low ... high)
* default ['observance', 'optional', 'school', 'bank', 'public']
*/
types?: HolidayType[];
}
export interface ActiveRange {
/** active from date */
from?: Date | string;
/** active until date */
to?: Date | string;
}
export interface HolidayOptions {
/** holiday name or if object holiday names in different languages. key defines language */
name: { [key: string]: string; } | string;
/** holiday type */
type?: HolidayType;
/** disable rule in year, year+month or date */
disabled?: string[];
/** enable a different date; requires disabled date for given year */
enabled?: string[];
/** defines active ranges of rule */
active?: ActiveRange[];
/** substitute a holiday */
substitute?: boolean;
/** custom attributes */
[key: string]: any;
}
export interface HolidayRule extends HolidayOptions {
/** the holiday rule */
rule: string;
}
export interface Holiday {
/** datestring as "YYYY-MM-DD hh:mm:ss [-hh:ss]" */
date: string;
/** start date */
start: Date;
/** end date */
end: Date;
/** name of holiday in selected or fallback language */
name: string;
/** type of holiday */
type: HolidayType;
/** the holiday rule - use for references */
rule: string;
/** holiday is a substritute day */
substitute?: boolean;
}
}
export class HolidayRule {
constructor(ruleObj: HolidaysTypes.HolidayRule);
/**
* disable rule in year (month)
*/
disableIn(year: number, month?: number): void;
}
export default class Holidays {
constructor(opts?: HolidaysTypes.Options);
constructor(country: HolidaysTypes.Country | string, opts?: HolidaysTypes.Options);
constructor(country: HolidaysTypes.Country | string, state: string, opts?: HolidaysTypes.Options);
constructor(country: HolidaysTypes.Country | string, state: string, region: string, opts?: HolidaysTypes.Options);
/**
* initialize holidays for a country/state/region
*/
init(country?: HolidaysTypes.Country | string, opts?: HolidaysTypes.Options): void;
init(country?: string, state?: string, opts?: HolidaysTypes.Options): void;
init(country?: string, state?: string, region?: string, opts?: HolidaysTypes.Options): void;
/**
* set (custom) holiday
* @throws {TypeError}
* @param rule - rule for holiday (check supported grammar) or date in ISO Format, e.g. 12-31 for 31th Dec
* @param [opts] - holiday options, if String then opts is used as name
* @param opts.name - translated holiday names e.g. `{ en: 'name', es: 'nombre', ... }`
* @param opts.type - holiday type `public|bank|school|observance`
* @returns `true` if holiday could be set returns `true`
*/
setHoliday(rule: string, opts: HolidaysTypes.HolidayOptions | string): boolean;
/**
* get all holidays for `year` with names using prefered `language`
* @param [year] - if omitted current year is choosen
* @param [language] - ISO 639-1 code for language
* @returns of found holidays in given year sorted by Date:
*/
getHolidays(year?: string | number | Date, lang?: string): HolidaysTypes.Holiday[];
/**
* check whether `date` is a holiday or not
* @returns of found holidays in given year sorted by Date:
*/
isHoliday(date: Date|string): HolidaysTypes.Holiday[] | false;
/**
* set or update rule
* @returns `true` if holiday could be set returns `true`
*/
setRule(holidayRule: HolidayRule|object): boolean;
/**
* unset rule
* @param rule - rule for holiday (check supported grammar) or date in ISO Format, e.g. 12-31 for 31th Dec
* @returns `true` if holiday could be set returns `true`
*/
unsetRule(rule: string): boolean;
/**
* get available rules for selected country, (state, region)
*/
getRules(): HolidayRule[];
/**
* get rule for selected country, (state, region)
* @param rule - rule for holiday (check supported grammar) or date in ISO Format, e.g. 12-31 for 31th Dec
*/
getRule(rule: string): HolidayRule;
/**
* Query for available Countries, States, Regions
* @param [country] - country code
* @param [state] - state code
* @param [lang] - ISO-639 language shortcode
* @returns shortcode, name pairs of supported countries, states, regions
*/
query(country?: string, state?: string, lang?: string): { [key: string]: string; };
/**
* get supported countries
* @param [lang] - ISO-639 language shortcode
* @returns shortcode, name pairs of supported countries
* ```js
* { AD: 'Andorra',
* US: 'United States' }
* ```
*/
getCountries(lang?: string): { [key: string]: string; };
/**
* get supported states for a given country
* @param country - shortcode of country
* @param [lang] - ISO-639 language shortcode
* @returns shortcode, name pairs of supported states, regions
* ```js
* { al: 'Alabama', ...
* wy: 'Wyoming' }
* ```
*/
getStates(country: string, lang?: string): { [key: string]: string; };
/**
* get supported regions for a given country, state
* @param country - shortcode of country
* @param state - shortcode of state
* @param [lang] - ISO-639 language shortcode
* @returns shortcode, name pairs of supported regions
* ```js
* { no: 'New Orleans' }
* ```
*/
getRegions(country: string, state: string, lang?: string): { [key: string]: string; };
/**
* sets timezone
* @param timezone - see `moment-timezone`
* if `timezone` is `undefined` then all dates are considered local dates
*/
setTimezone(timezone: string): void;
/**
* get timezones for country, state, region
* @returns of {String}s containing the timezones
*/
getTimezones(): string[];
/**
* set language(s) for holiday names
* @returns set languages
*/
setLanguages(language: string | string[]): string[];
/**
* get languages for selected country, state, region
* @returns containing ISO 639-1 language shortcodes
*/
getLanguages(): string[];
/**
* get default day off as weekday
* @returns weekday of day off
*/
getDayOff(): string;
}
}