temporal-fmt 0.1.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 +75 -0
- package/dist/index.cjs +148 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NovaByte Official
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# temporal-fmt
|
|
2
|
+
|
|
3
|
+
Format `Temporal.PlainDate` / `PlainTime` / `PlainDateTime` / `ZonedDateTime` objects
|
|
4
|
+
using date-fns-style token strings.
|
|
5
|
+
|
|
6
|
+
Native `Temporal` shipped in Node 26 and modern browsers, but it deliberately has
|
|
7
|
+
no custom-string formatter — the TC39 authors punted that to userland in favor of
|
|
8
|
+
`Intl.DateTimeFormat`. This fills that specific gap for people who want the
|
|
9
|
+
`'yyyy-MM-dd'`-style syntax they already know from date-fns / moment / dayjs.
|
|
10
|
+
|
|
11
|
+
Zero dependencies. Requires a global `Temporal` (native in Node 26+, or bring your
|
|
12
|
+
own polyfill like `temporal-polyfill`).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install temporal-fmt
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { format } from 'temporal-fmt';
|
|
24
|
+
|
|
25
|
+
const date = Temporal.PlainDate.from('2026-08-04');
|
|
26
|
+
format(date, 'yyyy-MM-dd'); // "2026-08-04"
|
|
27
|
+
format(date, 'MMMM d, yyyy'); // "August 4, 2026"
|
|
28
|
+
|
|
29
|
+
const dt = Temporal.PlainDateTime.from('2026-08-04T15:45:30');
|
|
30
|
+
format(dt, "MMM d, yyyy 'at' h:mm a"); // "Aug 4, 2026 at 3:45 PM"
|
|
31
|
+
|
|
32
|
+
const zdt = Temporal.ZonedDateTime.from('2026-08-04T15:45:30-04:00[America/New_York]');
|
|
33
|
+
format(zdt, 'yyyy-MM-dd HH:mm zzz'); // "2026-08-04 15:45 America/New_York"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Quote literal text with single quotes: `'at'`. Use `''` for a literal single quote.
|
|
37
|
+
|
|
38
|
+
## Tokens
|
|
39
|
+
|
|
40
|
+
| Token | Meaning | Example |
|
|
41
|
+
|-------|------------------|---------|
|
|
42
|
+
| yyyy | 4-digit year | 2026 |
|
|
43
|
+
| yy | 2-digit year | 26 |
|
|
44
|
+
| MMMM | full month name | August |
|
|
45
|
+
| MMM | short month name | Aug |
|
|
46
|
+
| MM | 2-digit month | 08 |
|
|
47
|
+
| M | month | 8 |
|
|
48
|
+
| dd | 2-digit day | 04 |
|
|
49
|
+
| d | day | 4 |
|
|
50
|
+
| EEEE | full weekday | Tuesday |
|
|
51
|
+
| EEE | short weekday | Tue |
|
|
52
|
+
| HH | 2-digit hour (24h) | 15 |
|
|
53
|
+
| H | hour (24h) | 15 |
|
|
54
|
+
| hh | 2-digit hour (12h) | 03 |
|
|
55
|
+
| h | hour (12h) | 3 |
|
|
56
|
+
| mm | 2-digit minute | 45 |
|
|
57
|
+
| m | minute | 45 |
|
|
58
|
+
| ss | 2-digit second | 30 |
|
|
59
|
+
| s | second | 30 |
|
|
60
|
+
| SSS | milliseconds | 000 |
|
|
61
|
+
| a | AM/PM | PM |
|
|
62
|
+
| zzz | IANA time zone id | America/New_York |
|
|
63
|
+
|
|
64
|
+
Passing a token the input type doesn't support (e.g. `HH` on a `PlainDate`) throws
|
|
65
|
+
a clear error instead of silently printing `undefined`.
|
|
66
|
+
|
|
67
|
+
## Dev notes
|
|
68
|
+
|
|
69
|
+
`tsconfig.json` sets `ignoreDeprecations: "6.0"` as a workaround for a tsup bug
|
|
70
|
+
(tsup#1388/#1389) — tsup's dts build step injects a deprecated `baseUrl` internally,
|
|
71
|
+
which TypeScript 6+ hard-errors on. Remove this once tsup ships a fix upstream.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
format: () => format
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/tokens.ts
|
|
28
|
+
function pad(n, len) {
|
|
29
|
+
return String(n).padStart(len, "0");
|
|
30
|
+
}
|
|
31
|
+
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
32
|
+
var MONTHS_LONG = [
|
|
33
|
+
"January",
|
|
34
|
+
"February",
|
|
35
|
+
"March",
|
|
36
|
+
"April",
|
|
37
|
+
"May",
|
|
38
|
+
"June",
|
|
39
|
+
"July",
|
|
40
|
+
"August",
|
|
41
|
+
"September",
|
|
42
|
+
"October",
|
|
43
|
+
"November",
|
|
44
|
+
"December"
|
|
45
|
+
];
|
|
46
|
+
var DAYS_SHORT = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
47
|
+
var DAYS_LONG = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
48
|
+
var TOKENS = [
|
|
49
|
+
["yyyy", (t) => pad(t.year, 4), "year"],
|
|
50
|
+
["yy", (t) => pad(t.year % 100, 2), "year"],
|
|
51
|
+
["MMMM", (t) => MONTHS_LONG[t.month - 1], "month"],
|
|
52
|
+
["MMM", (t) => MONTHS_SHORT[t.month - 1], "month"],
|
|
53
|
+
["MM", (t) => pad(t.month, 2), "month"],
|
|
54
|
+
["M", (t) => String(t.month), "month"],
|
|
55
|
+
["dd", (t) => pad(t.day, 2), "day"],
|
|
56
|
+
["d", (t) => String(t.day), "day"],
|
|
57
|
+
["EEEE", (t) => DAYS_LONG[t.dayOfWeek - 1], "dayOfWeek"],
|
|
58
|
+
["EEE", (t) => DAYS_SHORT[t.dayOfWeek - 1], "dayOfWeek"],
|
|
59
|
+
["HH", (t) => pad(t.hour, 2), "hour"],
|
|
60
|
+
["H", (t) => String(t.hour), "hour"],
|
|
61
|
+
["hh", (t) => pad(t.hour % 12 || 12, 2), "hour"],
|
|
62
|
+
["h", (t) => String(t.hour % 12 || 12), "hour"],
|
|
63
|
+
["mm", (t) => pad(t.minute, 2), "minute"],
|
|
64
|
+
["m", (t) => String(t.minute), "minute"],
|
|
65
|
+
["ss", (t) => pad(t.second, 2), "second"],
|
|
66
|
+
["s", (t) => String(t.second), "second"],
|
|
67
|
+
["SSS", (t) => pad(t.millisecond, 3), "millisecond"],
|
|
68
|
+
["a", (t) => t.hour < 12 ? "AM" : "PM", "hour"],
|
|
69
|
+
["zzz", (t) => t.timeZoneId, "timeZoneId"]
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
// src/tokenize.ts
|
|
73
|
+
var SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);
|
|
74
|
+
function tokenize(format2) {
|
|
75
|
+
const pieces = [];
|
|
76
|
+
let i = 0;
|
|
77
|
+
while (i < format2.length) {
|
|
78
|
+
const ch = format2[i];
|
|
79
|
+
if (ch === "'") {
|
|
80
|
+
if (format2[i + 1] === "'") {
|
|
81
|
+
pieces.push({ kind: "literal", value: "'" });
|
|
82
|
+
i += 2;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
let j = i + 1;
|
|
86
|
+
let literal = "";
|
|
87
|
+
let closed = false;
|
|
88
|
+
while (j < format2.length) {
|
|
89
|
+
if (format2[j] === "'") {
|
|
90
|
+
if (format2[j + 1] === "'") {
|
|
91
|
+
literal += "'";
|
|
92
|
+
j += 2;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
closed = true;
|
|
96
|
+
j += 1;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
literal += format2[j];
|
|
100
|
+
j += 1;
|
|
101
|
+
}
|
|
102
|
+
if (!closed) {
|
|
103
|
+
throw new Error(`temporal-fmt: unterminated quote in format string "${format2}"`);
|
|
104
|
+
}
|
|
105
|
+
pieces.push({ kind: "literal", value: literal });
|
|
106
|
+
i = j;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const match = SORTED_TOKEN_STRINGS.find((tok) => format2.startsWith(tok, i));
|
|
110
|
+
if (match) {
|
|
111
|
+
pieces.push({ kind: "token", value: match });
|
|
112
|
+
i += match.length;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
pieces.push({ kind: "literal", value: ch });
|
|
116
|
+
i += 1;
|
|
117
|
+
}
|
|
118
|
+
return pieces;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/format.ts
|
|
122
|
+
var HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));
|
|
123
|
+
function format(temporal, formatStr) {
|
|
124
|
+
const pieces = tokenize(formatStr);
|
|
125
|
+
let result = "";
|
|
126
|
+
for (const piece of pieces) {
|
|
127
|
+
if (piece.kind === "literal") {
|
|
128
|
+
result += piece.value;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
132
|
+
if (!handler) {
|
|
133
|
+
throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
134
|
+
}
|
|
135
|
+
if (temporal[handler.field] === void 0) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
result += handler.fn(temporal);
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
format
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/tokens.ts","../src/tokenize.ts","../src/format.ts"],"sourcesContent":["export { format } from './format.js';\nexport type { TemporalLike } from './tokens.js';\n","// Pad a number with leading zeros to `len` digits.\nexport function pad(n: number, len: number): string {\n return String(n).padStart(len, '0');\n}\n\n// Minimal duck-typed shape covering every field we might read off a Temporal\n// object. Not every field exists on every type (PlainDate has no .hour, for\n// example) — callers check for undefined before formatting a token.\nexport interface TemporalLike {\n year?: number;\n month?: number;\n day?: number;\n hour?: number;\n minute?: number;\n second?: number;\n millisecond?: number;\n timeZoneId?: string;\n dayOfWeek?: number; // 1 (Mon) - 7 (Sun), per Temporal spec\n}\n\nconst MONTHS_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\nconst MONTHS_LONG = [\n 'January', 'February', 'March', 'April', 'May', 'June',\n 'July', 'August', 'September', 'October', 'November', 'December',\n];\nconst DAYS_SHORT = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];\nconst DAYS_LONG = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];\n\n// Each token renders itself from a TemporalLike. The third tuple element\n// below names the field it depends on, so format.ts can check for undefined\n// before calling the handler (e.g. `HH` needs `.hour`, which PlainDate lacks).\ntype TokenHandler = (t: TemporalLike) => string;\n\n// Longest tokens first — the tokenizer is greedy, so \"yyyy\" must be tried\n// before \"yy\" or it'll never match.\nexport const TOKENS: Array<[string, TokenHandler, keyof TemporalLike]> = [\n ['yyyy', (t) => pad(t.year!, 4), 'year'],\n ['yy', (t) => pad(t.year! % 100, 2), 'year'],\n ['MMMM', (t) => MONTHS_LONG[t.month! - 1], 'month'],\n ['MMM', (t) => MONTHS_SHORT[t.month! - 1], 'month'],\n ['MM', (t) => pad(t.month!, 2), 'month'],\n ['M', (t) => String(t.month!), 'month'],\n ['dd', (t) => pad(t.day!, 2), 'day'],\n ['d', (t) => String(t.day!), 'day'],\n ['EEEE', (t) => DAYS_LONG[t.dayOfWeek! - 1], 'dayOfWeek'],\n ['EEE', (t) => DAYS_SHORT[t.dayOfWeek! - 1], 'dayOfWeek'],\n ['HH', (t) => pad(t.hour!, 2), 'hour'],\n ['H', (t) => String(t.hour!), 'hour'],\n ['hh', (t) => pad(t.hour! % 12 || 12, 2), 'hour'],\n ['h', (t) => String(t.hour! % 12 || 12), 'hour'],\n ['mm', (t) => pad(t.minute!, 2), 'minute'],\n ['m', (t) => String(t.minute!), 'minute'],\n ['ss', (t) => pad(t.second!, 2), 'second'],\n ['s', (t) => String(t.second!), 'second'],\n ['SSS', (t) => pad(t.millisecond!, 3), 'millisecond'],\n ['a', (t) => (t.hour! < 12 ? 'AM' : 'PM'), 'hour'],\n ['zzz', (t) => t.timeZoneId!, 'timeZoneId'],\n];","import { TOKENS } from './tokens.js';\n\nexport type Piece =\n | { kind: 'token'; value: string }\n | { kind: 'literal'; value: string };\n\n// Sort once, longest-first, so the greedy scanner below never matches \"M\"\n// when \"MMMM\" was actually there.\nconst SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);\n\n/**\n * Splits a format string like `\"yyyy-MM-dd 'at' HH:mm\"` into a sequence of\n * token and literal pieces. Text inside single quotes is always literal —\n * that's how you escape a token that would otherwise be parsed (e.g. a\n * literal \"d\" in \"3rd\" — write 'rd' in quotes so it isn't read as the day token).\n * A doubled quote ('') anywhere means a literal single quote character —\n * this works both inside an open quoted span (e.g. 'it''s' -> it's) and\n * as a standalone escape outside one (e.g. yyyy'' -> \"2026'\").\n */\nexport function tokenize(format: string): Piece[] {\n const pieces: Piece[] = [];\n let i = 0;\n\n while (i < format.length) {\n const ch = format[i];\n\n if (ch === \"'\") {\n // Doubled quote is always a literal ' — check this before treating\n // the quote as an open-delimiter, or \"''best''\" gets misread as\n // \"open quote, then bare text, then open quote\" instead of two\n // separate escaped-apostrophe literals around plain text.\n if (format[i + 1] === \"'\") {\n pieces.push({ kind: 'literal', value: \"'\" });\n i += 2;\n continue;\n }\n\n // Otherwise this opens a quoted literal span. Scan forward, treating\n // any '' we find *inside* the span as an escaped literal quote rather\n // than the closing delimiter.\n let j = i + 1;\n let literal = '';\n let closed = false;\n while (j < format.length) {\n if (format[j] === \"'\") {\n if (format[j + 1] === \"'\") {\n literal += \"'\";\n j += 2;\n continue;\n }\n closed = true;\n j += 1;\n break;\n }\n literal += format[j];\n j += 1;\n }\n\n if (!closed) {\n throw new Error(`temporal-fmt: unterminated quote in format string \"${format}\"`);\n }\n\n pieces.push({ kind: 'literal', value: literal });\n i = j;\n continue;\n }\n\n const match = SORTED_TOKEN_STRINGS.find((tok) => format.startsWith(tok, i));\n if (match) {\n pieces.push({ kind: 'token', value: match });\n i += match.length;\n continue;\n }\n\n // Not a token, not a quote — pass the character through as-is. This is\n // what lets you write \"yyyy-MM-dd\" with bare hyphens instead of quoting them.\n pieces.push({ kind: 'literal', value: ch });\n i += 1;\n }\n\n return pieces;\n}","import { TOKENS, type TemporalLike } from './tokens.js';\nimport { tokenize } from './tokenize.js';\n\nconst HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));\n\n/**\n * Format a Temporal.PlainDate, PlainTime, PlainDateTime, or ZonedDateTime\n * using a date-fns-style token string.\n *\n * @example\n * format(Temporal.Now.plainDateISO(), 'yyyy-MM-dd') // \"2026-08-04\"\n * format(zdt, \"MMM d, yyyy 'at' h:mm a\") // \"Aug 4, 2026 at 3:45 PM\"\n *\n * Throws if the format string uses a token the input type doesn't support\n * (e.g. 'HH' on a PlainDate, which has no time component) — this is\n * deliberate: silently printing \"undefined\" would be worse than failing loudly.\n */\nexport function format(temporal: TemporalLike, formatStr: string): string {\n const pieces = tokenize(formatStr);\n let result = '';\n\n for (const piece of pieces) {\n if (piece.kind === 'literal') {\n result += piece.value;\n continue;\n }\n\n const handler = HANDLER_BY_TOKEN.get(piece.value);\n // Shouldn't happen — tokenize() only emits tokens from TOKENS — but keep\n // TypeScript honest and fail loudly instead of silently.\n if (!handler) {\n throw new Error(`temporal-fmt: unknown token \"${piece.value}\"`);\n }\n\n if (temporal[handler.field] === undefined) {\n throw new Error(\n `temporal-fmt: token \"${piece.value}\" requires \"${handler.field}\", ` +\n `which this Temporal object doesn't have. ` +\n `(e.g. PlainDate has no time fields, PlainTime has no date fields)`\n );\n }\n\n result += handler.fn(temporal);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,SAAS,IAAI,GAAW,KAAqB;AAClD,SAAO,OAAO,CAAC,EAAE,SAAS,KAAK,GAAG;AACpC;AAiBA,IAAM,eAAe,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AACxG,IAAM,cAAc;AAAA,EAClB;AAAA,EAAW;AAAA,EAAY;AAAA,EAAS;AAAA,EAAS;AAAA,EAAO;AAAA,EAChD;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAa;AAAA,EAAW;AAAA,EAAY;AACxD;AACA,IAAM,aAAa,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK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AAA,IACF;AAEA,UAAM,QAAQ,qBAAqB,KAAK,CAAC,QAAQA,QAAO,WAAW,KAAK,CAAC,CAAC;AAC1E,QAAI,OAAO;AACT,aAAO,KAAK,EAAE,MAAM,SAAS,OAAO,MAAM,CAAC;AAC3C,WAAK,MAAM;AACX;AAAA,IACF;AAIA,WAAO,KAAK,EAAE,MAAM,WAAW,OAAO,GAAG,CAAC;AAC1C,SAAK;AAAA,EACP;AAEA,SAAO;AACT;;;AC9EA,IAAM,mBAAmB,IAAI,IAAI,OAAO,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC;AAchF,SAAS,OAAO,UAAwB,WAA2B;AACxE,QAAM,SAAS,SAAS,SAAS;AACjC,MAAI,SAAS;AAEb,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,SAAS,WAAW;AAC5B,gBAAU,MAAM;AAChB;AAAA,IACF;AAEA,UAAM,UAAU,iBAAiB,IAAI,MAAM,KAAK;AAGhD,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,gCAAgC,MAAM,KAAK,GAAG;AAAA,IAChE;AAEA,QAAI,SAAS,QAAQ,KAAK,MAAM,QAAW;AACzC,YAAM,IAAI;AAAA,QACR,wBAAwB,MAAM,KAAK,eAAe,QAAQ,KAAK;AAAA,MAGjE;AAAA,IACF;AAEA,cAAU,QAAQ,GAAG,QAAQ;AAAA,EAC/B;AAEA,SAAO;AACT;","names":["format"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface TemporalLike {
|
|
2
|
+
year?: number;
|
|
3
|
+
month?: number;
|
|
4
|
+
day?: number;
|
|
5
|
+
hour?: number;
|
|
6
|
+
minute?: number;
|
|
7
|
+
second?: number;
|
|
8
|
+
millisecond?: number;
|
|
9
|
+
timeZoneId?: string;
|
|
10
|
+
dayOfWeek?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format a Temporal.PlainDate, PlainTime, PlainDateTime, or ZonedDateTime
|
|
15
|
+
* using a date-fns-style token string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* format(Temporal.Now.plainDateISO(), 'yyyy-MM-dd') // "2026-08-04"
|
|
19
|
+
* format(zdt, "MMM d, yyyy 'at' h:mm a") // "Aug 4, 2026 at 3:45 PM"
|
|
20
|
+
*
|
|
21
|
+
* Throws if the format string uses a token the input type doesn't support
|
|
22
|
+
* (e.g. 'HH' on a PlainDate, which has no time component) — this is
|
|
23
|
+
* deliberate: silently printing "undefined" would be worse than failing loudly.
|
|
24
|
+
*/
|
|
25
|
+
declare function format(temporal: TemporalLike, formatStr: string): string;
|
|
26
|
+
|
|
27
|
+
export { type TemporalLike, format };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface TemporalLike {
|
|
2
|
+
year?: number;
|
|
3
|
+
month?: number;
|
|
4
|
+
day?: number;
|
|
5
|
+
hour?: number;
|
|
6
|
+
minute?: number;
|
|
7
|
+
second?: number;
|
|
8
|
+
millisecond?: number;
|
|
9
|
+
timeZoneId?: string;
|
|
10
|
+
dayOfWeek?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format a Temporal.PlainDate, PlainTime, PlainDateTime, or ZonedDateTime
|
|
15
|
+
* using a date-fns-style token string.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* format(Temporal.Now.plainDateISO(), 'yyyy-MM-dd') // "2026-08-04"
|
|
19
|
+
* format(zdt, "MMM d, yyyy 'at' h:mm a") // "Aug 4, 2026 at 3:45 PM"
|
|
20
|
+
*
|
|
21
|
+
* Throws if the format string uses a token the input type doesn't support
|
|
22
|
+
* (e.g. 'HH' on a PlainDate, which has no time component) — this is
|
|
23
|
+
* deliberate: silently printing "undefined" would be worse than failing loudly.
|
|
24
|
+
*/
|
|
25
|
+
declare function format(temporal: TemporalLike, formatStr: string): string;
|
|
26
|
+
|
|
27
|
+
export { type TemporalLike, format };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// src/tokens.ts
|
|
2
|
+
function pad(n, len) {
|
|
3
|
+
return String(n).padStart(len, "0");
|
|
4
|
+
}
|
|
5
|
+
var MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
6
|
+
var MONTHS_LONG = [
|
|
7
|
+
"January",
|
|
8
|
+
"February",
|
|
9
|
+
"March",
|
|
10
|
+
"April",
|
|
11
|
+
"May",
|
|
12
|
+
"June",
|
|
13
|
+
"July",
|
|
14
|
+
"August",
|
|
15
|
+
"September",
|
|
16
|
+
"October",
|
|
17
|
+
"November",
|
|
18
|
+
"December"
|
|
19
|
+
];
|
|
20
|
+
var DAYS_SHORT = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
21
|
+
var DAYS_LONG = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
22
|
+
var TOKENS = [
|
|
23
|
+
["yyyy", (t) => pad(t.year, 4), "year"],
|
|
24
|
+
["yy", (t) => pad(t.year % 100, 2), "year"],
|
|
25
|
+
["MMMM", (t) => MONTHS_LONG[t.month - 1], "month"],
|
|
26
|
+
["MMM", (t) => MONTHS_SHORT[t.month - 1], "month"],
|
|
27
|
+
["MM", (t) => pad(t.month, 2), "month"],
|
|
28
|
+
["M", (t) => String(t.month), "month"],
|
|
29
|
+
["dd", (t) => pad(t.day, 2), "day"],
|
|
30
|
+
["d", (t) => String(t.day), "day"],
|
|
31
|
+
["EEEE", (t) => DAYS_LONG[t.dayOfWeek - 1], "dayOfWeek"],
|
|
32
|
+
["EEE", (t) => DAYS_SHORT[t.dayOfWeek - 1], "dayOfWeek"],
|
|
33
|
+
["HH", (t) => pad(t.hour, 2), "hour"],
|
|
34
|
+
["H", (t) => String(t.hour), "hour"],
|
|
35
|
+
["hh", (t) => pad(t.hour % 12 || 12, 2), "hour"],
|
|
36
|
+
["h", (t) => String(t.hour % 12 || 12), "hour"],
|
|
37
|
+
["mm", (t) => pad(t.minute, 2), "minute"],
|
|
38
|
+
["m", (t) => String(t.minute), "minute"],
|
|
39
|
+
["ss", (t) => pad(t.second, 2), "second"],
|
|
40
|
+
["s", (t) => String(t.second), "second"],
|
|
41
|
+
["SSS", (t) => pad(t.millisecond, 3), "millisecond"],
|
|
42
|
+
["a", (t) => t.hour < 12 ? "AM" : "PM", "hour"],
|
|
43
|
+
["zzz", (t) => t.timeZoneId, "timeZoneId"]
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// src/tokenize.ts
|
|
47
|
+
var SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);
|
|
48
|
+
function tokenize(format2) {
|
|
49
|
+
const pieces = [];
|
|
50
|
+
let i = 0;
|
|
51
|
+
while (i < format2.length) {
|
|
52
|
+
const ch = format2[i];
|
|
53
|
+
if (ch === "'") {
|
|
54
|
+
if (format2[i + 1] === "'") {
|
|
55
|
+
pieces.push({ kind: "literal", value: "'" });
|
|
56
|
+
i += 2;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
let j = i + 1;
|
|
60
|
+
let literal = "";
|
|
61
|
+
let closed = false;
|
|
62
|
+
while (j < format2.length) {
|
|
63
|
+
if (format2[j] === "'") {
|
|
64
|
+
if (format2[j + 1] === "'") {
|
|
65
|
+
literal += "'";
|
|
66
|
+
j += 2;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
closed = true;
|
|
70
|
+
j += 1;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
literal += format2[j];
|
|
74
|
+
j += 1;
|
|
75
|
+
}
|
|
76
|
+
if (!closed) {
|
|
77
|
+
throw new Error(`temporal-fmt: unterminated quote in format string "${format2}"`);
|
|
78
|
+
}
|
|
79
|
+
pieces.push({ kind: "literal", value: literal });
|
|
80
|
+
i = j;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const match = SORTED_TOKEN_STRINGS.find((tok) => format2.startsWith(tok, i));
|
|
84
|
+
if (match) {
|
|
85
|
+
pieces.push({ kind: "token", value: match });
|
|
86
|
+
i += match.length;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
pieces.push({ kind: "literal", value: ch });
|
|
90
|
+
i += 1;
|
|
91
|
+
}
|
|
92
|
+
return pieces;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/format.ts
|
|
96
|
+
var HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));
|
|
97
|
+
function format(temporal, formatStr) {
|
|
98
|
+
const pieces = tokenize(formatStr);
|
|
99
|
+
let result = "";
|
|
100
|
+
for (const piece of pieces) {
|
|
101
|
+
if (piece.kind === "literal") {
|
|
102
|
+
result += piece.value;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
106
|
+
if (!handler) {
|
|
107
|
+
throw new Error(`temporal-fmt: unknown token "${piece.value}"`);
|
|
108
|
+
}
|
|
109
|
+
if (temporal[handler.field] === void 0) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
result += handler.fn(temporal);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
format
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tokens.ts","../src/tokenize.ts","../src/format.ts"],"sourcesContent":["// Pad a number with leading zeros to `len` digits.\nexport function pad(n: number, len: number): string {\n return String(n).padStart(len, '0');\n}\n\n// Minimal duck-typed shape covering every field we might read off a Temporal\n// object. Not every field exists on every type (PlainDate has no .hour, for\n// example) — callers check for undefined before formatting a token.\nexport interface TemporalLike {\n year?: number;\n month?: number;\n day?: number;\n hour?: number;\n minute?: number;\n second?: number;\n millisecond?: number;\n timeZoneId?: string;\n dayOfWeek?: number; // 1 (Mon) - 7 (Sun), per Temporal spec\n}\n\nconst MONTHS_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\nconst MONTHS_LONG = [\n 'January', 'February', 'March', 'April', 'May', 'June',\n 'July', 'August', 'September', 'October', 'November', 'December',\n];\nconst DAYS_SHORT = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];\nconst DAYS_LONG = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];\n\n// Each token renders itself from a TemporalLike. The third tuple element\n// below names the field it depends on, so format.ts can check for undefined\n// before calling the handler (e.g. `HH` needs `.hour`, which PlainDate lacks).\ntype TokenHandler = (t: TemporalLike) => string;\n\n// Longest tokens first — the tokenizer is greedy, so \"yyyy\" must be tried\n// before \"yy\" or it'll never match.\nexport const TOKENS: Array<[string, TokenHandler, keyof TemporalLike]> = [\n ['yyyy', (t) => pad(t.year!, 4), 'year'],\n ['yy', (t) => pad(t.year! % 100, 2), 'year'],\n ['MMMM', (t) => MONTHS_LONG[t.month! - 1], 'month'],\n ['MMM', (t) => MONTHS_SHORT[t.month! - 1], 'month'],\n ['MM', (t) => pad(t.month!, 2), 'month'],\n ['M', (t) => String(t.month!), 'month'],\n ['dd', (t) => pad(t.day!, 2), 'day'],\n ['d', (t) => String(t.day!), 'day'],\n ['EEEE', (t) => DAYS_LONG[t.dayOfWeek! - 1], 'dayOfWeek'],\n ['EEE', (t) => DAYS_SHORT[t.dayOfWeek! - 1], 'dayOfWeek'],\n ['HH', (t) => pad(t.hour!, 2), 'hour'],\n ['H', (t) => String(t.hour!), 'hour'],\n ['hh', (t) => pad(t.hour! % 12 || 12, 2), 'hour'],\n ['h', (t) => String(t.hour! % 12 || 12), 'hour'],\n ['mm', (t) => pad(t.minute!, 2), 'minute'],\n ['m', (t) => String(t.minute!), 'minute'],\n ['ss', (t) => pad(t.second!, 2), 'second'],\n ['s', (t) => String(t.second!), 'second'],\n ['SSS', (t) => pad(t.millisecond!, 3), 'millisecond'],\n ['a', (t) => (t.hour! < 12 ? 'AM' : 'PM'), 'hour'],\n ['zzz', (t) => t.timeZoneId!, 'timeZoneId'],\n];","import { TOKENS } from './tokens.js';\n\nexport type Piece =\n | { kind: 'token'; value: string }\n | { kind: 'literal'; value: string };\n\n// Sort once, longest-first, so the greedy scanner below never matches \"M\"\n// when \"MMMM\" was actually there.\nconst SORTED_TOKEN_STRINGS = TOKENS.map(([tok]) => tok).sort((a, b) => b.length - a.length);\n\n/**\n * Splits a format string like `\"yyyy-MM-dd 'at' HH:mm\"` into a sequence of\n * token and literal pieces. Text inside single quotes is always literal —\n * that's how you escape a token that would otherwise be parsed (e.g. a\n * literal \"d\" in \"3rd\" — write 'rd' in quotes so it isn't read as the day token).\n * A doubled quote ('') anywhere means a literal single quote character —\n * this works both inside an open quoted span (e.g. 'it''s' -> it's) and\n * as a standalone escape outside one (e.g. yyyy'' -> \"2026'\").\n */\nexport function tokenize(format: string): Piece[] {\n const pieces: Piece[] = [];\n let i = 0;\n\n while (i < format.length) {\n const ch = format[i];\n\n if (ch === \"'\") {\n // Doubled quote is always a literal ' — check this before treating\n // the quote as an open-delimiter, or \"''best''\" gets misread as\n // \"open quote, then bare text, then open quote\" instead of two\n // separate escaped-apostrophe literals around plain text.\n if (format[i + 1] === \"'\") {\n pieces.push({ kind: 'literal', value: \"'\" });\n i += 2;\n continue;\n }\n\n // Otherwise this opens a quoted literal span. Scan forward, treating\n // any '' we find *inside* the span as an escaped literal quote rather\n // than the closing delimiter.\n let j = i + 1;\n let literal = '';\n let closed = false;\n while (j < format.length) {\n if (format[j] === \"'\") {\n if (format[j + 1] === \"'\") {\n literal += \"'\";\n j += 2;\n continue;\n }\n closed = true;\n j += 1;\n break;\n }\n literal += format[j];\n j += 1;\n }\n\n if (!closed) {\n throw new Error(`temporal-fmt: unterminated quote in format string \"${format}\"`);\n }\n\n pieces.push({ kind: 'literal', value: literal });\n i = j;\n continue;\n }\n\n const match = SORTED_TOKEN_STRINGS.find((tok) => format.startsWith(tok, i));\n if (match) {\n pieces.push({ kind: 'token', value: match });\n i += match.length;\n continue;\n }\n\n // Not a token, not a quote — pass the character through as-is. This is\n // what lets you write \"yyyy-MM-dd\" with bare hyphens instead of quoting them.\n pieces.push({ kind: 'literal', value: ch });\n i += 1;\n }\n\n return pieces;\n}","import { TOKENS, type TemporalLike } from './tokens.js';\nimport { tokenize } from './tokenize.js';\n\nconst HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));\n\n/**\n * Format a Temporal.PlainDate, PlainTime, PlainDateTime, or ZonedDateTime\n * using a date-fns-style token string.\n *\n * @example\n * format(Temporal.Now.plainDateISO(), 'yyyy-MM-dd') // \"2026-08-04\"\n * format(zdt, \"MMM d, yyyy 'at' h:mm a\") // \"Aug 4, 2026 at 3:45 PM\"\n *\n * Throws if the format string uses a token the input type doesn't support\n * (e.g. 'HH' on a PlainDate, which has no time component) — this is\n * deliberate: silently printing \"undefined\" would be worse than failing loudly.\n */\nexport function format(temporal: TemporalLike, formatStr: string): string {\n const pieces = tokenize(formatStr);\n let result = '';\n\n for (const piece of pieces) {\n if (piece.kind === 'literal') {\n result += piece.value;\n continue;\n }\n\n const handler = HANDLER_BY_TOKEN.get(piece.value);\n // Shouldn't happen — tokenize() only emits tokens from TOKENS — but keep\n // TypeScript honest and fail loudly instead of silently.\n if (!handler) {\n throw new Error(`temporal-fmt: unknown token \"${piece.value}\"`);\n }\n\n if (temporal[handler.field] === undefined) {\n throw new Error(\n `temporal-fmt: token \"${piece.value}\" requires \"${handler.field}\", ` +\n `which this Temporal object doesn't have. ` +\n `(e.g. PlainDate has no time fields, PlainTime has no date fields)`\n );\n }\n\n result += handler.fn(temporal);\n }\n\n return result;\n}\n"],"mappings":";AACO,SAAS,IAAI,GAAW,KAAqB;AAClD,SAAO,OAAO,CAAC,EAAE,SAAS,KAAK,GAAG;AACpC;AAiBA,IAAM,eAAe,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AACxG,IAAM,cAAc;AAAA,EAClB;AAAA,EAAW;AAAA,EAAY;AAAA,EAAS;AAAA,EAAS;AAAA,EAAO;AAAA,EAChD;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAa;AAAA,EAAW;AAAA,EAAY;AACxD;AACA,IAAM,aAAa,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AACnE,IAAM,YAAY,CAAC,UAAU,WAAW,aAAa,YAAY,UAAU,YAAY,QAAQ;AASxF,IAAM,SAA4D;AAAA,EACvE,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,MAAO,CAAC,GAAG,MAAM;AAAA,EACvC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,OAAQ,KAAK,CAAC,GAAG,MAAM;AAAA,EAC3C,CAAC,QAAQ,CAAC,MAAM,YAAY,EAAE,QAAS,CAAC,GAAG,OAAO;AAAA,EAClD,CAAC,OAAO,CAAC,MAAM,aAAa,EAAE,QAAS,CAAC,GAAG,OAAO;AAAA,EAClD,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,OAAQ,CAAC,GAAG,OAAO;AAAA,EACvC,CAAC,KAAK,CAAC,MAAM,OAAO,EAAE,KAAM,GAAG,OAAO;AAAA,EACtC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,KAAM,CAAC,GAAG,KAAK;AAAA,EACnC,CAAC,KAAK,CAAC,MAAM,OA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K;AAGhD,QAAI,CAAC,SAAS;AACZ,YAAM,IAAI,MAAM,gCAAgC,MAAM,KAAK,GAAG;AAAA,IAChE;AAEA,QAAI,SAAS,QAAQ,KAAK,MAAM,QAAW;AACzC,YAAM,IAAI;AAAA,QACR,wBAAwB,MAAM,KAAK,eAAe,QAAQ,KAAK;AAAA,MAGjE;AAAA,IACF;AAEA,cAAU,QAAQ,GAAG,QAAQ;AAAA,EAC/B;AAEA,SAAO;AACT;","names":["format"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "temporal-fmt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Format Temporal.PlainDate/PlainDateTime/PlainTime/ZonedDateTime objects using date-fns-style token strings.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"dev": "tsup --watch",
|
|
23
|
+
"test": "node --test test/*.test.js",
|
|
24
|
+
"prepublishOnly": "npm run build && npm test"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"temporal",
|
|
28
|
+
"date",
|
|
29
|
+
"time",
|
|
30
|
+
"format",
|
|
31
|
+
"tc39"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/NovaByteOfficial/temporal-fmt.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/NovaByteOfficial/temporal-fmt/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/NovaByteOfficial/temporal-fmt#readme",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"temporal-polyfill": "^1.0.3",
|
|
44
|
+
"tsup": "^8.5.1",
|
|
45
|
+
"typescript": "^6.0.3"
|
|
46
|
+
},
|
|
47
|
+
"overrides": {
|
|
48
|
+
"esbuild": "0.28.1"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=24"
|
|
52
|
+
}
|
|
53
|
+
}
|