daymath 0.7.1 → 0.7.2
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 +46 -0
- package/index.js +7 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -360,6 +360,52 @@ would not escape this. Bundlers and browsers are unaffected. A Jest consumer nee
|
|
|
360
360
|
|
|
361
361
|
Node 18 was supported through 0.3.0 and is dropped here. It went end-of-life in April 2025.
|
|
362
362
|
|
|
363
|
+
### In a browser, from a CDN
|
|
364
|
+
|
|
365
|
+
The `?bundle` is not optional.
|
|
366
|
+
|
|
367
|
+
```html
|
|
368
|
+
<script type="module">
|
|
369
|
+
import * as daymath from 'https://esm.sh/daymath?bundle'
|
|
370
|
+
console.log(daymath.addDays('2026-08-06', 7))
|
|
371
|
+
</script>
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The answer that snippet logs, asserted by `npm run test:examples`, because a claim inside an html
|
|
375
|
+
fence is not:
|
|
376
|
+
|
|
377
|
+
```js
|
|
378
|
+
addDays('2026-08-06', 7) // '2026-08-13'
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Most CDNs serve a daymath that throws on every date, and the message it throws is not helpful.
|
|
382
|
+
daymath imports two subpaths of `temporal-polyfill`, `fns/PlainDate` and `fns/Calendar`. A CDN that
|
|
383
|
+
rebuilds each subpath into its own bundle gives each one a private copy of the polyfill's internals,
|
|
384
|
+
so the calendar built by one copy is unrecognisable to the other and `fromString` throws
|
|
385
|
+
`TypeError: Invalid calling context`. No import spelling avoids it: `temporal-polyfill/fns` is in
|
|
386
|
+
the export map but its file is empty, so the separate subpaths are the whole `fns` API.
|
|
387
|
+
|
|
388
|
+
Measured 2026-09-05. `npm run test:demo` re-checks the first row on a schedule; the other four rows
|
|
389
|
+
carry no gate, so re-measure them rather than trusting the table:
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
for u in "https://esm.sh/daymath?bundle" "https://unpkg.com/daymath?module" "https://esm.sh/daymath" "https://esm.run/daymath" "https://cdn.jsdelivr.net/npm/daymath/+esm"; do
|
|
393
|
+
node scripts/demo-page.mjs --url "$u" >/dev/null 2>&1 && echo "yes $u" || echo "no $u"
|
|
394
|
+
done
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
| URL | Works |
|
|
399
|
+
| --- | --- |
|
|
400
|
+
| `https://esm.sh/daymath?bundle` | yes |
|
|
401
|
+
| `https://unpkg.com/daymath?module` | yes |
|
|
402
|
+
| `https://esm.sh/daymath` | no |
|
|
403
|
+
| `https://esm.run/daymath` | no |
|
|
404
|
+
| `https://cdn.jsdelivr.net/npm/daymath/+esm` | no |
|
|
405
|
+
|
|
406
|
+
A bundler is unaffected. It resolves both subpaths through one copy in `node_modules`, which is why
|
|
407
|
+
every gate in this repo stayed green while the demo page was dead.
|
|
408
|
+
|
|
363
409
|
## Types & tests
|
|
364
410
|
|
|
365
411
|
Plain JS + `index.d.ts` (no compile step). CI runs on Node 20, 22, 24, and 26; the
|
package/index.js
CHANGED
|
@@ -401,6 +401,13 @@ function toPlainDate(value, label = 'date') {
|
|
|
401
401
|
? plain
|
|
402
402
|
: PlainDateFns.withCalendar(plain, getAny(calendar))
|
|
403
403
|
} catch (err) {
|
|
404
|
+
// Temporal reports every input fault here as a RangeError, so anything else is the
|
|
405
|
+
// implementation breaking and must surface unchanged. A CDN serving two copies of
|
|
406
|
+
// `temporal-polyfill/fns` throws `TypeError: Invalid calling context`; the old catch-all
|
|
407
|
+
// relabelled that as `invalid date` and sent the reader after their own input instead.
|
|
408
|
+
// Ignored for coverage because a healthy Temporal cannot reach it.
|
|
409
|
+
/* c8 ignore next */
|
|
410
|
+
if (!(err instanceof RangeError)) throw err
|
|
404
411
|
throw new RangeError(`daymath: invalid ${label} ${JSON.stringify(text)}`, {
|
|
405
412
|
cause: err,
|
|
406
413
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daymath",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Calendar date math (ISO 8601 day / PlainDate). date-fns-shaped. No Date. No time zones.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"test:runtimes:write": "node scripts/cross-runtime.mjs --write",
|
|
31
31
|
"test:intl-day": "node scripts/intl-day.mjs",
|
|
32
32
|
"test:examples": "node scripts/examples.mjs",
|
|
33
|
+
"test:demo": "node scripts/demo-page.mjs",
|
|
33
34
|
"test:examples:write": "node scripts/examples.mjs --write",
|
|
34
35
|
"test:intl-day:sweep": "node scripts/intl-day.mjs --sweep",
|
|
35
36
|
"size": "node scripts/bundle-size.mjs --run",
|
|
@@ -70,8 +71,8 @@
|
|
|
70
71
|
"c8": "^12.0.0",
|
|
71
72
|
"date-fns": "4.4.0",
|
|
72
73
|
"esbuild": "0.28.2",
|
|
73
|
-
"oxfmt": "0.
|
|
74
|
-
"oxlint": "1.
|
|
74
|
+
"oxfmt": "0.65.0",
|
|
75
|
+
"oxlint": "1.81.0",
|
|
75
76
|
"typescript": "7.0.2"
|
|
76
77
|
}
|
|
77
78
|
}
|