UNPKG

2.54 kBTypeScriptView Raw
1// Type definitions for dateformat 3.0
2// Project: https://github.com/felixge/node-dateformat
3// Definitions by: Kombu <https://github.com/aicest>
4// BendingBender <https://github.com/BendingBender>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6// TypeScript Version: 2.2
7
8export as namespace dateFormat;
9export = dateFormat;
10
11/**
12 * dateFormat()
13 *
14 * Accepts a date, a mask, or a date and a mask.
15 * Returns a formatted version of the given date.
16 * The date defaults to the current date/time.
17 * The mask defaults to dateFormat.masks.default.
18 *
19 * https://github.com/felixge/node-dateformat/blob/master/lib/dateformat.js#L18
20 */
21declare function dateFormat(
22 date?: Date | string | number,
23 mask?: string,
24 utc?: boolean,
25 gmt?: boolean
26): string;
27declare function dateFormat(mask?: string, utc?: boolean, gmt?: boolean): string;
28
29declare namespace dateFormat {
30 const masks: DateFormatMasks;
31 let i18n: DateFormatI18n;
32
33 /**
34 * dateFormat.masks
35 *
36 * Predefined Formats
37 *
38 * @see https://github.com/felixge/node-dateformat/blob/master/lib/dateformat.js#L107
39 */
40 interface DateFormatMasks {
41 default: string;
42 shortDate: string;
43 mediumDate: string;
44 longDate: string;
45 fullDate: string;
46 shortTime: string;
47 mediumTime: string;
48 longTime: string;
49 isoDate: string;
50 isoTime: string;
51 isoDateTime: string;
52 isoUtcDateTime: string;
53 expiresHeaderFormat: string;
54 [key: string]: string;
55 }
56
57 /**
58 * dateFormat.i18n
59 *
60 * Internationalization strings
61 *
62 * Example:
63 *
64 * @example ```
65 * dateFormat.i18n = {
66 * dayNames: [
67 * 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
68 * 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
69 * ],
70 * monthNames: [
71 * 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
72 * 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
73 * ],
74 * timeNames: [
75 * 'a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'
76 * ]
77 * };```
78 *
79 * @see https://github.com/felixge/node-dateformat/blob/master/lib/dateformat.js#L124
80 */
81 interface DateFormatI18n {
82 dayNames: string[];
83 monthNames: string[];
84 timeNames: string[];
85 }
86}