@tutao/tutanota-utils 3.94.0 → 3.94.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,42 +2,30 @@
2
2
  * Represents a resource that is either not ready, ready, or error
3
3
  * Sort of fills a similar role to LazyLoaded, usage is more verbose but also more typesafe. maybe this should be reconciled.
4
4
  */
5
- export class AsyncResult extends Promise {
6
- constructor(promiseOrCallback) {
7
- super((resolve, reject) => {
8
- if (promiseOrCallback instanceof Promise) {
9
- promiseOrCallback.then(resolve).catch(reject)
10
- } else {
11
- promiseOrCallback(resolve, reject)
12
- }
13
- })
14
- this._state = pending()
15
- this.then(result => (this._state = complete(result))).catch(error => (this._state = failure(error)))
16
- }
17
- state() {
18
- return this._state
19
- }
20
- result() {
21
- return this._state.status === "complete" ? this._state.result : null
22
- }
23
- static completed(value) {
24
- return new AsyncResult(resolve => resolve(value))
25
- }
5
+ export class AsyncResult {
6
+ constructor(promise) {
7
+ this._state = pending(promise);
8
+ promise.then(result => (this._state = complete(result))).catch(error => (this._state = failure(error)));
9
+ }
10
+ state() {
11
+ return this._state;
12
+ }
26
13
  }
27
- function pending() {
28
- return {
29
- status: "pending",
30
- }
14
+ function pending(promise) {
15
+ return {
16
+ status: "pending",
17
+ promise,
18
+ };
31
19
  }
32
20
  function complete(result) {
33
- return {
34
- status: "complete",
35
- result,
36
- }
21
+ return {
22
+ status: "complete",
23
+ result,
24
+ };
37
25
  }
38
26
  function failure(error) {
39
- return {
40
- status: "failure",
41
- error,
42
- }
27
+ return {
28
+ status: "failure",
29
+ error,
30
+ };
43
31
  }
@@ -2,4 +2,4 @@
2
2
  * Everything that is in both array1 and array2
3
3
  * This is a naive implementation, don't use it on large inputs
4
4
  */
5
- export declare function intersection<T>(set1: Set<T>, set2: Set<T>): Set<T>
5
+ export declare function intersection<T>(set1: Set<T>, set2: Set<T>): Set<T>;
@@ -3,5 +3,5 @@
3
3
  * This is a naive implementation, don't use it on large inputs
4
4
  */
5
5
  export function intersection(set1, set2) {
6
- return new Set(Array.from(set1).filter(item => set2.has(item)))
6
+ return new Set(Array.from(set1).filter(item => set2.has(item)));
7
7
  }
@@ -3,58 +3,58 @@
3
3
  * As functions here do not use Luxon it cannot be used for calculating things in different time zones, they
4
4
  * are dependent on the system time zone.
5
5
  */
6
- export declare const DAY_IN_MILLIS: number
6
+ export declare const DAY_IN_MILLIS: number;
7
7
  /**
8
8
  * Provides a date representing the beginning of the next day of the given date in local time.
9
9
  */
10
- export declare function getStartOfNextDay(date: Date): Date
10
+ export declare function getStartOfNextDay(date: Date): Date;
11
11
  /**
12
12
  * Provides a date representing the end of the given date in local time.
13
13
  */
14
- export declare function getEndOfDay(date: Date): Date
14
+ export declare function getEndOfDay(date: Date): Date;
15
15
  /**
16
16
  * Provides a date representing the beginning of the given date in local time.
17
17
  */
18
- export declare function getStartOfDay(date: Date): Date
18
+ export declare function getStartOfDay(date: Date): Date;
19
19
  /**
20
20
  * Provides a date representing the day of the given date at the given hour in local time.
21
21
  */
22
- export declare function getHourOfDay(date: Date, hour: number): Date
23
- export declare function isStartOfDay(date: Date): boolean
22
+ export declare function getHourOfDay(date: Date, hour: number): Date;
23
+ export declare function isStartOfDay(date: Date): boolean;
24
24
  /**
25
25
  * Returns true if the given date is today in local time.
26
26
  */
27
- export declare function isToday(date: Date): boolean
27
+ export declare function isToday(date: Date): boolean;
28
28
  /**
29
29
  * Returns true if the given dates represent the same day (time of day is ignored).
30
30
  */
31
- export declare function isSameDay(date1: Date, date2: Date): boolean
31
+ export declare function isSameDay(date1: Date, date2: Date): boolean;
32
32
  /**
33
33
  * Creates new date in with {@param days} added to it as if the days are just fixed
34
34
  * periods of time and are not subject to daylight saving.
35
35
  */
36
- export declare function getDayShifted(date: Date, days: number): Date
36
+ export declare function getDayShifted(date: Date, days: number): Date;
37
37
  /**
38
38
  * Increment the date in place and return it
39
39
  */
40
- export declare function incrementDate(date: Date, byValue: number): Date
41
- export declare function incrementMonth(d: Date, byValue: number): Date
42
- export declare function isSameDayOfDate(date1: Date | null | undefined, date2: Date | null | undefined): boolean
40
+ export declare function incrementDate(date: Date, byValue: number): Date;
41
+ export declare function incrementMonth(d: Date, byValue: number): Date;
42
+ export declare function isSameDayOfDate(date1: Date | null | undefined, date2: Date | null | undefined): boolean;
43
43
  /**
44
44
  * Formats as yyyy-mm-dd
45
45
  */
46
- export declare function formatSortableDate(date: Date): string
46
+ export declare function formatSortableDate(date: Date): string;
47
47
  /**
48
48
  * Formats as yyyy-mm-dd-<hh>h-<mm>m-<ss>
49
49
  */
50
- export declare function formatSortableDateTime(date: Date): string
50
+ export declare function formatSortableDateTime(date: Date): string;
51
51
  /**
52
52
  * @returns {string} sortableDateTime of the current time
53
53
  */
54
- export declare function sortableTimestamp(): string
55
- export declare function isValidDate(date: Date): boolean
54
+ export declare function sortableTimestamp(): string;
55
+ export declare function isValidDate(date: Date): boolean;
56
56
  /**
57
57
  * not interested in any fancy calendar edge cases, only use this where approximation is ok
58
58
  */
59
- export declare function millisToDays(millis: number): number
60
- export declare function daysToMillis(days: number): number
59
+ export declare function millisToDays(millis: number): number;
60
+ export declare function daysToMillis(days: number): number;
package/dist/DateUtils.js CHANGED
@@ -3,114 +3,112 @@
3
3
  * As functions here do not use Luxon it cannot be used for calculating things in different time zones, they
4
4
  * are dependent on the system time zone.
5
5
  */
6
- export const DAY_IN_MILLIS = 1000 * 60 * 60 * 24
6
+ export const DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
7
7
  /**
8
8
  * Provides a date representing the beginning of the next day of the given date in local time.
9
9
  */
10
10
  export function getStartOfNextDay(date) {
11
- let d = new Date(date.getTime())
12
- d.setDate(date.getDate() + 1)
13
- d.setHours(0, 0, 0, 0) // sets the beginning of the day in local time
14
- return d
11
+ let d = new Date(date.getTime());
12
+ d.setDate(date.getDate() + 1);
13
+ d.setHours(0, 0, 0, 0); // sets the beginning of the day in local time
14
+ return d;
15
15
  }
16
16
  /**
17
17
  * Provides a date representing the end of the given date in local time.
18
18
  */
19
19
  export function getEndOfDay(date) {
20
- let d = new Date(date.getTime())
21
- d.setHours(23, 59, 59, 999)
22
- return d
20
+ let d = new Date(date.getTime());
21
+ d.setHours(23, 59, 59, 999);
22
+ return d;
23
23
  }
24
24
  /**
25
25
  * Provides a date representing the beginning of the given date in local time.
26
26
  */
27
27
  export function getStartOfDay(date) {
28
- return getHourOfDay(date, 0)
28
+ return getHourOfDay(date, 0);
29
29
  }
30
30
  /**
31
31
  * Provides a date representing the day of the given date at the given hour in local time.
32
32
  */
33
33
  export function getHourOfDay(date, hour) {
34
- let d = new Date(date.getTime())
35
- d.setHours(hour, 0, 0, 0)
36
- return d
34
+ let d = new Date(date.getTime());
35
+ d.setHours(hour, 0, 0, 0);
36
+ return d;
37
37
  }
38
38
  export function isStartOfDay(date) {
39
- return date.getHours() === 0 && date.getMinutes() === 0
39
+ return date.getHours() === 0 && date.getMinutes() === 0;
40
40
  }
41
41
  /**
42
42
  * Returns true if the given date is today in local time.
43
43
  */
44
44
  export function isToday(date) {
45
- return new Date().toDateString() === date.toDateString()
45
+ return new Date().toDateString() === date.toDateString();
46
46
  }
47
47
  /**
48
48
  * Returns true if the given dates represent the same day (time of day is ignored).
49
49
  */
50
50
  export function isSameDay(date1, date2) {
51
- return date1.toDateString() === date2.toDateString()
51
+ return date1.toDateString() === date2.toDateString();
52
52
  }
53
53
  /**
54
54
  * Creates new date in with {@param days} added to it as if the days are just fixed
55
55
  * periods of time and are not subject to daylight saving.
56
56
  */
57
57
  export function getDayShifted(date, days) {
58
- return new Date(date.getTime() + days * DAY_IN_MILLIS)
58
+ return new Date(date.getTime() + days * DAY_IN_MILLIS);
59
59
  }
60
60
  /**
61
61
  * Increment the date in place and return it
62
62
  */
63
63
  export function incrementDate(date, byValue) {
64
- date.setDate(date.getDate() + byValue)
65
- return date
64
+ date.setDate(date.getDate() + byValue);
65
+ return date;
66
66
  }
67
67
  export function incrementMonth(d, byValue) {
68
- const date = new Date(d)
69
- date.setMonth(date.getMonth() + byValue)
70
- return date
68
+ const date = new Date(d);
69
+ date.setMonth(date.getMonth() + byValue);
70
+ return date;
71
71
  }
72
72
  export function isSameDayOfDate(date1, date2) {
73
- return (
74
- (!date1 && !date2) ||
75
- (date1 != null &&
76
- date2 != null &&
77
- date1.getFullYear() === date2.getFullYear() &&
78
- date1.getMonth() === date2.getMonth() &&
79
- date1.getDate() === date2.getDate())
80
- )
73
+ return ((!date1 && !date2) ||
74
+ (date1 != null &&
75
+ date2 != null &&
76
+ date1.getFullYear() === date2.getFullYear() &&
77
+ date1.getMonth() === date2.getMonth() &&
78
+ date1.getDate() === date2.getDate()));
81
79
  }
82
80
  /**
83
81
  * Formats as yyyy-mm-dd
84
82
  */
85
83
  export function formatSortableDate(date) {
86
- const month = ("0" + (date.getMonth() + 1)).slice(-2)
87
- const day = ("0" + date.getDate()).slice(-2)
88
- return `${date.getFullYear()}-${month}-${day}`
84
+ const month = ("0" + (date.getMonth() + 1)).slice(-2);
85
+ const day = ("0" + date.getDate()).slice(-2);
86
+ return `${date.getFullYear()}-${month}-${day}`;
89
87
  }
90
88
  /**
91
89
  * Formats as yyyy-mm-dd-<hh>h-<mm>m-<ss>
92
90
  */
93
91
  export function formatSortableDateTime(date) {
94
- const hours = ("0" + date.getHours()).slice(-2)
95
- const minutes = ("0" + date.getMinutes()).slice(-2)
96
- const seconds = ("0" + date.getSeconds()).slice(-2)
97
- return `${formatSortableDate(date)}-${hours}h${minutes}m${seconds}s`
92
+ const hours = ("0" + date.getHours()).slice(-2);
93
+ const minutes = ("0" + date.getMinutes()).slice(-2);
94
+ const seconds = ("0" + date.getSeconds()).slice(-2);
95
+ return `${formatSortableDate(date)}-${hours}h${minutes}m${seconds}s`;
98
96
  }
99
97
  /**
100
98
  * @returns {string} sortableDateTime of the current time
101
99
  */
102
100
  export function sortableTimestamp() {
103
- return formatSortableDateTime(new Date())
101
+ return formatSortableDateTime(new Date());
104
102
  }
105
103
  export function isValidDate(date) {
106
- return !isNaN(date.getTime())
104
+ return !isNaN(date.getTime());
107
105
  }
108
106
  /**
109
107
  * not interested in any fancy calendar edge cases, only use this where approximation is ok
110
108
  */
111
109
  export function millisToDays(millis) {
112
- return millis / DAY_IN_MILLIS
110
+ return millis / DAY_IN_MILLIS;
113
111
  }
114
112
  export function daysToMillis(days) {
115
- return days * DAY_IN_MILLIS
113
+ return days * DAY_IN_MILLIS;
116
114
  }
@@ -1,22 +1,22 @@
1
- export declare type Base64 = string
2
- export declare type Base64Ext = string
3
- export declare type Base64Url = string
4
- export declare type Hex = string
5
- export declare function uint8ArrayToArrayBuffer(uint8Array: Uint8Array): ArrayBuffer
1
+ export declare type Base64 = string;
2
+ export declare type Base64Ext = string;
3
+ export declare type Base64Url = string;
4
+ export declare type Hex = string;
5
+ export declare function uint8ArrayToArrayBuffer(uint8Array: Uint8Array): ArrayBuffer;
6
6
  /**
7
7
  * Converts a hex coded string into a base64 coded string.
8
8
  *
9
9
  * @param hex A hex encoded string.
10
10
  * @return A base64 encoded string.
11
11
  */
12
- export declare function hexToBase64(hex: Hex): Base64
12
+ export declare function hexToBase64(hex: Hex): Base64;
13
13
  /**
14
14
  * Converts a base64 coded string into a hex coded string.
15
15
  *
16
16
  * @param base64 A base64 encoded string.
17
17
  * @return A hex encoded string.
18
18
  */
19
- export declare function base64ToHex(base64: Base64): Hex
19
+ export declare function base64ToHex(base64: Base64): Hex;
20
20
  /**
21
21
  * Converts a base64 string to a url-conform base64 string. This is used for
22
22
  * base64 coded url parameters.
@@ -24,7 +24,7 @@ export declare function base64ToHex(base64: Base64): Hex
24
24
  * @param base64 The base64 string.
25
25
  * @return The base64url string.
26
26
  */
27
- export declare function base64ToBase64Url(base64: Base64): Base64Url
27
+ export declare function base64ToBase64Url(base64: Base64): Base64Url;
28
28
  /**
29
29
  * Converts a base64 string to a base64ext string. Base64ext uses another character set than base64 in order to make it sortable.
30
30
  *
@@ -32,13 +32,13 @@ export declare function base64ToBase64Url(base64: Base64): Base64Url
32
32
  * @param base64 The base64 string.
33
33
  * @return The base64Ext string.
34
34
  */
35
- export declare function base64ToBase64Ext(base64: Base64): Base64Ext
35
+ export declare function base64ToBase64Ext(base64: Base64): Base64Ext;
36
36
  /**
37
37
  * Converts a Base64Ext string to a Base64 string and appends the padding if needed.
38
38
  * @param base64ext The base64Ext string
39
39
  * @returns The base64 string
40
40
  */
41
- export declare function base64ExtToBase64(base64ext: Base64Ext): Base64
41
+ export declare function base64ExtToBase64(base64ext: Base64Ext): Base64;
42
42
  /**
43
43
  * Converts a base64 url string to a "normal" base64 string. This is used for
44
44
  * base64 coded url parameters.
@@ -46,41 +46,41 @@ export declare function base64ExtToBase64(base64ext: Base64Ext): Base64
46
46
  * @param base64url The base64 url string.
47
47
  * @return The base64 string.
48
48
  */
49
- export declare function base64UrlToBase64(base64url: Base64Url): Base64
50
- export declare function _stringToUtf8Uint8ArrayLegacy(string: string): Uint8Array
51
- export declare function _replaceLoneSurrogates(s: string | null | undefined): string
49
+ export declare function base64UrlToBase64(base64url: Base64Url): Base64;
50
+ export declare function _stringToUtf8Uint8ArrayLegacy(string: string): Uint8Array;
51
+ export declare function _replaceLoneSurrogates(s: string | null | undefined): string;
52
52
  /**
53
53
  * Converts a string to a Uint8Array containing a UTF-8 string data.
54
54
  *
55
55
  * @param string The string to convert.
56
56
  * @return The array.
57
57
  */
58
- export declare function stringToUtf8Uint8Array(string: string): Uint8Array
59
- export declare function _utf8Uint8ArrayToStringLegacy(uint8Array: Uint8Array): string
58
+ export declare function stringToUtf8Uint8Array(string: string): Uint8Array;
59
+ export declare function _utf8Uint8ArrayToStringLegacy(uint8Array: Uint8Array): string;
60
60
  /**
61
61
  * Converts an Uint8Array containing UTF-8 string data into a string.
62
62
  *
63
63
  * @param uint8Array The Uint8Array.
64
64
  * @return The string.
65
65
  */
66
- export declare function utf8Uint8ArrayToString(uint8Array: Uint8Array): string
67
- export declare function hexToUint8Array(hex: Hex): Uint8Array
68
- export declare function uint8ArrayToHex(uint8Array: Uint8Array): Hex
66
+ export declare function utf8Uint8ArrayToString(uint8Array: Uint8Array): string;
67
+ export declare function hexToUint8Array(hex: Hex): Uint8Array;
68
+ export declare function uint8ArrayToHex(uint8Array: Uint8Array): Hex;
69
69
  /**
70
70
  * Converts an Uint8Array to a Base64 encoded string.
71
71
  *
72
72
  * @param bytes The bytes to convert.
73
73
  * @return The Base64 encoded string.
74
74
  */
75
- export declare function uint8ArrayToBase64(bytes: Uint8Array): Base64
76
- export declare function int8ArrayToBase64(bytes: Int8Array): Base64
75
+ export declare function uint8ArrayToBase64(bytes: Uint8Array): Base64;
76
+ export declare function int8ArrayToBase64(bytes: Int8Array): Base64;
77
77
  /**
78
78
  * Converts a base64 encoded string to a Uint8Array.
79
79
  *
80
80
  * @param base64 The Base64 encoded string.
81
81
  * @return The bytes.
82
82
  */
83
- export declare function base64ToUint8Array(base64: Base64): Uint8Array
83
+ export declare function base64ToUint8Array(base64: Base64): Uint8Array;
84
84
  /**
85
85
  * Converts a Uint8Array containing string data into a string, given the charset the data is in.
86
86
  * @param charset The charset. Must be supported by TextDecoder.
@@ -88,7 +88,7 @@ export declare function base64ToUint8Array(base64: Base64): Uint8Array
88
88
  * @trhows RangeError if the charset is not supported
89
89
  * @return The string
90
90
  */
91
- export declare function uint8ArrayToString(charset: string, bytes: Uint8Array): string
91
+ export declare function uint8ArrayToString(charset: string, bytes: Uint8Array): string;
92
92
  /**
93
93
  * Decodes a quoted-printable piece of text in a given charset.
94
94
  * This was copied and modified from https://github.com/mathiasbynens/quoted-printable/blob/master/src/quoted-printable.js (MIT licensed)
@@ -98,6 +98,6 @@ export declare function uint8ArrayToString(charset: string, bytes: Uint8Array):
98
98
  * @throws RangeError if the charset is not supported
99
99
  * @returns The text as a JavaScript string
100
100
  */
101
- export declare function decodeQuotedPrintable(charset: string, input: string): string
102
- export declare function decodeBase64(charset: string, input: string): string
103
- export declare function stringToBase64(str: string): string
101
+ export declare function decodeQuotedPrintable(charset: string, input: string): string;
102
+ export declare function decodeBase64(charset: string, input: string): string;
103
+ export declare function stringToBase64(str: string): string;