UNPKG

7.14 kBTypeScriptView Raw
1declare module 'date-holidays' {
2 export namespace HolidaysTypes {
3 export interface Country {
4 /** IANA country code */
5 country: string;
6 /** short code of state (ISO 3166-2) */
7 state?: string;
8 /** short code of region */
9 region?: string;
10 }
11
12 export type HolidayType = 'public' | 'bank' | 'optional' | 'school' | 'observance' | string;
13
14 export interface Options {
15 /** languages using ISO 639-1 shortcodes */
16 languages?: string | string[];
17 /** timezone, e.g. America/New_York */
18 timezone?: string;
19 /**
20 * holiday types; priority is in ascending order (low ... high)
21 * default ['observance', 'optional', 'school', 'bank', 'public']
22 */
23 types?: HolidayType[];
24 }
25
26 export interface ActiveRange {
27 /** active from date */
28 from?: Date | string;
29 /** active until date */
30 to?: Date | string;
31 }
32
33 export interface HolidayOptions {
34 /** holiday name or if object holiday names in different languages. key defines language */
35 name: { [key: string]: string; } | string;
36 /** holiday type */
37 type?: HolidayType;
38 /** disable rule in year, year+month or date */
39 disabled?: string[];
40 /** enable a different date; requires disabled date for given year */
41 enabled?: string[];
42 /** defines active ranges of rule */
43 active?: ActiveRange[];
44 /** substitute a holiday */
45 substitute?: boolean;
46 /** custom attributes */
47 [key: string]: any;
48 }
49
50 export interface HolidayRule extends HolidayOptions {
51 /** the holiday rule */
52 rule: string;
53 }
54
55 export interface Holiday {
56 /** datestring as "YYYY-MM-DD hh:mm:ss [-hh:ss]" */
57 date: string;
58 /** start date */
59 start: Date;
60 /** end date */
61 end: Date;
62 /** name of holiday in selected or fallback language */
63 name: string;
64 /** type of holiday */
65 type: HolidayType;
66 /** the holiday rule - use for references */
67 rule: string;
68 /** holiday is a substritute day */
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