@choksheak/ts-utils 0.1.8 → 0.2.0
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.
- package/dateTimeStr.d.ts +68 -14
- package/dateTimeStr.js +68 -41
- package/dateTimeStr.js.map +1 -1
- package/duration.d.ts +70 -0
- package/duration.js +174 -0
- package/duration.js.map +1 -0
- package/kvStore.d.ts +18 -1
- package/kvStore.js +31 -4
- package/kvStore.js.map +1 -1
- package/localStorageCache.d.ts +37 -7
- package/localStorageCache.js +64 -36
- package/localStorageCache.js.map +1 -1
- package/nonEmpty.d.ts +3 -0
- package/nonEmpty.js.map +1 -1
- package/nonNil.d.ts +3 -0
- package/nonNil.js.map +1 -1
- package/package.json +1 -1
- package/safeParseInt.d.ts +3 -0
- package/safeParseInt.js.map +1 -1
- package/sleep.d.ts +4 -0
- package/sleep.js.map +1 -1
- package/src/dateTimeStr.ts +141 -69
- package/src/duration.ts +237 -0
- package/src/kvStore.ts +38 -2
- package/src/localStorageCache.ts +72 -39
- package/src/nonEmpty.ts +3 -0
- package/src/nonNil.ts +3 -0
- package/src/safeParseInt.ts +3 -0
- package/src/sleep.ts +4 -0
- package/src/timeConstants.ts +22 -0
- package/timeConstants.d.ts +18 -0
- package/timeConstants.js +70 -0
- package/timeConstants.js.map +1 -0
package/src/duration.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bunch of miscellaneous constants and utility functions related to handling
|
|
3
|
+
* date and time durations.
|
|
4
|
+
*
|
|
5
|
+
* Note that month and year do not have fixed durations, and hence are excluded
|
|
6
|
+
* from this file. Weeks have fixed durations, but are excluded because we
|
|
7
|
+
* use days as the max duration supported.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
MS_PER_SECOND,
|
|
12
|
+
SECONDS_PER_MINUTE,
|
|
13
|
+
MINUTES_PER_HOUR,
|
|
14
|
+
HOURS_PER_DAY,
|
|
15
|
+
MS_PER_DAY,
|
|
16
|
+
MS_PER_MINUTE,
|
|
17
|
+
MS_PER_HOUR,
|
|
18
|
+
} from "./timeConstants";
|
|
19
|
+
|
|
20
|
+
export type Duration = {
|
|
21
|
+
days?: number;
|
|
22
|
+
hours?: number;
|
|
23
|
+
minutes?: number;
|
|
24
|
+
seconds?: number;
|
|
25
|
+
milliseconds?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One of: days, hours, minutes, seconds, milliseconds
|
|
30
|
+
*/
|
|
31
|
+
export type DurationType = keyof Duration;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Order in which the duration type appears in the duration string.
|
|
35
|
+
*/
|
|
36
|
+
export const DURATION_TYPE_SEQUENCE: DurationType[] = [
|
|
37
|
+
"days",
|
|
38
|
+
"hours",
|
|
39
|
+
"minutes",
|
|
40
|
+
"seconds",
|
|
41
|
+
"milliseconds",
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Follows the same format as Intl.DurationFormat.prototype.format().
|
|
46
|
+
*
|
|
47
|
+
* Short: 1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns
|
|
48
|
+
* Long: 1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds,
|
|
49
|
+
* 7 milliseconds, 8 microseconds, 9 nanoseconds
|
|
50
|
+
* Narrow: 1y 2mo 3w 3d 4h 5m 6s 7ms 8μs 9ns
|
|
51
|
+
*/
|
|
52
|
+
export type DurationStyle = "short" | "long" | "narrow";
|
|
53
|
+
|
|
54
|
+
export type DurationSuffixMap = {
|
|
55
|
+
short: string;
|
|
56
|
+
shorts: string;
|
|
57
|
+
long: string;
|
|
58
|
+
longs: string;
|
|
59
|
+
narrow: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type DurationSuffixType = keyof DurationSuffixMap;
|
|
63
|
+
|
|
64
|
+
export const DURATION_STYLE_SUFFIX_MAP: Record<
|
|
65
|
+
DurationType,
|
|
66
|
+
DurationSuffixMap
|
|
67
|
+
> = {
|
|
68
|
+
days: {
|
|
69
|
+
short: "day",
|
|
70
|
+
shorts: "days",
|
|
71
|
+
long: "day",
|
|
72
|
+
longs: "days",
|
|
73
|
+
narrow: "d",
|
|
74
|
+
},
|
|
75
|
+
hours: {
|
|
76
|
+
short: "hr",
|
|
77
|
+
shorts: "hrs",
|
|
78
|
+
long: "hour",
|
|
79
|
+
longs: "hours",
|
|
80
|
+
narrow: "h",
|
|
81
|
+
},
|
|
82
|
+
minutes: {
|
|
83
|
+
short: "min",
|
|
84
|
+
shorts: "mins",
|
|
85
|
+
long: "minute",
|
|
86
|
+
longs: "minutes",
|
|
87
|
+
narrow: "m",
|
|
88
|
+
},
|
|
89
|
+
seconds: {
|
|
90
|
+
short: "sec",
|
|
91
|
+
shorts: "secs",
|
|
92
|
+
long: "second",
|
|
93
|
+
longs: "seconds",
|
|
94
|
+
narrow: "s",
|
|
95
|
+
},
|
|
96
|
+
milliseconds: {
|
|
97
|
+
short: "ms",
|
|
98
|
+
shorts: "ms",
|
|
99
|
+
long: "millisecond",
|
|
100
|
+
longs: "milliseconds",
|
|
101
|
+
narrow: "ms",
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
function getDurationStyleForPlural(style: DurationStyle): DurationSuffixType {
|
|
106
|
+
return style == "short" ? "shorts" : style === "long" ? "longs" : style;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getValueAndUnitSeparator(style: DurationStyle): string {
|
|
110
|
+
return style === "narrow" ? "" : " ";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getDurationTypeSeparator(style: DurationStyle): string {
|
|
114
|
+
return style === "narrow" ? " " : ", ";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Convert a milliseconds duration into a Duration object. If the given ms is
|
|
119
|
+
* zero, then return an object with a single field of zero with duration type
|
|
120
|
+
* of durationTypeForZero.
|
|
121
|
+
*
|
|
122
|
+
* @param durationTypeForZero Defaults to 'milliseconds'
|
|
123
|
+
*/
|
|
124
|
+
export function msToDuration(
|
|
125
|
+
ms: number,
|
|
126
|
+
durationTypeForZero?: DurationType,
|
|
127
|
+
): Duration {
|
|
128
|
+
if (ms === 0) {
|
|
129
|
+
durationTypeForZero = durationTypeForZero ?? "milliseconds";
|
|
130
|
+
return { [durationTypeForZero]: 0 };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const duration: Duration = {};
|
|
134
|
+
|
|
135
|
+
for (let i = 0; i < 1; i++) {
|
|
136
|
+
let seconds = Math.floor(ms / MS_PER_SECOND);
|
|
137
|
+
const millis = ms - seconds * MS_PER_SECOND;
|
|
138
|
+
|
|
139
|
+
if (millis > 0) {
|
|
140
|
+
duration["milliseconds"] = millis;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (seconds === 0) {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let minutes = Math.floor(seconds / SECONDS_PER_MINUTE);
|
|
148
|
+
seconds -= minutes * SECONDS_PER_MINUTE;
|
|
149
|
+
|
|
150
|
+
if (seconds > 0) {
|
|
151
|
+
duration["seconds"] = seconds;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (minutes === 0) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let hours = Math.floor(minutes / MINUTES_PER_HOUR);
|
|
159
|
+
minutes -= hours * MINUTES_PER_HOUR;
|
|
160
|
+
|
|
161
|
+
if (minutes > 0) {
|
|
162
|
+
duration["minutes"] = minutes;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (hours === 0) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const days = Math.floor(hours / HOURS_PER_DAY);
|
|
170
|
+
hours -= days * HOURS_PER_DAY;
|
|
171
|
+
|
|
172
|
+
if (hours > 0) {
|
|
173
|
+
duration["hours"] = hours;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (days > 0) {
|
|
177
|
+
duration["days"] = days;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return duration;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns the number of milliseconds for the given duration.
|
|
186
|
+
*/
|
|
187
|
+
export function durationToMs(duration: Duration): number {
|
|
188
|
+
const daysMs = (duration.days ?? 0) * MS_PER_DAY;
|
|
189
|
+
const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;
|
|
190
|
+
const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;
|
|
191
|
+
const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;
|
|
192
|
+
const msMs = duration.milliseconds ?? 0;
|
|
193
|
+
|
|
194
|
+
return daysMs + hoursMs + minsMs + secsMs + msMs;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Format a given Duration object into a string. If the object has no fields,
|
|
199
|
+
* then returns an empty string.
|
|
200
|
+
*
|
|
201
|
+
* @param style Defaults to 'short'
|
|
202
|
+
*/
|
|
203
|
+
export function formatDuration(duration: Duration, style?: DurationStyle) {
|
|
204
|
+
style = style ?? "short";
|
|
205
|
+
const stylePlural = getDurationStyleForPlural(style);
|
|
206
|
+
|
|
207
|
+
const space = getValueAndUnitSeparator(style);
|
|
208
|
+
|
|
209
|
+
const a: string[] = [];
|
|
210
|
+
|
|
211
|
+
for (const unit of DURATION_TYPE_SEQUENCE) {
|
|
212
|
+
const value = duration[unit];
|
|
213
|
+
if (value === undefined) continue;
|
|
214
|
+
|
|
215
|
+
const suffixMap = DURATION_STYLE_SUFFIX_MAP[unit];
|
|
216
|
+
const suffix = value === 1 ? suffixMap[style] : suffixMap[stylePlural];
|
|
217
|
+
a.push(value + space + suffix);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const separator = getDurationTypeSeparator(style);
|
|
221
|
+
return a.join(separator);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Convert a millisecond duration into a human-readable duration string.
|
|
226
|
+
*
|
|
227
|
+
* @param options.durationTypeForZero - Defaults to 'milliseconds'
|
|
228
|
+
* @param options.style - Defaults to 'short'
|
|
229
|
+
*/
|
|
230
|
+
export function readableDuration(
|
|
231
|
+
ms: number,
|
|
232
|
+
options?: { durationTypeForZero?: DurationType; style?: DurationStyle },
|
|
233
|
+
): string {
|
|
234
|
+
const duration = msToDuration(ms, options?.durationTypeForZero);
|
|
235
|
+
|
|
236
|
+
return formatDuration(duration, options?.style);
|
|
237
|
+
}
|
package/src/kvStore.ts
CHANGED
|
@@ -168,12 +168,12 @@ export class KVStore {
|
|
|
168
168
|
public async set<T>(
|
|
169
169
|
key: string,
|
|
170
170
|
value: T,
|
|
171
|
-
|
|
171
|
+
expiryDeltaMs: number = this.defaultExpiryDeltaMs,
|
|
172
172
|
): Promise<T> {
|
|
173
173
|
const obj = {
|
|
174
174
|
key,
|
|
175
175
|
value,
|
|
176
|
-
expireMs: Date.now() +
|
|
176
|
+
expireMs: Date.now() + expiryDeltaMs,
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
return await this.transact<T>(
|
|
@@ -380,3 +380,39 @@ export const kvStore = new KVStore(
|
|
|
380
380
|
DEFAULT_DB_VERSION,
|
|
381
381
|
DEFAULT_EXPIRY_DELTA_MS,
|
|
382
382
|
);
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Class to represent one key in the store with a default expiration.
|
|
386
|
+
*/
|
|
387
|
+
class KvStoreItem<T> {
|
|
388
|
+
public constructor(
|
|
389
|
+
public readonly key: string,
|
|
390
|
+
public readonly defaultExpiryDeltaMs: number,
|
|
391
|
+
public readonly store = kvStore,
|
|
392
|
+
) {}
|
|
393
|
+
|
|
394
|
+
public async get(): Promise<Awaited<T> | undefined> {
|
|
395
|
+
return await this.store.get(this.key);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
public async set(
|
|
399
|
+
value: T,
|
|
400
|
+
expiryDeltaMs: number = this.defaultExpiryDeltaMs,
|
|
401
|
+
): Promise<void> {
|
|
402
|
+
await this.store.set(this.key, value, expiryDeltaMs);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
public async delete(): Promise<void> {
|
|
406
|
+
await this.store.delete(this.key);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Create a KV store item with a key and a default expiration.
|
|
412
|
+
*/
|
|
413
|
+
export function kvStoreItem<T>(
|
|
414
|
+
key: string,
|
|
415
|
+
defaultExpiryDeltaMs: number,
|
|
416
|
+
): KvStoreItem<T> {
|
|
417
|
+
return new KvStoreItem<T>(key, defaultExpiryDeltaMs);
|
|
418
|
+
}
|
package/src/localStorageCache.ts
CHANGED
|
@@ -1,26 +1,73 @@
|
|
|
1
|
+
import { Duration, durationToMs } from "./duration";
|
|
2
|
+
|
|
3
|
+
export type StoredItem<T> = { value: T; expireMs: number };
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Simple local storage cache with support for auto-expiration.
|
|
3
7
|
* Note that this works in the browser context only because nodejs does not
|
|
4
8
|
* have local storage.
|
|
9
|
+
*
|
|
10
|
+
* Create a cache item accessor object with auto-expiration. The value will
|
|
11
|
+
* always be stored as a string by applying JSON.stringify(), and will be
|
|
12
|
+
* returned in the same object type by applying JSON.parse().
|
|
13
|
+
*
|
|
14
|
+
* In order to provide proper type-checking, please always specify the T
|
|
15
|
+
* type parameter. E.g. const item = storeItem<string>("name", 10_000);
|
|
16
|
+
*
|
|
17
|
+
* @param key The store key in local storage.
|
|
18
|
+
* @param expires Either a number in milliseconds, or a Duration object
|
|
19
|
+
* @param logError Log an error if we found an invalid object in the store.
|
|
20
|
+
* The invalid object is usually a string that cannot be parsed as JSON.
|
|
21
|
+
* @param defaultValue Specify a default value to use for the object. Defaults
|
|
22
|
+
* to undefined.
|
|
5
23
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
24
|
+
export function storeItem<T>(
|
|
25
|
+
key: string,
|
|
26
|
+
expires: number | Duration,
|
|
27
|
+
logError = true,
|
|
28
|
+
defaultValue?: T,
|
|
29
|
+
) {
|
|
30
|
+
const expireDeltaMs =
|
|
31
|
+
typeof expires === "number" ? expires : durationToMs(expires);
|
|
32
|
+
|
|
33
|
+
return new CacheItem<T>(key, expireDeltaMs, logError, defaultValue);
|
|
34
|
+
}
|
|
10
35
|
|
|
11
|
-
|
|
36
|
+
class CacheItem<T> {
|
|
37
|
+
/**
|
|
38
|
+
* Create a cache item accessor object with auto-expiration.
|
|
39
|
+
*/
|
|
40
|
+
public constructor(
|
|
41
|
+
public readonly key: string,
|
|
42
|
+
public readonly expireDeltaMs: number,
|
|
43
|
+
public readonly logError: boolean,
|
|
44
|
+
public readonly defaultValue: T | undefined,
|
|
45
|
+
) {}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set the value of this item with auto-expiration.
|
|
49
|
+
*/
|
|
50
|
+
public set(value: T): void {
|
|
51
|
+
const expireMs = Date.now() + this.expireDeltaMs;
|
|
52
|
+
const toStore: StoredItem<T> = { value, expireMs };
|
|
53
|
+
const valueStr = JSON.stringify(toStore);
|
|
54
|
+
|
|
55
|
+
globalThis.localStorage.setItem(this.key, valueStr);
|
|
12
56
|
}
|
|
13
57
|
|
|
14
|
-
|
|
15
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Get the value of this item, or undefined if value is not set or expired.
|
|
60
|
+
*/
|
|
61
|
+
public get(): T | undefined {
|
|
62
|
+
const jsonStr = globalThis.localStorage.getItem(this.key);
|
|
16
63
|
|
|
17
|
-
if (!jsonStr
|
|
18
|
-
return
|
|
64
|
+
if (!jsonStr) {
|
|
65
|
+
return this.defaultValue;
|
|
19
66
|
}
|
|
20
67
|
|
|
21
68
|
try {
|
|
22
|
-
const obj:
|
|
23
|
-
|
|
69
|
+
const obj: StoredItem<T> | undefined = JSON.parse(jsonStr);
|
|
70
|
+
|
|
24
71
|
if (
|
|
25
72
|
!obj ||
|
|
26
73
|
typeof obj !== "object" ||
|
|
@@ -29,41 +76,27 @@ export class LocalStorageCache {
|
|
|
29
76
|
typeof obj.expireMs !== "number" ||
|
|
30
77
|
Date.now() >= obj.expireMs
|
|
31
78
|
) {
|
|
32
|
-
|
|
33
|
-
return
|
|
79
|
+
this.remove();
|
|
80
|
+
return this.defaultValue;
|
|
34
81
|
}
|
|
35
82
|
|
|
36
83
|
return obj.value;
|
|
37
84
|
} catch (e) {
|
|
38
|
-
if (logError) {
|
|
39
|
-
console.error(
|
|
85
|
+
if (this.logError) {
|
|
86
|
+
console.error(
|
|
87
|
+
`Found invalid storage value: ${this.key}=${jsonStr}:`,
|
|
88
|
+
e,
|
|
89
|
+
);
|
|
40
90
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
91
|
+
this.remove();
|
|
92
|
+
return this.defaultValue;
|
|
43
93
|
}
|
|
44
94
|
}
|
|
45
|
-
}
|
|
46
95
|
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
public readonly logError = true,
|
|
53
|
-
defaultValue?: T,
|
|
54
|
-
) {
|
|
55
|
-
if (defaultValue !== undefined) {
|
|
56
|
-
if (this.get() === undefined) {
|
|
57
|
-
this.set(defaultValue);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public set(value: T) {
|
|
63
|
-
LocalStorageCache.setValue(this.key, value, this.expireDeltaMs);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public get(): T | undefined {
|
|
67
|
-
return LocalStorageCache.getValue(this.key, this.logError);
|
|
96
|
+
/**
|
|
97
|
+
* Remove the value of this item.
|
|
98
|
+
*/
|
|
99
|
+
public remove(): void {
|
|
100
|
+
globalThis.localStorage.removeItem(this.key);
|
|
68
101
|
}
|
|
69
102
|
}
|
package/src/nonEmpty.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { isEmpty } from "./isEmpty";
|
|
|
3
3
|
/**
|
|
4
4
|
* Type asserts that `t` is truthy.
|
|
5
5
|
* Throws an error if `t` is null or undefined.
|
|
6
|
+
*
|
|
7
|
+
* @param varName The variable name to include in the error to throw when t is
|
|
8
|
+
* empty. Defaults to 'value'.
|
|
6
9
|
*/
|
|
7
10
|
export function nonEmpty<T>(
|
|
8
11
|
t: T | null | undefined | "" | 0 | -0 | 0n | false | typeof NaN,
|
package/src/nonNil.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type asserts that `t` is neither null nor undefined.
|
|
3
3
|
* Throws an error if `t` is null or undefined.
|
|
4
|
+
*
|
|
5
|
+
* @param varName The variable name to include in the error to throw when t is
|
|
6
|
+
* nil. Defaults to 'value'.
|
|
4
7
|
*/
|
|
5
8
|
export function nonNil<T>(t: T | null | undefined, varName = "value"): T {
|
|
6
9
|
if (t === null || t === undefined) {
|
package/src/safeParseInt.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns 0 if the string is not a valid number.
|
|
3
|
+
*
|
|
4
|
+
* @param logError Log a console error if the given string is not a valid
|
|
5
|
+
* number. Defaults to false (don't log anything).
|
|
3
6
|
*/
|
|
4
7
|
export function safeParseInt(s: string, logError = false): number {
|
|
5
8
|
const i = Number(s);
|
package/src/sleep.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sleep for a given number of milliseconds. Note that this method is async,
|
|
3
|
+
* so please remember to call it with await, like `await sleep(1000);`.
|
|
4
|
+
*/
|
|
1
5
|
export function sleep(ms: number): Promise<void> {
|
|
2
6
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
7
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note that month and year do not have fixed durations, and hence are excluded
|
|
3
|
+
* from this file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const MS_PER_SECOND = 1000;
|
|
7
|
+
export const MS_PER_MINUTE = 60_000;
|
|
8
|
+
export const MS_PER_HOUR = 3_600_000;
|
|
9
|
+
export const MS_PER_DAY = 86_400_000;
|
|
10
|
+
export const MS_PER_WEEK = 604_800_000;
|
|
11
|
+
|
|
12
|
+
export const SECONDS_PER_MINUTE = 60;
|
|
13
|
+
export const SECONDS_PER_HOUR = 3_600;
|
|
14
|
+
export const SECONDS_PER_DAY = 86_400;
|
|
15
|
+
export const SECONDS_PER_WEEK = 604_800;
|
|
16
|
+
|
|
17
|
+
export const MINUTES_PER_HOUR = 60;
|
|
18
|
+
export const MINUTES_PER_DAY = 1440;
|
|
19
|
+
export const MINUTES_PER_WEEK = 10_080;
|
|
20
|
+
|
|
21
|
+
export const HOURS_PER_DAY = 24;
|
|
22
|
+
export const HOURS_PER_WEEK = 168;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note that month and year do not have fixed durations, and hence are excluded
|
|
3
|
+
* from this file.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MS_PER_SECOND = 1000;
|
|
6
|
+
export declare const MS_PER_MINUTE = 60000;
|
|
7
|
+
export declare const MS_PER_HOUR = 3600000;
|
|
8
|
+
export declare const MS_PER_DAY = 86400000;
|
|
9
|
+
export declare const MS_PER_WEEK = 604800000;
|
|
10
|
+
export declare const SECONDS_PER_MINUTE = 60;
|
|
11
|
+
export declare const SECONDS_PER_HOUR = 3600;
|
|
12
|
+
export declare const SECONDS_PER_DAY = 86400;
|
|
13
|
+
export declare const SECONDS_PER_WEEK = 604800;
|
|
14
|
+
export declare const MINUTES_PER_HOUR = 60;
|
|
15
|
+
export declare const MINUTES_PER_DAY = 1440;
|
|
16
|
+
export declare const MINUTES_PER_WEEK = 10080;
|
|
17
|
+
export declare const HOURS_PER_DAY = 24;
|
|
18
|
+
export declare const HOURS_PER_WEEK = 168;
|
package/timeConstants.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/timeConstants.ts
|
|
21
|
+
var timeConstants_exports = {};
|
|
22
|
+
__export(timeConstants_exports, {
|
|
23
|
+
HOURS_PER_DAY: () => HOURS_PER_DAY,
|
|
24
|
+
HOURS_PER_WEEK: () => HOURS_PER_WEEK,
|
|
25
|
+
MINUTES_PER_DAY: () => MINUTES_PER_DAY,
|
|
26
|
+
MINUTES_PER_HOUR: () => MINUTES_PER_HOUR,
|
|
27
|
+
MINUTES_PER_WEEK: () => MINUTES_PER_WEEK,
|
|
28
|
+
MS_PER_DAY: () => MS_PER_DAY,
|
|
29
|
+
MS_PER_HOUR: () => MS_PER_HOUR,
|
|
30
|
+
MS_PER_MINUTE: () => MS_PER_MINUTE,
|
|
31
|
+
MS_PER_SECOND: () => MS_PER_SECOND,
|
|
32
|
+
MS_PER_WEEK: () => MS_PER_WEEK,
|
|
33
|
+
SECONDS_PER_DAY: () => SECONDS_PER_DAY,
|
|
34
|
+
SECONDS_PER_HOUR: () => SECONDS_PER_HOUR,
|
|
35
|
+
SECONDS_PER_MINUTE: () => SECONDS_PER_MINUTE,
|
|
36
|
+
SECONDS_PER_WEEK: () => SECONDS_PER_WEEK
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(timeConstants_exports);
|
|
39
|
+
var MS_PER_SECOND = 1e3;
|
|
40
|
+
var MS_PER_MINUTE = 6e4;
|
|
41
|
+
var MS_PER_HOUR = 36e5;
|
|
42
|
+
var MS_PER_DAY = 864e5;
|
|
43
|
+
var MS_PER_WEEK = 6048e5;
|
|
44
|
+
var SECONDS_PER_MINUTE = 60;
|
|
45
|
+
var SECONDS_PER_HOUR = 3600;
|
|
46
|
+
var SECONDS_PER_DAY = 86400;
|
|
47
|
+
var SECONDS_PER_WEEK = 604800;
|
|
48
|
+
var MINUTES_PER_HOUR = 60;
|
|
49
|
+
var MINUTES_PER_DAY = 1440;
|
|
50
|
+
var MINUTES_PER_WEEK = 10080;
|
|
51
|
+
var HOURS_PER_DAY = 24;
|
|
52
|
+
var HOURS_PER_WEEK = 168;
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
HOURS_PER_DAY,
|
|
56
|
+
HOURS_PER_WEEK,
|
|
57
|
+
MINUTES_PER_DAY,
|
|
58
|
+
MINUTES_PER_HOUR,
|
|
59
|
+
MINUTES_PER_WEEK,
|
|
60
|
+
MS_PER_DAY,
|
|
61
|
+
MS_PER_HOUR,
|
|
62
|
+
MS_PER_MINUTE,
|
|
63
|
+
MS_PER_SECOND,
|
|
64
|
+
MS_PER_WEEK,
|
|
65
|
+
SECONDS_PER_DAY,
|
|
66
|
+
SECONDS_PER_HOUR,
|
|
67
|
+
SECONDS_PER_MINUTE,
|
|
68
|
+
SECONDS_PER_WEEK
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=timeConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/timeConstants.ts"],"sourcesContent":["/**\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file.\n */\n\nexport const MS_PER_SECOND = 1000;\nexport const MS_PER_MINUTE = 60_000;\nexport const MS_PER_HOUR = 3_600_000;\nexport const MS_PER_DAY = 86_400_000;\nexport const MS_PER_WEEK = 604_800_000;\n\nexport const SECONDS_PER_MINUTE = 60;\nexport const SECONDS_PER_HOUR = 3_600;\nexport const SECONDS_PER_DAY = 86_400;\nexport const SECONDS_PER_WEEK = 604_800;\n\nexport const MINUTES_PER_HOUR = 60;\nexport const MINUTES_PER_DAY = 1440;\nexport const MINUTES_PER_WEEK = 10_080;\n\nexport const HOURS_PER_DAY = 24;\nexport const HOURS_PER_WEEK = 168;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AACtB,IAAM,cAAc;AACpB,IAAM,aAAa;AACnB,IAAM,cAAc;AAEpB,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAEzB,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAEzB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;","names":[]}
|