daymath 0.2.2 → 0.2.3
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 +23 -3
- package/index.js +2 -0
- package/package.json +12 -6
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# daymath
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/daymath)
|
|
4
|
+
[](https://github.com/leemr/daymath/actions/workflows/ci.yml)
|
|
5
|
+
[](https://codecov.io/gh/leemr/daymath)
|
|
4
6
|
[](./LICENSE)
|
|
5
7
|
[](https://www.npmjs.com/package/daymath)
|
|
6
8
|
|
|
@@ -8,12 +10,22 @@
|
|
|
8
10
|
|
|
9
11
|
No `Date`. No time zones. No silent “local now.”
|
|
10
12
|
|
|
11
|
-
[**Play
|
|
13
|
+
[**Play →**](https://leemr.github.io/daymath/) · [npm](https://www.npmjs.com/package/daymath) · [Changelog](./CHANGELOG.md) · [Contributing](./CONTRIBUTING.md) · [FUTURE](./FUTURE.md)
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
16
|
npm install daymath
|
|
15
17
|
```
|
|
16
18
|
|
|
19
|
+
Same code also publishes to **GitHub Packages** as `@leemr/daymath` (scoped; see [GitHub npm registry docs](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry)):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# one-time: map the scope (auth with a PAT that has read:packages, or GITHUB_TOKEN in Actions)
|
|
23
|
+
echo '@leemr:registry=https://npm.pkg.github.com' >> .npmrc
|
|
24
|
+
npm install @leemr/daymath
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Most people should keep using **`daymath` on npmjs**.
|
|
28
|
+
|
|
17
29
|
```js
|
|
18
30
|
import { addDays, addMonths, differenceInDays, isSameDay } from 'daymath'
|
|
19
31
|
|
|
@@ -23,6 +35,10 @@ differenceInDays('2026-08-06', '2026-08-01') // 5
|
|
|
23
35
|
isSameDay('2026-08-06', '2026-08-06') // true
|
|
24
36
|
```
|
|
25
37
|
|
|
38
|
+
```bash
|
|
39
|
+
node examples/basic.mjs # from a clone
|
|
40
|
+
```
|
|
41
|
+
|
|
26
42
|
## Why
|
|
27
43
|
|
|
28
44
|
`Date` is a timestamp. Hire dates, passport expiry, trip days are **calendar** values. daymath only does plain days as ISO strings.
|
|
@@ -72,13 +88,17 @@ Uses global `Temporal` when present; otherwise [`temporal-polyfill`](https://www
|
|
|
72
88
|
|
|
73
89
|
## Types & tests
|
|
74
90
|
|
|
75
|
-
Plain JS + `index.d.ts` (no compile step).
|
|
91
|
+
Plain JS + `index.d.ts` (no compile step). CI runs on Node 18, 20, and 22.
|
|
76
92
|
|
|
77
93
|
```bash
|
|
78
94
|
npm test
|
|
79
|
-
npm run test:coverage # 100% lines on index.js
|
|
95
|
+
npm run test:coverage # c8: 100% lines/funcs/branches on index.js + lcov
|
|
80
96
|
```
|
|
81
97
|
|
|
98
|
+
CI uploads coverage to [Codecov](https://codecov.io/gh/leemr/daymath) (see [CONTRIBUTING.md](./CONTRIBUTING.md) for one-time app/token setup).
|
|
99
|
+
|
|
100
|
+
PRs welcome via fork — see [CONTRIBUTING.md](./CONTRIBUTING.md). Security reports: [SECURITY.md](./SECURITY.md).
|
|
101
|
+
|
|
82
102
|
## License
|
|
83
103
|
|
|
84
104
|
MIT
|
package/index.js
CHANGED
|
@@ -116,6 +116,8 @@ function toInterval(interval) {
|
|
|
116
116
|
* True if value is a valid daymath day (ISO day string or PlainDate).
|
|
117
117
|
* Invalid strings → false. `Date` → throws (not a quiet false — swap trap).
|
|
118
118
|
* @param {unknown} value
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
* @throws {TypeError} If `value` is a `Date`
|
|
119
121
|
*/
|
|
120
122
|
export function isValid(value) {
|
|
121
123
|
if (value instanceof Date) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daymath",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Calendar date math (ISO 8601 day / PlainDate). date-fns-shaped. No time zones.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -18,17 +18,19 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "node --test test.js",
|
|
21
|
-
"test:coverage": "
|
|
22
|
-
"prepublishOnly": "npm run test:coverage"
|
|
21
|
+
"test:coverage": "c8 --include=index.js --check-coverage --lines 100 --functions 100 --branches 100 --reporter=text --reporter=lcov node --test test.js",
|
|
22
|
+
"prepublishOnly": "npm run test:coverage",
|
|
23
|
+
"publish:github": "node scripts/publish-github-packages.mjs"
|
|
23
24
|
},
|
|
24
|
-
|
|
25
25
|
"keywords": [
|
|
26
26
|
"date",
|
|
27
27
|
"calendar",
|
|
28
28
|
"plain-date",
|
|
29
29
|
"temporal",
|
|
30
30
|
"date-fns",
|
|
31
|
-
"YYYY-MM-DD"
|
|
31
|
+
"YYYY-MM-DD",
|
|
32
|
+
"ISO-8601",
|
|
33
|
+
"PlainDate"
|
|
32
34
|
],
|
|
33
35
|
"author": "leemr",
|
|
34
36
|
"license": "MIT",
|
|
@@ -39,11 +41,15 @@
|
|
|
39
41
|
"bugs": {
|
|
40
42
|
"url": "https://github.com/leemr/daymath/issues"
|
|
41
43
|
},
|
|
42
|
-
"homepage": "https://github.
|
|
44
|
+
"homepage": "https://leemr.github.io/daymath/",
|
|
45
|
+
"sideEffects": false,
|
|
43
46
|
"dependencies": {
|
|
44
47
|
"temporal-polyfill": "^1.0.3"
|
|
45
48
|
},
|
|
46
49
|
"engines": {
|
|
47
50
|
"node": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"c8": "^12.0.0"
|
|
48
54
|
}
|
|
49
55
|
}
|