|
1 | 1 | # Tree-shakeable API |
2 | 2 |
|
3 | | -The tree-shakeable function-based API docs are organized by Temporal type or |
4 | | -support object. Each page catalogs the public functions exported for that area |
5 | | -and shows the codemod-shaped rewrite to the real Temporal API. |
| 3 | +Instead of large `Temporal.*` classes, the tree-shakeable API exposes every |
| 4 | +operation as a standalone function that acts on a plain record, so a bundler |
| 5 | +keeps only the functions you actually import: |
6 | 6 |
|
7 | | -Unlike the class-based entry points, the tree-shakeable API always uses the |
8 | | -runtime's native `Temporal` when one is available, with no option to force the |
9 | | -bundled JavaScript implementation. |
| 7 | +```js |
| 8 | +import * as PlainDateFns from 'temporal-polyfill/fns/PlainDate' |
10 | 9 |
|
11 | | -Abbreviations used by the type pages: |
| 10 | +const date = PlainDateFns.create(2024, 1, 1) |
| 11 | +const later = PlainDateFns.addMonths(date, 2) |
12 | 12 |
|
13 | | -- `Record` is the record type exported by the file being cataloged. |
14 | | -- `CalendarFns.Record` is the opaque calendar handle used by tree-shakeable API |
15 | | - functions that accept calendar behavior. |
16 | | -- `OverflowOptions` is the calendar-field overflow options bag. |
17 | | -- `RoundingMathOptions` contains rounding increment and rounding mode options. |
18 | | - The unit is implied by the `roundTo*` function name. Round helpers also |
19 | | - accept a `RoundingMode` string as shorthand for `options.roundingMode`. |
| 13 | +PlainDateFns.toString(later) // '2024-03-01' |
| 14 | +``` |
| 15 | + |
| 16 | +Each Temporal type has its own entrypoint under `temporal-polyfill/fns/*` — for |
| 17 | +example `temporal-polyfill/fns/PlainDate` or `temporal-polyfill/fns/ZonedDateTime`. |
| 18 | +These docs are organized by Temporal type or support object: each page catalogs |
| 19 | +the public functions exported for that area and shows the codemod-shaped rewrite |
| 20 | +to the real Temporal API. |
| 21 | + |
| 22 | +The tree-shakeable API always uses the runtime's native `Temporal` when one is |
| 23 | +available. Unlike the class-based entry points — which offer |
| 24 | +`/implementation` variants for forcing the bundled JavaScript implementation — |
| 25 | +the tree-shakeable API has no such option. |
20 | 26 |
|
21 | 27 | ## Catalog |
22 | 28 |
|
@@ -47,3 +53,15 @@ before calling `toTemporal`; we recommend this package's own |
47 | 53 | `temporal-polyfill/global` entrypoint for optimal code sharing. |
48 | 54 |
|
49 | 55 | `toTemporal` throws when no global `Temporal` is present. |
| 56 | + |
| 57 | +## Abbreviations |
| 58 | + |
| 59 | +Abbreviations used by the type pages: |
| 60 | + |
| 61 | +- `Record` is the record type exported by the file being cataloged. |
| 62 | +- `CalendarFns.Record` is the opaque calendar handle used by tree-shakeable API |
| 63 | + functions that accept calendar behavior. |
| 64 | +- `OverflowOptions` is the calendar-field overflow options bag. |
| 65 | +- `RoundingMathOptions` contains rounding increment and rounding mode options. |
| 66 | + The unit is implied by the `roundTo*` function name. Round helpers also |
| 67 | + accept a `RoundingMode` string as shorthand for `options.roundingMode`. |
0 commit comments