@magmacomputing/tempo 1.0.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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/array.library.d.ts +25 -0
- package/dist/array.library.js +78 -0
- package/dist/buffer.library.d.ts +6 -0
- package/dist/buffer.library.js +192 -0
- package/dist/cipher.class.d.ts +18 -0
- package/dist/cipher.class.js +65 -0
- package/dist/class.library.d.ts +10 -0
- package/dist/class.library.js +57 -0
- package/dist/coercion.library.d.ts +14 -0
- package/dist/coercion.library.js +71 -0
- package/dist/enumerate.library.d.ts +64 -0
- package/dist/enumerate.library.js +54 -0
- package/dist/function.library.d.ts +9 -0
- package/dist/function.library.js +49 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/logify.class.d.ts +33 -0
- package/dist/logify.class.js +53 -0
- package/dist/number.library.d.ts +16 -0
- package/dist/number.library.js +36 -0
- package/dist/object.library.d.ts +37 -0
- package/dist/object.library.js +94 -0
- package/dist/pledge.class.d.ts +54 -0
- package/dist/pledge.class.js +131 -0
- package/dist/prototype.library.d.ts +33 -0
- package/dist/prototype.library.js +51 -0
- package/dist/reflection.library.d.ts +74 -0
- package/dist/reflection.library.js +97 -0
- package/dist/serialize.library.d.ts +25 -0
- package/dist/serialize.library.js +266 -0
- package/dist/storage.library.d.ts +8 -0
- package/dist/storage.library.js +57 -0
- package/dist/string.library.d.ts +37 -0
- package/dist/string.library.js +93 -0
- package/dist/tempo.class.d.ts +556 -0
- package/dist/tempo.class.js +1412 -0
- package/dist/tempo.config/plugins/term.import.d.ts +42 -0
- package/dist/tempo.config/plugins/term.import.js +44 -0
- package/dist/tempo.config/plugins/term.quarter.d.ts +7 -0
- package/dist/tempo.config/plugins/term.quarter.js +28 -0
- package/dist/tempo.config/plugins/term.season.d.ts +7 -0
- package/dist/tempo.config/plugins/term.season.js +36 -0
- package/dist/tempo.config/plugins/term.timeline.d.ts +7 -0
- package/dist/tempo.config/plugins/term.timeline.js +19 -0
- package/dist/tempo.config/plugins/term.utils.d.ts +17 -0
- package/dist/tempo.config/plugins/term.utils.js +38 -0
- package/dist/tempo.config/plugins/term.zodiac.d.ts +7 -0
- package/dist/tempo.config/plugins/term.zodiac.js +62 -0
- package/dist/tempo.config/tempo.default.d.ts +169 -0
- package/dist/tempo.config/tempo.default.js +158 -0
- package/dist/tempo.config/tempo.enum.d.ts +99 -0
- package/dist/tempo.config/tempo.enum.js +78 -0
- package/dist/temporal.polyfill.d.ts +9 -0
- package/dist/temporal.polyfill.js +18 -0
- package/dist/type.library.d.ts +296 -0
- package/dist/type.library.js +80 -0
- package/dist/utility.library.d.ts +32 -0
- package/dist/utility.library.js +54 -0
- package/package.json +54 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { asNumber, asString, isNumeric } from './coercion.library.js';
|
|
2
|
+
import { stringify } from './serialize.library.js';
|
|
3
|
+
import { isString, isObject, assertCondition, assertString, nullToValue } from './type.library.js';
|
|
4
|
+
// General <string> functions
|
|
5
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
6
|
+
// This section needs to be Function declarations so that they are hoisted
|
|
7
|
+
// (because they are referenced in prototype.library)
|
|
8
|
+
/**
|
|
9
|
+
* clean a string to remove some standard control-characters (tab, line-feed, carriage-return) and trim redundant spaces.
|
|
10
|
+
* allow for optional RegExp to specify additional match
|
|
11
|
+
*/
|
|
12
|
+
export function trimAll(str, pat) {
|
|
13
|
+
return str
|
|
14
|
+
.toString() // coerce to String
|
|
15
|
+
.replace(pat, '') // remove regexp, if supplied
|
|
16
|
+
.replace(/\t/g, ' ') // replace <tab> with <space>
|
|
17
|
+
.replace(/(\r\n|\n|\r)/g, ' ') // replace <return> & <newline>
|
|
18
|
+
.replace(/\s{2,}/g, ' ') // trim multiple <space>
|
|
19
|
+
.trim(); // leading/trailing <space>
|
|
20
|
+
}
|
|
21
|
+
/** every word has its first letter capitalized */
|
|
22
|
+
export function toProperCase(...str) {
|
|
23
|
+
return str
|
|
24
|
+
.flat() // in case {str} was already an array
|
|
25
|
+
.map(text => text.replace(/\w\S*/g, word => word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()))
|
|
26
|
+
.join(' ');
|
|
27
|
+
}
|
|
28
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
29
|
+
const PAT = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g;
|
|
30
|
+
export const toCamelCase = (sentence) => {
|
|
31
|
+
let [word, ...rest] = sentence.match(PAT) ?? [''];
|
|
32
|
+
if (isNumeric(word)) {
|
|
33
|
+
word = rest[0];
|
|
34
|
+
rest.splice(0, 1);
|
|
35
|
+
}
|
|
36
|
+
return (sentence.startsWith('_') ? '_' : '') + word.toLocaleLowerCase() + toProperCase(...rest).replace(/ /g, '');
|
|
37
|
+
};
|
|
38
|
+
const HEX = 16;
|
|
39
|
+
export const randomString = (len = 36) => {
|
|
40
|
+
let str = '';
|
|
41
|
+
do // generate random strings
|
|
42
|
+
str += Math.floor(Math.random() * 10 ** 16).toString(HEX).substring(2, 15);
|
|
43
|
+
while (str.length < len);
|
|
44
|
+
return str.substring(0, len);
|
|
45
|
+
};
|
|
46
|
+
export function sprintf(fmt, ...msg) {
|
|
47
|
+
const regexp = /\$\{(\d)\}/g; // pattern to find "${digit}" parameter markers
|
|
48
|
+
let sfmt = asString(fmt); // avoid mutate fmt
|
|
49
|
+
if (!isString(fmt)) { // might be an Object
|
|
50
|
+
msg.unshift(JSON.stringify(fmt)); // push to start of msg[]
|
|
51
|
+
sfmt = ''; // reset the string-format
|
|
52
|
+
}
|
|
53
|
+
let cnt = 0; // if the format does not contain a corresponding '${digit}' then re-construct the parameters
|
|
54
|
+
sfmt = sfmt.replace(/%[sj]/g, _ => `\${${cnt++}}`); // flip all the %s or %j to a ${digit} parameter
|
|
55
|
+
const params = Array.from(sfmt.matchAll(regexp))
|
|
56
|
+
.map(match => Number(match[1])); // which parameters are in the fmt
|
|
57
|
+
msg.forEach((_, idx) => {
|
|
58
|
+
if (!params.includes(idx)) // if more args than params
|
|
59
|
+
sfmt += `${sfmt.length === 0 ? '' : sfmt.endsWith(':') ? ' ' : ', '}\${${idx}}`; // append a dummy params to fmt
|
|
60
|
+
});
|
|
61
|
+
// 2024-02-21 some Objects do not have a .toString method
|
|
62
|
+
return sfmt.replace(regexp, (_, idx) => msg[idx]?.toString?.() || stringify(msg[idx]));
|
|
63
|
+
}
|
|
64
|
+
/** apply a plural suffix, if greater than '1' */
|
|
65
|
+
export const plural = (val, word, plural = word + 's') => {
|
|
66
|
+
const _plural = (num, word, plural = word + 's') => [1, -1].includes(Number(num)) ? word : plural;
|
|
67
|
+
return isObject(val)
|
|
68
|
+
? (num, word) => _plural(num, word, val[word])
|
|
69
|
+
: _plural(val, word, plural);
|
|
70
|
+
};
|
|
71
|
+
/** strip a plural suffix, if endsWith 's' */
|
|
72
|
+
export const singular = (val) => val.endsWith('s') ? val.slice(0, -1) : val;
|
|
73
|
+
/** make an Object's values into a Template Literals, and evaluate */
|
|
74
|
+
export const makeTemplate = (templateString) => (templateData) => new Function(`{${Object.keys(templateData).join(',')}}`, 'return `' + templateString + '`')(templateData);
|
|
75
|
+
/** stringify if not nullish */
|
|
76
|
+
export { asString } from './coercion.library.js';
|
|
77
|
+
export const toLower = (str) => isString(str) ? asString(str).toLowerCase().trim() : str;
|
|
78
|
+
export const toUpper = (str) => isString(str) ? asString(str).toUpperCase().trim() : str;
|
|
79
|
+
export const strlen = (str, min, max) => {
|
|
80
|
+
assertString(str);
|
|
81
|
+
assertCondition(str.length >= min && str.length <= (max ?? min), 'string length is not between specified min and max');
|
|
82
|
+
return str;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* pad a string with leading character
|
|
86
|
+
* @param nbr input value to pad
|
|
87
|
+
* @param len fill-length (default: 2)
|
|
88
|
+
* @param fill character (default \<space> for string and \<zero> for number)
|
|
89
|
+
* @returns fixed-length string padded on the left with fill-character
|
|
90
|
+
*/
|
|
91
|
+
export const pad = (nbr = 0, len = 2, fill) => nbr.toString().padStart(len, nullToValue(fill, isNumeric(nbr) ? '0' : ' ').toString());
|
|
92
|
+
/** pad a string with non-blocking spaces, to help right-align a display */
|
|
93
|
+
export const padString = (str, pad = 6) => (isNumeric(str) ? asNumber(str).toFixed(2).toString() : str.toString() ?? '').padStart(pad, '\u007F');
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import type { IntRange, LiteralKey, LooseUnion, NonOptional, Property, Type } from './type.library.js';
|
|
2
|
+
import * as enums from './tempo.config/tempo.enum.js';
|
|
3
|
+
import { Token, Snippet, Layout, Event, Period } from './tempo.config/tempo.default.js';
|
|
4
|
+
import './prototype.library.js';
|
|
5
|
+
/**
|
|
6
|
+
* # Tempo
|
|
7
|
+
* **Tempo** is a powerful wrapper around `Temporal.ZonedDateTime` designed for flexible parsing and intuitive manipulation of date-time objects.
|
|
8
|
+
*
|
|
9
|
+
* It bridges the gap between raw string/number inputs and the strict requirements of the ECMAScript Temporal API.
|
|
10
|
+
*
|
|
11
|
+
* ### Key Features
|
|
12
|
+
* - **Flexible Parsing**: Interprets strings, numbers, BigInts, and various Temporal objects.
|
|
13
|
+
* - **Static Utility**: Access to common enums like `WEEKDAY`, `MONTH` and `SEASON`.
|
|
14
|
+
* - **Fluent API**: Methods for adding, setting, formatting, and comparing date-times.
|
|
15
|
+
* - **Alias Parsing**: Define custom `events` (e.g., "xmas" → "25 Dec") and `periods` (e.g., "noon" → "12:00") for intuitive parsing.
|
|
16
|
+
* - **Plugin System**: Extensible via "terms" to provide contextual date calculations (e.g., quarters, seasons, zodiac signs, etc.).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Standard parsing
|
|
21
|
+
* const t1 = new Tempo('2024-05-20');
|
|
22
|
+
*
|
|
23
|
+
* // Using an event alias (pre-defined or custom)
|
|
24
|
+
* const t2 = new Tempo('christmas'); // Dec 25th
|
|
25
|
+
*
|
|
26
|
+
* // Using a period alias
|
|
27
|
+
* const t3 = new Tempo('2024-05-20 midnight'); // 2024-05-20T00:00:00
|
|
28
|
+
*
|
|
29
|
+
* // Custom events and periods for this instance
|
|
30
|
+
* const t4 = new Tempo('birthday', {
|
|
31
|
+
* event: [['birthday', '20 May']],
|
|
32
|
+
* period: [['tea-time', '15:30']]
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class Tempo {
|
|
37
|
+
#private;
|
|
38
|
+
/** Weekday names (short-form) */ static get WEEKDAY(): import("./enumerate.library.js").Enum.wrap<import("./type.library.js").Index<readonly ["All", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]>>;
|
|
39
|
+
/** Weekday names (long-form) */ static get WEEKDAYS(): import("./enumerate.library.js").Enum.wrap<import("./type.library.js").Index<readonly ["Everyday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]>>;
|
|
40
|
+
/** Month names (short-form) */ static get MONTH(): import("./enumerate.library.js").Enum.wrap<import("./type.library.js").Index<readonly ["All", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]>>;
|
|
41
|
+
/** Month names (long-form) */ static get MONTHS(): import("./enumerate.library.js").Enum.wrap<import("./type.library.js").Index<readonly ["Every", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]>>;
|
|
42
|
+
/** Time durations as seconds (singular) */ static get DURATION(): import("./enumerate.library.js").Enum.wrap<{
|
|
43
|
+
readonly year: 31536000;
|
|
44
|
+
readonly month: 2628000;
|
|
45
|
+
readonly week: 604800;
|
|
46
|
+
readonly day: 86400;
|
|
47
|
+
readonly hour: 3600;
|
|
48
|
+
readonly minute: 60;
|
|
49
|
+
readonly second: 1;
|
|
50
|
+
readonly millisecond: 0.001;
|
|
51
|
+
readonly microsecond: 0.000001;
|
|
52
|
+
readonly nanosecond: 1e-9;
|
|
53
|
+
}>;
|
|
54
|
+
/** Time durations as milliseconds (plural) */ static get DURATIONS(): import("./enumerate.library.js").Enum.wrap<{
|
|
55
|
+
readonly years: number;
|
|
56
|
+
readonly months: number;
|
|
57
|
+
readonly weeks: number;
|
|
58
|
+
readonly days: number;
|
|
59
|
+
readonly hours: number;
|
|
60
|
+
readonly minutes: number;
|
|
61
|
+
readonly seconds: number;
|
|
62
|
+
readonly milliseconds: number;
|
|
63
|
+
readonly microseconds: number;
|
|
64
|
+
readonly nanoseconds: number;
|
|
65
|
+
}>;
|
|
66
|
+
/** Quarterly Seasons */ static get SEASON(): import("./enumerate.library.js").Enum.wrap<{
|
|
67
|
+
readonly Summer: "summer";
|
|
68
|
+
readonly Autumn: "autumn";
|
|
69
|
+
readonly Winter: "winter";
|
|
70
|
+
readonly Spring: "spring";
|
|
71
|
+
}>;
|
|
72
|
+
/** Compass cardinal points */ static get COMPASS(): import("./enumerate.library.js").Enum.wrap<{
|
|
73
|
+
readonly North: "north";
|
|
74
|
+
readonly East: "east";
|
|
75
|
+
readonly South: "south";
|
|
76
|
+
readonly West: "west";
|
|
77
|
+
}>;
|
|
78
|
+
/** Tempo to Temporal DateTime Units map */ static get ELEMENT(): import("./enumerate.library.js").Enum.wrap<{
|
|
79
|
+
readonly yy: "year";
|
|
80
|
+
readonly mm: "month";
|
|
81
|
+
readonly ww: "week";
|
|
82
|
+
readonly dd: "day";
|
|
83
|
+
readonly hh: "hour";
|
|
84
|
+
readonly mi: "minute";
|
|
85
|
+
readonly ss: "second";
|
|
86
|
+
readonly ms: "millisecond";
|
|
87
|
+
readonly us: "microsecond";
|
|
88
|
+
readonly ns: "nanosecond";
|
|
89
|
+
}>;
|
|
90
|
+
/** Pre-configured format {name -> string} pairs */ static get FORMAT(): import("./enumerate.library.js").Enum.wrap<{
|
|
91
|
+
readonly display: "{www}, {dd} {mmm} {yyyy}";
|
|
92
|
+
readonly weekDate: "{www}, {yyyy}-{mmm}-{dd}";
|
|
93
|
+
readonly weekTime: "{www}, {yyyy}-{mmm}-{dd} {hh}:{mi}:{ss}";
|
|
94
|
+
readonly weekStamp: "{www}, {yyyy}-{mmm}-{dd} {hh}:{mi}:{ss}.{ff}";
|
|
95
|
+
readonly dayMonth: "{dd}-{mmm}";
|
|
96
|
+
readonly dayDate: "{dd}-{mmm}-{yyyy}";
|
|
97
|
+
readonly dayTime: "{dd}-{mmm}-{yyyy} {hh}:{mi}:{ss}";
|
|
98
|
+
readonly logStamp: "{yyyy}{mm}{dd}T{hhmiss}.{ff}";
|
|
99
|
+
readonly sortTime: "{yyyy}-{mm}-{dd} {hh}:{mi}:{ss}";
|
|
100
|
+
readonly yearWeek: "{yyyy}{ww}";
|
|
101
|
+
readonly yearMonth: "{yyyy}{mm}";
|
|
102
|
+
readonly yearMonthDay: "{yyyy}{mm}{dd}";
|
|
103
|
+
readonly date: "{yyyy}-{mm}-{dd}";
|
|
104
|
+
readonly time: "{hh}:{mi}:{ss}";
|
|
105
|
+
}>;
|
|
106
|
+
/** some useful Dates */ static get LIMIT(): import("./type.library.js").SecureObject<{
|
|
107
|
+
readonly maxTempo: bigint;
|
|
108
|
+
readonly minTempo: bigint;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Initializes the global default configuration for all subsequent `Tempo` instances.
|
|
112
|
+
*
|
|
113
|
+
* Settings are inherited in this priority:
|
|
114
|
+
* 1. Reasonable library defaults (defined in tempo.config.js)
|
|
115
|
+
* 2. Persistent storage (e.g. localStorage), if available.
|
|
116
|
+
* 3. `options` provided to this method.
|
|
117
|
+
*
|
|
118
|
+
* @param options - Configuration overrides to apply globally.
|
|
119
|
+
* @returns The resolved global configuration.
|
|
120
|
+
*/
|
|
121
|
+
static init(options?: Tempo.Options): Tempo.Config;
|
|
122
|
+
/**
|
|
123
|
+
* Reads `Tempo` options from persistent storage (e.g., localStorage).
|
|
124
|
+
* @returns The stored configuration or an empty object.
|
|
125
|
+
*/
|
|
126
|
+
static readStore(key?: string): Partial<{
|
|
127
|
+
/** localStorage key */ store: string;
|
|
128
|
+
/** additional console.log for tracking */ debug: boolean | undefined;
|
|
129
|
+
/** catch or throw Errors */ catch: boolean | undefined;
|
|
130
|
+
/** Temporal timeZone */ timeZone: string;
|
|
131
|
+
/** Temporal calendar */ calendar: string;
|
|
132
|
+
/** locale (e.g. en-AU) */ locale: string;
|
|
133
|
+
/** pivot year for two-digit years */ pivot: number;
|
|
134
|
+
/** hemisphere for term.qtr or term.szn */ sphere: Tempo.COMPASS | undefined;
|
|
135
|
+
/** granularity of timestamps (ms | ns) */ timeStamp: Tempo.TimeStamp;
|
|
136
|
+
/** locale-names that prefer 'mm-dd-yy' date order */ mdyLocales: string | string[];
|
|
137
|
+
/** swap parse-order of layouts */ mdyLayouts: Internal.StringTuple[];
|
|
138
|
+
/** date-time snippets to help compose a Layout */ snippet: Snippet | Internal.PatternOption<string | RegExp>;
|
|
139
|
+
/** patterns to help parse value */ layout: Layout | Internal.PatternOption<string | RegExp>;
|
|
140
|
+
/** custom date aliases (events). */ event: Event | Internal.PatternOption<string | Function>;
|
|
141
|
+
/** custom time aliases (periods). */ period: Period | Internal.PatternOption<string | Function>;
|
|
142
|
+
/** supplied value to parse */ value: Tempo.DateTime;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Writes the provided configuration into persistent storage.
|
|
146
|
+
* @param config - The options to save.
|
|
147
|
+
*/
|
|
148
|
+
static writeStore(config?: Tempo.Options, key?: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* looks-up or registers a new `Symbol` for a given key.
|
|
151
|
+
* auto-maintains the `Token` registry for internal consistency.
|
|
152
|
+
*
|
|
153
|
+
* @param key - The description for which to retrieve/create a Symbol.
|
|
154
|
+
*/
|
|
155
|
+
static getSymbol(key?: string | symbol): symbol;
|
|
156
|
+
/**
|
|
157
|
+
* translates a {layout} string into an anchored, case-insensitive regular expression.
|
|
158
|
+
* supports placeholder expansion using the {snippet} registry (e.g., `{yy}`, `{mm}`).
|
|
159
|
+
*/
|
|
160
|
+
static regexp(layout: string | RegExp, snippet?: Snippet): RegExp;
|
|
161
|
+
/**
|
|
162
|
+
* Compares two `Tempo` instances or date-time values.
|
|
163
|
+
* Useful for sorting or determining chronological order.
|
|
164
|
+
*
|
|
165
|
+
* @param tempo1 - The first value to compare.
|
|
166
|
+
* @param tempo2 - The second value to compare (defaults to 'now').
|
|
167
|
+
* @returns `-1` if `tempo1 < tempo2`, `0` if tempo1 == tempo2, `1` if `tempo1 > tempo2`.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const sorted = [t1, t2].sort(Tempo.compare);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
static compare(tempo1?: Tempo.DateTime | Tempo.Options, tempo2?: Tempo.DateTime | Tempo.Options): number;
|
|
175
|
+
/** Creates a new `Tempo` instance. */
|
|
176
|
+
static from(options?: Tempo.Options): Tempo;
|
|
177
|
+
static from(tempo: Tempo.DateTime | undefined, options?: Tempo.Options): Tempo;
|
|
178
|
+
/** Returns current time as epoch nanoseconds (BigInt). */
|
|
179
|
+
static now(): bigint;
|
|
180
|
+
/** static Tempo.terms getter */
|
|
181
|
+
static get terms(): import("./type.library.js").SecureArray<{
|
|
182
|
+
key: string;
|
|
183
|
+
scope: string;
|
|
184
|
+
description: string;
|
|
185
|
+
}>;
|
|
186
|
+
/** static Tempo properties getter */
|
|
187
|
+
static get properties(): import("./type.library.js").SecureArray<string | number | symbol>;
|
|
188
|
+
/** Tempo global config settings */
|
|
189
|
+
static get config(): import("./type.library.js").SecureObject<{
|
|
190
|
+
readonly scope: "global" | "local";
|
|
191
|
+
readonly debug: boolean | undefined;
|
|
192
|
+
readonly timeStamp: Tempo.TimeStamp;
|
|
193
|
+
readonly store: string;
|
|
194
|
+
readonly catch: boolean | undefined;
|
|
195
|
+
readonly timeZone: string;
|
|
196
|
+
readonly calendar: string;
|
|
197
|
+
readonly locale: string;
|
|
198
|
+
readonly pivot: number;
|
|
199
|
+
readonly sphere: Tempo.COMPASS | undefined;
|
|
200
|
+
readonly snippet: Snippet | Internal.PatternOption<string | RegExp>;
|
|
201
|
+
readonly layout: Layout | Internal.PatternOption<string | RegExp>;
|
|
202
|
+
readonly event: Event | Internal.PatternOption<string | Function>;
|
|
203
|
+
readonly period: Period | Internal.PatternOption<string | Function>;
|
|
204
|
+
}>;
|
|
205
|
+
/** Tempo initial default settings */
|
|
206
|
+
static get default(): import("./type.library.js").SecureObject<import("./type.library.js").SecureObject<Partial<{
|
|
207
|
+
/** localStorage key */ store: string;
|
|
208
|
+
/** additional console.log for tracking */ debug: boolean | undefined;
|
|
209
|
+
/** catch or throw Errors */ catch: boolean | undefined;
|
|
210
|
+
/** Temporal timeZone */ timeZone: string;
|
|
211
|
+
/** Temporal calendar */ calendar: string;
|
|
212
|
+
/** locale (e.g. en-AU) */ locale: string;
|
|
213
|
+
/** pivot year for two-digit years */ pivot: number;
|
|
214
|
+
/** hemisphere for term.qtr or term.szn */ sphere: Tempo.COMPASS | undefined;
|
|
215
|
+
/** granularity of timestamps (ms | ns) */ timeStamp: Tempo.TimeStamp;
|
|
216
|
+
/** locale-names that prefer 'mm-dd-yy' date order */ mdyLocales: string | string[];
|
|
217
|
+
/** swap parse-order of layouts */ mdyLayouts: Internal.StringTuple[];
|
|
218
|
+
/** date-time snippets to help compose a Layout */ snippet: Snippet | Internal.PatternOption<string | RegExp>;
|
|
219
|
+
/** patterns to help parse value */ layout: Layout | Internal.PatternOption<string | RegExp>;
|
|
220
|
+
/** custom date aliases (events). */ event: Event | Internal.PatternOption<string | Function>;
|
|
221
|
+
/** custom time aliases (periods). */ period: Period | Internal.PatternOption<string | Function>;
|
|
222
|
+
/** supplied value to parse */ value: Tempo.DateTime;
|
|
223
|
+
}>>>;
|
|
224
|
+
/**
|
|
225
|
+
* configuration governing the static 'rules' used when parsing Tempo.DateTime argument
|
|
226
|
+
*/
|
|
227
|
+
static get parse(): import("./type.library.js").SecureObject<{
|
|
228
|
+
readonly snippet: {
|
|
229
|
+
readonly [x: symbol]: RegExp;
|
|
230
|
+
};
|
|
231
|
+
readonly layout: {
|
|
232
|
+
readonly [x: symbol]: "{dd}{sep}?{mm}({sep}?{yy})?|{mod}?({evt})" | "({hh}{mi}?{ss}?{ff}?{mer}?|{per})" | "({dt}){sfx}?" | "({wkd}{sep}+)?{dd}{sep}?{mm}({sep}?{yy})?{sfx}?" | "({wkd}{sep}+)?{mm}{sep}?{dd}({sep}?{yy})?{sfx}?" | "({wkd}{sep}+)?{yy}{sep}?{mm}({sep}?{dd})?{sfx}?" | "{mod}?{wkd}{afx}?{sfx}?" | "{mod}?{dd}{afx}?" | "{nbr}{sep}?{unt}{sep}?{afx}";
|
|
233
|
+
};
|
|
234
|
+
readonly event: {
|
|
235
|
+
readonly [x: string]: string | Function;
|
|
236
|
+
readonly 'new.?years? ?eve': "31 Dec";
|
|
237
|
+
readonly nye: "31 Dec";
|
|
238
|
+
readonly 'new.?years?( ?day)?': "01 Jan";
|
|
239
|
+
readonly ny: "01 Jan";
|
|
240
|
+
readonly 'christmas ?eve': "24 Dec";
|
|
241
|
+
readonly christmas: "25 Dec";
|
|
242
|
+
readonly 'xmas ?eve': "24 Dec";
|
|
243
|
+
readonly xmas: "25 Dec";
|
|
244
|
+
readonly now: (this: any) => Temporal.Instant;
|
|
245
|
+
readonly today: (this: any) => Temporal.PlainDate;
|
|
246
|
+
readonly tomorrow: (this: any) => Temporal.PlainDate;
|
|
247
|
+
readonly yesterday: (this: any) => Temporal.PlainDate;
|
|
248
|
+
};
|
|
249
|
+
readonly period: {
|
|
250
|
+
readonly [x: string]: string | Function;
|
|
251
|
+
readonly 'mid[ -]?night': "24:00";
|
|
252
|
+
readonly morning: "8:00";
|
|
253
|
+
readonly 'mid[ -]?morning': "10:00";
|
|
254
|
+
readonly 'mid[ -]?day': "12:00";
|
|
255
|
+
readonly noon: "12:00";
|
|
256
|
+
readonly 'after[ -]?noon': "3:00pm";
|
|
257
|
+
readonly evening: "18:00";
|
|
258
|
+
readonly night: "20:00";
|
|
259
|
+
};
|
|
260
|
+
readonly mdyLocales: {
|
|
261
|
+
locale: string;
|
|
262
|
+
timeZones: string[];
|
|
263
|
+
}[];
|
|
264
|
+
readonly mdyLayouts: Internal.StringTuple[];
|
|
265
|
+
readonly isMonthDay?: boolean;
|
|
266
|
+
readonly token: Token;
|
|
267
|
+
readonly pattern: Internal.RegexpMap;
|
|
268
|
+
readonly result: Internal.Match[];
|
|
269
|
+
}>;
|
|
270
|
+
/** iterate over Tempo properties */
|
|
271
|
+
static [Symbol.iterator](): ArrayIterator<string | number | symbol>;
|
|
272
|
+
/** allow for auto-convert of Tempo to BigInt */
|
|
273
|
+
[Symbol.toPrimitive](hint?: 'string' | 'number' | 'default'): bigint;
|
|
274
|
+
/** iterate over instance formats */
|
|
275
|
+
[Symbol.iterator](): ArrayIterator<import("./type.library.js").EntryOf<{
|
|
276
|
+
[x: string & {}]: string;
|
|
277
|
+
display: string;
|
|
278
|
+
weekDate: string;
|
|
279
|
+
weekTime: string;
|
|
280
|
+
weekStamp: string;
|
|
281
|
+
dayMonth: string;
|
|
282
|
+
dayDate: string;
|
|
283
|
+
dayTime: string;
|
|
284
|
+
logStamp: string;
|
|
285
|
+
sortTime: string;
|
|
286
|
+
yearWeek: string;
|
|
287
|
+
yearMonth: string;
|
|
288
|
+
yearMonthDay: string;
|
|
289
|
+
date: string;
|
|
290
|
+
time: string;
|
|
291
|
+
}>>;
|
|
292
|
+
get [Symbol.toStringTag](): string;
|
|
293
|
+
/**
|
|
294
|
+
* Instantiates a new `Tempo` object.
|
|
295
|
+
*
|
|
296
|
+
* @param tempo - The date-time value to parse. Can be a string, number, BigInt, Date, or another Tempo/Temporal object.
|
|
297
|
+
* @param options - Configuration options for this specific instance.
|
|
298
|
+
*/
|
|
299
|
+
constructor(options?: Tempo.Options);
|
|
300
|
+
constructor(tempo: Tempo.DateTime, options?: Tempo.Options);
|
|
301
|
+
/** 4-digit year (e.g., 2024) */ get yy(): number;
|
|
302
|
+
/** Month number: Jan=1, Dec=12 */ get mm(): Tempo.mm;
|
|
303
|
+
/** ISO week number of the year */ get ww(): Tempo.ww;
|
|
304
|
+
/** Day of the month (1-31) */ get dd(): number;
|
|
305
|
+
/** Day of the month (alias for `dd`) */ get day(): number;
|
|
306
|
+
/** Hour of the day (0-23) */ get hh(): Tempo.hh;
|
|
307
|
+
/** Minutes of the hour (0-59) */ get mi(): Tempo.mi;
|
|
308
|
+
/** Seconds of the minute (0-59) */ get ss(): Tempo.ss;
|
|
309
|
+
/** Milliseconds of the second (0-999) */ get ms(): Tempo.ms;
|
|
310
|
+
/** Microseconds of the millisecond (0-999) */ get us(): Tempo.us;
|
|
311
|
+
/** Nanoseconds of the microsecond (0-999) */ get ns(): Tempo.ns;
|
|
312
|
+
/** Fractional seconds (e.g., 0.123456789) */ get ff(): number;
|
|
313
|
+
/** IANA Time Zone ID (e.g., 'Australia/Sydney') */ get tz(): string;
|
|
314
|
+
/** Unix timestamp (defaults to milliseconds) */ get ts(): number | bigint;
|
|
315
|
+
/** Short month name (e.g., 'Jan') */ get mmm(): "All" | "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec";
|
|
316
|
+
/** Full month name (e.g., 'January') */ get mon(): "May" | "Every" | "January" | "February" | "March" | "April" | "June" | "July" | "August" | "September" | "October" | "November" | "December";
|
|
317
|
+
/** Short weekday name (e.g., 'Mon') */ get www(): "All" | "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun";
|
|
318
|
+
/** Full weekday name (e.g., 'Monday') */ get wkd(): "Everyday" | "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday";
|
|
319
|
+
/** ISO weekday number: Mon=1, Sun=7 */ get dow(): Tempo.Weekday;
|
|
320
|
+
/** Nanoseconds since Unix epoch (BigInt) */ get nano(): bigint;
|
|
321
|
+
/** Instance-specific configuration settings */ get config(): Tempo.Config;
|
|
322
|
+
/** Instance-specific parse rules (merged with global) */ get parse(): Internal.Parse;
|
|
323
|
+
/** Object containing results from all term plugins */ get term(): Property<any>;
|
|
324
|
+
/** Formatted results for all pre-defined format codes */ get fmt(): {
|
|
325
|
+
[x: string & {}]: string;
|
|
326
|
+
display: string;
|
|
327
|
+
weekDate: string;
|
|
328
|
+
weekTime: string;
|
|
329
|
+
weekStamp: string;
|
|
330
|
+
dayMonth: string;
|
|
331
|
+
dayDate: string;
|
|
332
|
+
dayTime: string;
|
|
333
|
+
logStamp: string;
|
|
334
|
+
sortTime: string;
|
|
335
|
+
yearWeek: string;
|
|
336
|
+
yearMonth: string;
|
|
337
|
+
yearMonthDay: string;
|
|
338
|
+
date: string;
|
|
339
|
+
time: string;
|
|
340
|
+
};
|
|
341
|
+
/** units since epoch */ get epoch(): import("./type.library.js").SecureObject<{
|
|
342
|
+
/** seconds since epoch */ readonly ss: number;
|
|
343
|
+
/** milliseconds since epoch */ readonly ms: number;
|
|
344
|
+
/** microseconds since epoch */ readonly us: number;
|
|
345
|
+
/** nanoseconds since epoch */ readonly ns: bigint;
|
|
346
|
+
}>;
|
|
347
|
+
/** time duration until (with unit, returns number) */ until(until: Tempo.Until, opts?: Tempo.Options): number;
|
|
348
|
+
/** time duration until another date-time (with unit) */ until(dateTimeOrOpts: Tempo.DateTime | Tempo.Options, until: Tempo.Until): number;
|
|
349
|
+
/** time duration until (returns Duration) */ until(dateTimeOrOpts?: Tempo.DateTime | Tempo.Options, opts?: Tempo.Options): Tempo.Duration;
|
|
350
|
+
/** time elapsed since (with unit) */ since(until: Tempo.Until, opts?: Tempo.Options): string;
|
|
351
|
+
/** time elapsed since another date-time (with unit) */ since(dateTimeOrOpts: Tempo.DateTime | Tempo.Options, until: Tempo.Until): string;
|
|
352
|
+
/** time elapsed since (without unit) */ since(dateTimeOrOpts?: Tempo.DateTime | Tempo.Options, opts?: Tempo.Options): string;
|
|
353
|
+
/** applies a format to the current `Tempo` instance. */ format<K extends enums.Format>(fmt: K): Tempo.FormatType<K>;
|
|
354
|
+
/** returns a new `Tempo` with specific duration added. */ add(mutate: Tempo.Add): Tempo;
|
|
355
|
+
/** returns a new `Tempo` with specific offsets. */ set(offset: Tempo.Set | Tempo.Add): Tempo;
|
|
356
|
+
/** `true` if the underlying date-time is valid. */ isValid(): boolean;
|
|
357
|
+
/** the underlying `Temporal.ZonedDateTime` object. */ toDateTime(): Temporal.ZonedDateTime;
|
|
358
|
+
/** the date-time as a `Temporal.Instant`. */ toInstant(): Temporal.Instant;
|
|
359
|
+
/** the date-time as a standard `Date` object. */ toDate(): Date;
|
|
360
|
+
/** the ISO8601 string representation of the date-time. */ toString(): string;
|
|
361
|
+
/** Custom JSON serialization for `JSON.stringify`. */ toJSON(): {
|
|
362
|
+
value: string;
|
|
363
|
+
/** configuration (global | local) */ scope: "global" | "local";
|
|
364
|
+
debug: boolean | undefined;
|
|
365
|
+
timeStamp: Tempo.TimeStamp;
|
|
366
|
+
store: string;
|
|
367
|
+
catch: boolean | undefined;
|
|
368
|
+
timeZone: string;
|
|
369
|
+
calendar: string;
|
|
370
|
+
locale: string;
|
|
371
|
+
pivot: number;
|
|
372
|
+
sphere: Tempo.COMPASS | undefined;
|
|
373
|
+
snippet: Snippet | Internal.PatternOption<string | RegExp>;
|
|
374
|
+
layout: Layout | Internal.PatternOption<string | RegExp>;
|
|
375
|
+
event: Event | Internal.PatternOption<string | Function>;
|
|
376
|
+
period: Period | Internal.PatternOption<string | Function>;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
export declare namespace Tempo {
|
|
380
|
+
/** the value that Tempo will attempt to interpret as a valid ISO date / time */
|
|
381
|
+
export type DateTime = string | number | bigint | Date | Tempo | typeof Temporal | Temporal.ZonedDateTimeLike | undefined | null;
|
|
382
|
+
/** the Options object found in a json-file, or passed to a call to Tempo.Init({}) or 'new Tempo({}) */
|
|
383
|
+
export type Options = Partial<{
|
|
384
|
+
/** localStorage key */ store: string;
|
|
385
|
+
/** additional console.log for tracking */ debug: boolean | undefined;
|
|
386
|
+
/** catch or throw Errors */ catch: boolean | undefined;
|
|
387
|
+
/** Temporal timeZone */ timeZone: string;
|
|
388
|
+
/** Temporal calendar */ calendar: string;
|
|
389
|
+
/** locale (e.g. en-AU) */ locale: string;
|
|
390
|
+
/** pivot year for two-digit years */ pivot: number;
|
|
391
|
+
/** hemisphere for term.qtr or term.szn */ sphere: Tempo.COMPASS | undefined;
|
|
392
|
+
/** granularity of timestamps (ms | ns) */ timeStamp: Tempo.TimeStamp;
|
|
393
|
+
/** locale-names that prefer 'mm-dd-yy' date order */ mdyLocales: string | string[];
|
|
394
|
+
/** swap parse-order of layouts */ mdyLayouts: Internal.StringTuple[];
|
|
395
|
+
/** date-time snippets to help compose a Layout */ snippet: Snippet | Internal.PatternOption<string | RegExp>;
|
|
396
|
+
/** patterns to help parse value */ layout: Layout | Internal.PatternOption<string | RegExp>;
|
|
397
|
+
/** custom date aliases (events). */ event: Event | Internal.PatternOption<string | Function>;
|
|
398
|
+
/** custom time aliases (periods). */ period: Period | Internal.PatternOption<string | Function>;
|
|
399
|
+
/** supplied value to parse */ value: Tempo.DateTime;
|
|
400
|
+
}>;
|
|
401
|
+
/** drop the setup-only Options */
|
|
402
|
+
type OptionsKeep = Omit<Options, "value" | "mdyLocales" | "mdyLayouts">;
|
|
403
|
+
/**
|
|
404
|
+
* the Config that Tempo will use to interpret a Tempo.DateTime
|
|
405
|
+
* derived from user-supplied options, else json-stored options, else reasonable-default options
|
|
406
|
+
*/
|
|
407
|
+
export interface Config extends Required<OptionsKeep> {
|
|
408
|
+
/** configuration (global | local) */ scope: 'global' | 'local';
|
|
409
|
+
}
|
|
410
|
+
/** Timestamp precision */
|
|
411
|
+
export type TimeStamp = 'ss' | 'ms' | 'us' | 'ns';
|
|
412
|
+
/** Configuration to use for #until() and #since() argument */
|
|
413
|
+
export type Unit = Temporal.DateUnit | Temporal.TimeUnit;
|
|
414
|
+
export type Until = (Tempo.Options & {
|
|
415
|
+
unit?: Tempo.Unit;
|
|
416
|
+
}) | Tempo.Unit;
|
|
417
|
+
export type Mutate = 'start' | 'mid' | 'end';
|
|
418
|
+
export type Set = Partial<Record<Tempo.Mutate, Tempo.Unit> & Record<'date' | 'time' | 'event' | 'period', string>>;
|
|
419
|
+
export type Add = Partial<Record<Tempo.Unit, number>>;
|
|
420
|
+
/** pre-configured format strings */
|
|
421
|
+
export interface Format {
|
|
422
|
+
/** www, dd mmm yyyy */ [Tempo.FORMAT.display]: string;
|
|
423
|
+
/** www, dd mmm yyyy */ display: string;
|
|
424
|
+
/** www, yyyy-mmm-dd */ [Tempo.FORMAT.weekDate]: string;
|
|
425
|
+
/** www, yyyy-mmm-dd */ weekDate: string;
|
|
426
|
+
/** www, yyyy-mmm-dd hh:mi.ss */ [Tempo.FORMAT.weekTime]: string;
|
|
427
|
+
/** www, yyyy-mmm-dd hh:mi.ss */ weekTime: string;
|
|
428
|
+
/** www, yyyy-mmm-dd hh:mi:ss.ff */ [Tempo.FORMAT.weekStamp]: string;
|
|
429
|
+
/** www, yyyy-mmm-dd hh:mi:ss.ff */ weekStamp: string;
|
|
430
|
+
/** dd-mmm */ [Tempo.FORMAT.dayMonth]: string;
|
|
431
|
+
/** dd-mmm */ dayMonth: string;
|
|
432
|
+
/** dd-mmm-yyyy */ [Tempo.FORMAT.dayDate]: string;
|
|
433
|
+
/** dd-mmm-yyyy */ dayDate: string;
|
|
434
|
+
/** dd-mmm-yyyy hh:mi:ss */ [Tempo.FORMAT.dayTime]: string;
|
|
435
|
+
/** dd-mmm-yyyy hh:mi:ss */ dayTime: string;
|
|
436
|
+
/** yyyymmdd.hhmiss.ff */ [Tempo.FORMAT.logStamp]: string;
|
|
437
|
+
/** yyyymmdd.hhmiss.ff */ logStamp: string;
|
|
438
|
+
/** yyyy-mm-dd hh:mi:ss */ [Tempo.FORMAT.sortTime]: string;
|
|
439
|
+
/** yyyy-mm-dd hh:mi:ss */ sortTime: string;
|
|
440
|
+
/** yyyyww */ [Tempo.FORMAT.yearWeek]: number;
|
|
441
|
+
/** yyyyww */ yearWeek: number;
|
|
442
|
+
/** yyyymm */ [Tempo.FORMAT.yearMonth]: number;
|
|
443
|
+
/** yyyymm */ yearMonth: number;
|
|
444
|
+
/** yyyymmdd */ [Tempo.FORMAT.yearMonthDay]: number;
|
|
445
|
+
/** yyyymmdd */ yearMonthDay: number;
|
|
446
|
+
/** ww */ [Tempo.ELEMENT.ww]: Tempo.WEEKDAY;
|
|
447
|
+
/** www */ weekDay: Tempo.WEEKDAY;
|
|
448
|
+
/** yyyy-mm-dd */ [Tempo.FORMAT.date]: string;
|
|
449
|
+
/** yyyy-mm-dd */ date: string;
|
|
450
|
+
/** hh:mi:ss */ [Tempo.FORMAT.time]: string;
|
|
451
|
+
/** hh:mi:ss */ time: string;
|
|
452
|
+
/** generic format */ [key: string]: string | number;
|
|
453
|
+
}
|
|
454
|
+
export type FormatType<K extends string> = K extends LiteralKey<Format> ? Format[K] : string;
|
|
455
|
+
export type Modifier = '=' | '-' | '+' | '<' | '<=' | '-=' | '>' | '>=' | '+=' | 'this' | 'next' | 'prev' | 'last' | 'first' | undefined;
|
|
456
|
+
export type Relative = 'ago' | 'hence' | 'prior';
|
|
457
|
+
export type mm = IntRange<0, 12>;
|
|
458
|
+
export type hh = IntRange<0, 24>;
|
|
459
|
+
export type mi = IntRange<0, 60>;
|
|
460
|
+
export type ss = IntRange<0, 60>;
|
|
461
|
+
export type ms = IntRange<0, 999>;
|
|
462
|
+
export type us = IntRange<0, 999>;
|
|
463
|
+
export type ns = IntRange<0, 999>;
|
|
464
|
+
export type ww = IntRange<1, 52>;
|
|
465
|
+
export type Duration = NonOptional<Temporal.DurationLikeObject> & Record<"iso", string> & Record<"sign", Temporal.Duration["sign"]> & Record<"blank", Temporal.Duration["blank"]> & Record<"unit", string | undefined>;
|
|
466
|
+
export type WEEKDAY = enums.WEEKDAY;
|
|
467
|
+
export type WEEKDAYS = enums.WEEKDAYS;
|
|
468
|
+
export type MONTH = enums.MONTH;
|
|
469
|
+
export type MONTHS = enums.MONTHS;
|
|
470
|
+
export type COMPASS = enums.COMPASS;
|
|
471
|
+
export type ELEMENT = enums.ELEMENT;
|
|
472
|
+
export type Weekday = enums.Weekday;
|
|
473
|
+
export type Month = enums.Month;
|
|
474
|
+
export type Element = enums.Element;
|
|
475
|
+
export {};
|
|
476
|
+
}
|
|
477
|
+
declare namespace Internal {
|
|
478
|
+
type StringPattern = string | RegExp;
|
|
479
|
+
type StringFunction = string | number | Function;
|
|
480
|
+
type StringTuple = [string, string];
|
|
481
|
+
type GroupWkd = {
|
|
482
|
+
wkd?: Tempo.WEEKDAY;
|
|
483
|
+
mod?: Tempo.Modifier;
|
|
484
|
+
nbr?: string;
|
|
485
|
+
sfx?: Tempo.Relative;
|
|
486
|
+
hh?: string;
|
|
487
|
+
mi?: string;
|
|
488
|
+
ss?: string;
|
|
489
|
+
ms?: string;
|
|
490
|
+
us?: string;
|
|
491
|
+
ns?: string;
|
|
492
|
+
ff?: string;
|
|
493
|
+
mer?: string;
|
|
494
|
+
};
|
|
495
|
+
type GroupDate = {
|
|
496
|
+
mod?: Tempo.Modifier;
|
|
497
|
+
nbr?: string;
|
|
498
|
+
afx?: Tempo.Relative;
|
|
499
|
+
unt?: string;
|
|
500
|
+
yy?: string;
|
|
501
|
+
mm?: string;
|
|
502
|
+
dd?: string;
|
|
503
|
+
};
|
|
504
|
+
type GroupModifier = {
|
|
505
|
+
mod?: Tempo.Modifier | Tempo.Relative;
|
|
506
|
+
adjust: number;
|
|
507
|
+
offset: number;
|
|
508
|
+
period: number;
|
|
509
|
+
};
|
|
510
|
+
type PatternOption<T> = T | Record<string | symbol, T> | PatternOption<T>[];
|
|
511
|
+
interface Shape {
|
|
512
|
+
/** current defaults for all Tempo instances */ config: Tempo.Config;
|
|
513
|
+
/** parsing rules */ parse: Internal.Parse;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Parsing rules
|
|
517
|
+
* Once a Tempo is instantiated, these values are for debug purposes only
|
|
518
|
+
*/
|
|
519
|
+
interface Parse {
|
|
520
|
+
/** Locales which prefer 'mm-dd-yyyy' date-order */ mdyLocales: {
|
|
521
|
+
locale: string;
|
|
522
|
+
timeZones: string[];
|
|
523
|
+
}[];
|
|
524
|
+
/** Layout names that are switched to mdy */ mdyLayouts: Internal.StringTuple[];
|
|
525
|
+
/** is a timeZone that prefers 'mmddyyyy' date order */ isMonthDay?: boolean;
|
|
526
|
+
/** Symbol registry */ token: Token;
|
|
527
|
+
/** Tempo snippets to aid in parsing */ snippet: Snippet;
|
|
528
|
+
/** Tempo layout strings */ layout: Layout;
|
|
529
|
+
/** Map of regex-patterns to match input-string */ pattern: Internal.RegexpMap;
|
|
530
|
+
/** configured Events */ event: Event;
|
|
531
|
+
/** configured Periods */ period: Period;
|
|
532
|
+
/** parsing match result */ result: Internal.Match[];
|
|
533
|
+
}
|
|
534
|
+
/** debug a Tempo instantiation */
|
|
535
|
+
interface Match {
|
|
536
|
+
/** pattern which matched the input */ match?: string | undefined;
|
|
537
|
+
/** groups from the pattern match */ groups?: Internal.StringRecord;
|
|
538
|
+
/** the type of the original input */ type: LooseUnion<Type>;
|
|
539
|
+
/** the value of the original input */ value: any;
|
|
540
|
+
}
|
|
541
|
+
type StringRecord = Record<string, string>;
|
|
542
|
+
type RegexpMap = Map<symbol, RegExp>;
|
|
543
|
+
}
|
|
544
|
+
export type Params<T> = {
|
|
545
|
+
(tempo?: Tempo.DateTime, options?: Tempo.Options): T;
|
|
546
|
+
(options: Tempo.Options): T;
|
|
547
|
+
};
|
|
548
|
+
type Fmt = {
|
|
549
|
+
<F extends enums.Format>(fmt: F, tempo?: Tempo.DateTime, options?: Tempo.Options): Tempo.FormatType<F>;
|
|
550
|
+
<F extends enums.Format>(fmt: F, options: Tempo.Options): Tempo.FormatType<F>;
|
|
551
|
+
};
|
|
552
|
+
/** check valid Tempo */ export declare const isTempo: (tempo?: unknown) => tempo is Tempo;
|
|
553
|
+
/** current timestamp (ts) */ export declare const getStamp: Params<number | bigint>;
|
|
554
|
+
/** create new Tempo */ export declare const getTempo: Params<Tempo>;
|
|
555
|
+
/** format a Tempo */ export declare const fmtTempo: Fmt;
|
|
556
|
+
export {};
|