@rikdotcodes/temporal-polyfill 0.3.1
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 +214 -0
- package/chunks/classApi.cjs +587 -0
- package/chunks/classApi.js +582 -0
- package/chunks/internal.cjs +3076 -0
- package/chunks/internal.js +3280 -0
- package/global.cjs +11 -0
- package/global.d.cts +1 -0
- package/global.d.ts +1 -0
- package/global.esm.js +11 -0
- package/global.js +3422 -0
- package/global.min.js +1 -0
- package/impl.cjs +5 -0
- package/impl.d.cts +1 -0
- package/impl.d.ts +1 -0
- package/impl.js +1 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Adam Shaw
|
|
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,214 @@
|
|
|
1
|
+
|
|
2
|
+
# temporal-polyfill
|
|
3
|
+
|
|
4
|
+
A lightweight polyfill for [Temporal](https://tc39.es/proposal-temporal/docs/), successor to the JavaScript `Date` object
|
|
5
|
+
|
|
6
|
+
Only 20 kB, [spec compliant](#spec-compliance)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Comparison with `@js-temporal/polyfill`](#comparison-with-js-temporalpolyfill)
|
|
13
|
+
- [Spec Compliance](#spec-compliance)
|
|
14
|
+
- [Browser Support](#browser-support)
|
|
15
|
+
- [BigInt Considerations](#bigint-considerations)
|
|
16
|
+
- [Tree-shakable API](#tree-shakable-api) (coming soon)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install temporal-polyfill
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import as an ES module without side effects:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { Temporal } from 'temporal-polyfill'
|
|
29
|
+
|
|
30
|
+
console.log(Temporal.Now.zonedDateTimeISO().toString())
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or, import globally:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import 'temporal-polyfill/global'
|
|
37
|
+
|
|
38
|
+
console.log(Temporal.Now.zonedDateTimeISO().toString())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use a `<script>` tags with a CDN link:
|
|
42
|
+
|
|
43
|
+
```html
|
|
44
|
+
<script src='https://cdn.jsdelivr.net/npm/temporal-polyfill@0.3.0/global.min.js'></script>
|
|
45
|
+
<script>
|
|
46
|
+
console.log(Temporal.Now.zonedDateTimeISO().toString())
|
|
47
|
+
</script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Comparison with `@js-temporal/polyfill`
|
|
52
|
+
|
|
53
|
+
<table>
|
|
54
|
+
<tr>
|
|
55
|
+
<td>Package</td>
|
|
56
|
+
<td>
|
|
57
|
+
<code>temporal-polyfill</code>
|
|
58
|
+
</td>
|
|
59
|
+
<td>
|
|
60
|
+
<code>@js-temporal/polyfill</code>
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td>Repo</td>
|
|
65
|
+
<td>
|
|
66
|
+
<a href='https://github.com/fullcalendar/temporal-polyfill'>
|
|
67
|
+
fullcalendar/temporal-polyfill
|
|
68
|
+
</a>
|
|
69
|
+
</td>
|
|
70
|
+
<td>
|
|
71
|
+
<a href='https://github.com/js-temporal/temporal-polyfill'>
|
|
72
|
+
js-temporal/temporal-polyfill
|
|
73
|
+
</a>
|
|
74
|
+
</td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr>
|
|
77
|
+
<td>Creators</td>
|
|
78
|
+
<td><a href='https://fullcalendar.io/'>FullCalendar</a> lead dev <a href='https://github.com/arshaw'>arshaw</a></td>
|
|
79
|
+
<td>Champions of the <a href='https://github.com/tc39/proposal-temporal'>Temporal proposal</a></td>
|
|
80
|
+
</tr>
|
|
81
|
+
<tr>
|
|
82
|
+
<td>Minified+gzip size</td>
|
|
83
|
+
<td><a href='https://bundlephobia.com/package/temporal-polyfill'>19.8 KB<a></td>
|
|
84
|
+
<td><a href='https://bundlephobia.com/package/@js-temporal/polyfill'>51.9 KB</a> (+162%)</td>
|
|
85
|
+
</tr>
|
|
86
|
+
<tr>
|
|
87
|
+
<td>Spec date</td>
|
|
88
|
+
<td>
|
|
89
|
+
Mar 2025
|
|
90
|
+
</td>
|
|
91
|
+
<td>
|
|
92
|
+
Mar 2025
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
<tr>
|
|
96
|
+
<td>BigInt approach</td>
|
|
97
|
+
<td>Internally avoids BigInt operations altogether</td>
|
|
98
|
+
<td>Internally relies on <a href='https://github.com/GoogleChromeLabs/jsbi'>JSBI</a></td>
|
|
99
|
+
</tr>
|
|
100
|
+
<tr>
|
|
101
|
+
<td>Global usage in ESM</td>
|
|
102
|
+
<td>
|
|
103
|
+
<code>import 'temporal-polyfill/global'</code>
|
|
104
|
+
</td>
|
|
105
|
+
<td>Not currently possible</td>
|
|
106
|
+
</tr>
|
|
107
|
+
</table>
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
## Spec Compliance
|
|
111
|
+
|
|
112
|
+
All calendar systems (ex: `chinese`, `persian`) and all time zones are supported.
|
|
113
|
+
|
|
114
|
+
Compliance with the latest version of the Temporal spec is near-perfect [with just 4 intentional deviations](https://github.com/fullcalendar/temporal-polyfill/blob/main/packages/temporal-polyfill/scripts/test262-config/expected-failures.txt).
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## Browser Support
|
|
118
|
+
|
|
119
|
+
<table>
|
|
120
|
+
<tr>
|
|
121
|
+
<td colspan='6'>
|
|
122
|
+
<strong>Minimum required browsers for ISO/gregory calendars:</strong>
|
|
123
|
+
</td>
|
|
124
|
+
</tr>
|
|
125
|
+
<tr>
|
|
126
|
+
<!-- Computed from Libraries+Syntax in worksheet below -->
|
|
127
|
+
<td>Chrome 60<br />(Jul 2017)</td>
|
|
128
|
+
<td>Firefox 55<br />(Aug 2017)</td>
|
|
129
|
+
<td>Safari 11.1<br />(Mar 2018)</td>
|
|
130
|
+
<td>Safari iOS 11.3<br />(Mar 2018)</td>
|
|
131
|
+
<td>Edge 79<br />(Jan 2020)</td>
|
|
132
|
+
<td>Node.js 14<br />(Apr 2020)</td>
|
|
133
|
+
</tr>
|
|
134
|
+
<tr>
|
|
135
|
+
<td colspan='6'>
|
|
136
|
+
<br />
|
|
137
|
+
<strong>If you transpile, you can support older browsers down to:</strong>
|
|
138
|
+
</td>
|
|
139
|
+
</tr>
|
|
140
|
+
<tr>
|
|
141
|
+
<!-- Computed from Libraries in worksheet below -->
|
|
142
|
+
<td>Chrome 57<br />(Mar 2017)</td>
|
|
143
|
+
<td>Firefox 52<br />(Mar 2017)</td>
|
|
144
|
+
<td>Safari 10<br />(Sep 2016)</td>
|
|
145
|
+
<td>Safari iOS 10<br />(Sep 2016)</td>
|
|
146
|
+
<td>Edge 15<br />(Apr 2017)</td>
|
|
147
|
+
<td>Node.js 14<br />(Apr 2020)</td>
|
|
148
|
+
</tr>
|
|
149
|
+
<tr>
|
|
150
|
+
<td colspan='6'>
|
|
151
|
+
<br />
|
|
152
|
+
<strong>For non-ISO/gregory calendars, requirements are higher:</strong>
|
|
153
|
+
</td>
|
|
154
|
+
</tr>
|
|
155
|
+
<tr>
|
|
156
|
+
<!-- https://caniuse.com/mdn-javascript_builtins_intl_datetimeformat_datetimeformat_options_parameter_options_calendar_parameter -->
|
|
157
|
+
<td>Chrome 80<br />(Feb 2020)</td>
|
|
158
|
+
<td>Firefox 76<br />(May 2020)</td>
|
|
159
|
+
<td>Safari 14.1<br />(Apr 2021)</td>
|
|
160
|
+
<td>Safari iOS 14.5<br />(Apr 2021)</td>
|
|
161
|
+
<td>Edge 80<br />(Feb 2020)</td>
|
|
162
|
+
<td>Node.js 14<br />(Apr 2020)</td>
|
|
163
|
+
</tr>
|
|
164
|
+
</table>
|
|
165
|
+
|
|
166
|
+
<!--
|
|
167
|
+
## Browser Support Worksheet
|
|
168
|
+
|
|
169
|
+
Use caniuse's star feature to find intersection of features.
|
|
170
|
+
|
|
171
|
+
Libraries:
|
|
172
|
+
- [Intl.DateTimeFormat IANA time zone names](https://caniuse.com/mdn-javascript_builtins_intl_datetimeformat_datetimeformat_options_parameter_options_timezone_parameter_iana_time_zones)
|
|
173
|
+
- [Number.isInteger](https://caniuse.com/mdn-javascript_builtins_number_isinteger)
|
|
174
|
+
- [Number.isSafeInteger] (https://caniuse.com/mdn-javascript_builtins_number_issafeinteger)
|
|
175
|
+
- [String::padStart](https://caniuse.com/mdn-javascript_builtins_string_padstart)
|
|
176
|
+
- [WeakMap](https://caniuse.com/mdn-javascript_builtins_weakmap)
|
|
177
|
+
|
|
178
|
+
Syntax:
|
|
179
|
+
- [Classes](https://caniuse.com/es6-class)
|
|
180
|
+
- [Exponentiation](https://caniuse.com/mdn-javascript_operators_exponentiation)
|
|
181
|
+
- [Spread in array literals](https://caniuse.com/mdn-javascript_operators_spread_spread_in_arrays)
|
|
182
|
+
- [Spread in function calls](https://caniuse.com/mdn-javascript_operators_spread_spread_in_function_calls)
|
|
183
|
+
- [Spread in object literals](https://caniuse.com/mdn-javascript_operators_spread_spread_in_object_literals)
|
|
184
|
+
|
|
185
|
+
BigInt (https://caniuse.com/bigint):
|
|
186
|
+
- Chrome 67 (May 2018)
|
|
187
|
+
- Firefox 68 (Jul 2019)
|
|
188
|
+
- Safari 14 (Sep 2020)
|
|
189
|
+
- Safari iOS 14 (Sep 2020)
|
|
190
|
+
- Edge 79 (Jan 2020)
|
|
191
|
+
|
|
192
|
+
Node.js is always 14 because the test-runner doesn't work with lower
|
|
193
|
+
-->
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## BigInt Considerations
|
|
197
|
+
|
|
198
|
+
This polyfill does NOT depend on [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) support. Internally, no operations leverage BigInt arithmetics. :thumbsup:
|
|
199
|
+
|
|
200
|
+
However, if you plan to use methods that accept/emit BigInts, your environment must support it. Alternatively, you can avoid using these methods altogether. [There's a cheatsheet](https://gist.github.com/arshaw/1ef4bf945d68654b86cef2dd8471c48f) to help you.
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## Tree-shakable API
|
|
204
|
+
|
|
205
|
+
🚧 Coming Soon
|
|
206
|
+
|
|
207
|
+
For library authors and other devs who are hyper-concerned about bundle size, `temporal-polyfill` will be providing an alternate API designed for tree-shaking.
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
import * as ZonedDateTime from 'temporal-polyfill/fns/zoneddatetime'
|
|
211
|
+
|
|
212
|
+
const zdt = ZonedDateTime.from({ year: 2024, month: 1, day: 1 })
|
|
213
|
+
const s = ZonedDateTime.toString(zdt) // not how you normally call a method!
|
|
214
|
+
```
|