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