temporal-fmt 0.9.31 β 0.9.32
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/README.md +34 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# temporal-fmt π₯Άπ₯
|
|
2
2
|
|
|
3
3
|
-brightgreen?style=flat-square)
|
|
4
|
+
[](https://bundlephobia.com/package/temporal-fmt)
|
|
5
|
+
[](https://bundlephobia.com/package/temporal-fmt)
|
|
4
6
|
|
|
5
|
-
Format `Temporal
|
|
6
|
-
using date-fns-style
|
|
7
|
+
Format and parse `Temporal` values (`PlainDate`, `PlainTime`, `PlainDateTime`,
|
|
8
|
+
`ZonedDateTime`) using date-fns-style tokens, with real validation β bad input
|
|
9
|
+
throws instead of silently returning garbage. Locale-aware, no deps.
|
|
7
10
|
|
|
8
11
|
Node 26 shipped native `Temporal` and then pointedly left out a custom-string
|
|
9
12
|
formatter. TC39's take: use `Intl.DateTimeFormat` and leave string-token syntax
|
|
@@ -12,7 +15,8 @@ muscle memory from date-fns, moment, or dayjs, that's a rough adjustment. This
|
|
|
12
15
|
library exists so you don't have to make it.
|
|
13
16
|
|
|
14
17
|
Zero dependencies. Native on Node 26+, or bring your own via a polyfill or
|
|
15
|
-
`setTemporal()`.
|
|
18
|
+
`setTemporal()`. Import from a subpath (`temporal-fmt/format`, `temporal-fmt/parse`,
|
|
19
|
+
etc.) to pull in only what you use β see [Subpath imports](#subpath-imports).
|
|
16
20
|
|
|
17
21
|
Locale-aware tokens need Node 20+ regardless of which path you use β native
|
|
18
22
|
on 26+, or falling back to the Temporal implementation's own
|
|
@@ -26,10 +30,27 @@ npm install temporal-fmt
|
|
|
26
30
|
|
|
27
31
|
[View on npm](https://www.npmjs.com/package/temporal-fmt)
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
## Get started
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { format } from 'temporal-fmt/format';
|
|
37
|
+
import { parse } from 'temporal-fmt/parse';
|
|
38
|
+
|
|
39
|
+
const date = Temporal.PlainDate.from('2026-08-04');
|
|
40
|
+
format(date, 'yyyy-MM-dd'); // "2026-08-04"
|
|
41
|
+
|
|
42
|
+
parse('yyyy-MM-dd HH:mm', '2026-08-04 15:45'); // Temporal.PlainDateTime
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
That's the whole library for most use cases β `format(temporal, formatStr)` in, `parse(formatStr, input)` out, same shape as date-fns or Day.js. Import from the subpaths (`temporal-fmt/format`, `temporal-fmt/parse`) shown above, not the bare `temporal-fmt` package β a bundler only ships what you actually call that way. Measured with esbuild: ~27KB for `format` alone via the subpath, versus ~68KB for the same function pulled from the bare import.
|
|
46
|
+
|
|
47
|
+
Below Node 26, `Temporal` isn't global yet, so you'll need a polyfill first β see [Providing `Temporal`](#providing-temporal). On Node 26+ the snippet above just works.
|
|
48
|
+
|
|
49
|
+
The package looks large on npm β locales, recurrence, business calendars, timezone disambiguation, an analyzer, config layers, a CLI β but none of that is required reading or required bundle weight. It's there behind its own subpaths for when you need it; see [Subpath imports](#subpath-imports) for the full list and [Formatting](#formatting)/[Parsing](#parsing) for the details on the two functions above.
|
|
30
50
|
|
|
31
51
|
## Contents
|
|
32
52
|
|
|
53
|
+
- [Get started](#get-started)
|
|
33
54
|
- [Providing `Temporal`](#providing-temporal)
|
|
34
55
|
- [Formatting](#formatting)
|
|
35
56
|
- [Parsing](#parsing)
|
|
@@ -71,7 +92,8 @@ Use a polyfill like [`temporal-polyfill`](https://github.com/fullcalendar/tempor
|
|
|
71
92
|
|
|
72
93
|
```js
|
|
73
94
|
import 'temporal-polyfill/global'
|
|
74
|
-
import { format
|
|
95
|
+
import { format } from 'temporal-fmt/format';
|
|
96
|
+
import { parse } from 'temporal-fmt/parse';
|
|
75
97
|
|
|
76
98
|
parse(...);
|
|
77
99
|
```
|
|
@@ -82,7 +104,9 @@ Set a Temporal implementation explicitly, once, before your app's first `format(
|
|
|
82
104
|
|
|
83
105
|
```js
|
|
84
106
|
import { Temporal } from 'temporal-polyfill/full';
|
|
85
|
-
import { setTemporal
|
|
107
|
+
import { setTemporal } from 'temporal-fmt';
|
|
108
|
+
import { format } from 'temporal-fmt/format';
|
|
109
|
+
import { parse } from 'temporal-fmt/parse';
|
|
86
110
|
|
|
87
111
|
setTemporal(Temporal); // once, before using format or parse
|
|
88
112
|
```
|
|
@@ -94,7 +118,7 @@ Anything that constructs a `Temporal` value from scratch needs this β `parse()
|
|
|
94
118
|
## Formatting
|
|
95
119
|
|
|
96
120
|
```js
|
|
97
|
-
import { format } from 'temporal-fmt';
|
|
121
|
+
import { format } from 'temporal-fmt/format';
|
|
98
122
|
|
|
99
123
|
const date = Temporal.PlainDate.from('2026-08-04');
|
|
100
124
|
format(date, 'yyyy-MM-dd'); // "2026-08-04"
|
|
@@ -120,7 +144,7 @@ Try a token your input type doesn't support β `HH` on a `PlainDate`, say β a
|
|
|
120
144
|
`parse()` builds a real `Temporal.PlainDate` / `PlainTime` / `PlainDateTime` / `ZonedDateTime` out of a string, picking whichever type fits the tokens present:
|
|
121
145
|
|
|
122
146
|
```js
|
|
123
|
-
import { parse } from 'temporal-fmt';
|
|
147
|
+
import { parse } from 'temporal-fmt/parse';
|
|
124
148
|
|
|
125
149
|
parse('yyyy-MM-dd HH:mm', '2026-08-04 15:45'); // Temporal.PlainDateTime
|
|
126
150
|
parse('yyyy-MM', '2026-08-04T15:45:30'); // throws β shape doesn't match
|
|
@@ -890,6 +914,8 @@ import { registerLocale } from 'temporal-fmt/locale';
|
|
|
890
914
|
|
|
891
915
|
The rest of the API (arithmetic, comparison, rounding, intervals-adjacent helpers not listed above, business calendars, holidays, serialization, config, type guards, typed errors, the analyzer, and IDE tooling data) is only available from the main `temporal-fmt` entry point β there's no dedicated subpath for those yet.
|
|
892
916
|
|
|
917
|
+
`sideEffects: false` is set in `package.json`, so a bundler with tree-shaking enabled genuinely drops what you don't import. Measured with esbuild: `import { format } from 'temporal-fmt/format'` bundles to ~27KB, versus ~68KB for the same single function pulled from the bare `temporal-fmt` entry β the main entry point re-exports everything, so anything imported from it drags the whole graph along regardless of what you actually call. If bundle size matters for your use case, import from the subpath, not the package root.
|
|
918
|
+
|
|
893
919
|
## Migrating from Day.js or date-fns
|
|
894
920
|
|
|
895
921
|
### Token mapping
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "temporal-fmt",
|
|
3
|
-
"version": "0.9.
|
|
4
|
-
"description": "Format Temporal
|
|
3
|
+
"version": "0.9.32",
|
|
4
|
+
"description": "Format and parse Temporal (PlainDate, PlainTime, PlainDateTime, ZonedDateTime) using date-fns-style tokens. Validates strictly β bad input throws, not garbage. Locale-aware, no deps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|