@tempots/std 0.19.0 → 0.21.0
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/array.cjs +1 -1
- package/array.d.ts +124 -284
- package/array.js +108 -128
- package/date.cjs +1 -0
- package/date.d.ts +393 -0
- package/date.js +49 -0
- package/function.cjs +1 -1
- package/function.d.ts +145 -0
- package/function.js +35 -5
- package/index.cjs +1 -1
- package/index.d.ts +6 -0
- package/index.js +272 -199
- package/iterator.cjs +1 -0
- package/iterator.d.ts +219 -0
- package/iterator.js +69 -0
- package/json.cjs +1 -1
- package/json.d.ts +40 -2
- package/json.js +7 -6
- package/map.cjs +1 -0
- package/map.d.ts +202 -0
- package/map.js +41 -0
- package/number.cjs +1 -1
- package/number.d.ts +16 -25
- package/number.js +26 -27
- package/object.cjs +1 -1
- package/object.d.ts +146 -8
- package/object.js +42 -15
- package/package.json +43 -1
- package/random.cjs +1 -0
- package/random.d.ts +200 -0
- package/random.js +72 -0
- package/set.cjs +1 -0
- package/set.d.ts +227 -0
- package/set.js +52 -0
- package/string.cjs +4 -4
- package/string.d.ts +2 -60
- package/string.js +122 -129
- package/timer.cjs +1 -1
- package/timer.d.ts +14 -0
- package/timer.js +49 -27
- package/url.cjs +1 -0
- package/url.d.ts +232 -0
- package/url.js +79 -0
package/array.js
CHANGED
|
@@ -1,160 +1,140 @@
|
|
|
1
|
-
import { objectKeys as
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
for (
|
|
5
|
-
e
|
|
6
|
-
return e;
|
|
7
|
-
}, _ = (t) => t.length > 0 ? t[0] : void 0, k = (t) => t.slice(1), F = (t, n, e) => {
|
|
8
|
-
if (t.length !== n.length) return !1;
|
|
9
|
-
for (let r = 0; r < t.length; r++)
|
|
10
|
-
if (!e(t[r], n[r])) return !1;
|
|
1
|
+
import { objectKeys as d } from "./object.js";
|
|
2
|
+
const E = (t) => t.length > 0 ? t[0] : void 0, B = (t) => t.slice(1), O = (t, r, e) => {
|
|
3
|
+
if (t.length !== r.length) return !1;
|
|
4
|
+
for (let n = 0; n < t.length; n++)
|
|
5
|
+
if (!e(t[n], r[n])) return !1;
|
|
11
6
|
return !0;
|
|
12
|
-
},
|
|
13
|
-
const e = [];
|
|
14
|
-
for (const r of t) n(r) && e.push(r);
|
|
15
|
-
return e;
|
|
16
|
-
}, b = (t, n) => {
|
|
7
|
+
}, _ = (t) => t.length === 0, q = (t) => t.length > 0, b = (t, r) => {
|
|
17
8
|
const e = [];
|
|
18
|
-
for (let
|
|
19
|
-
const
|
|
20
|
-
|
|
9
|
+
for (let n = 0; n < t.length; n++) {
|
|
10
|
+
const o = r(t[n], n);
|
|
11
|
+
o != null && e.push(o);
|
|
21
12
|
}
|
|
22
13
|
return e;
|
|
23
|
-
}, j = (t) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return !0;
|
|
32
|
-
}, N = (t, n) => {
|
|
33
|
-
for (const e of t)
|
|
34
|
-
if (n(e))
|
|
35
|
-
return !0;
|
|
36
|
-
return !1;
|
|
37
|
-
}, T = (t, n) => {
|
|
38
|
-
for (const e of t) n(e);
|
|
39
|
-
}, $ = (...t) => [].concat(...t), H = (t, n, e, r = !0) => {
|
|
40
|
-
if (t.length < n.length)
|
|
41
|
-
return -1 * (r ? 1 : -1);
|
|
42
|
-
if (t.length > n.length)
|
|
43
|
-
return 1 * (r ? 1 : -1);
|
|
44
|
-
for (let l = 0; l < t.length; l++) {
|
|
45
|
-
const a = e(t[l], n[l]);
|
|
46
|
-
if (a !== 0) return a;
|
|
14
|
+
}, j = (t) => t.filter((r) => r != null), D = (t, r, e, n = !0) => {
|
|
15
|
+
if (t.length < r.length)
|
|
16
|
+
return -1 * (n ? 1 : -1);
|
|
17
|
+
if (t.length > r.length)
|
|
18
|
+
return 1 * (n ? 1 : -1);
|
|
19
|
+
for (let o = 0; o < t.length; o++) {
|
|
20
|
+
const i = e(t[o], r[o]);
|
|
21
|
+
if (i !== 0) return i;
|
|
47
22
|
}
|
|
48
23
|
return 0;
|
|
49
|
-
},
|
|
24
|
+
}, v = (t, r) => Array.from({ length: t }, (e, n) => r(n)), F = (t, r = 0) => Array.from({ length: t }, (e, n) => r + n), M = (t, r) => v(t, () => r), I = (t, r) => {
|
|
50
25
|
const e = {};
|
|
51
|
-
return t.forEach((
|
|
52
|
-
e[n
|
|
53
|
-
}),
|
|
54
|
-
},
|
|
55
|
-
const e = t.indexOf(
|
|
26
|
+
return t.forEach((n) => {
|
|
27
|
+
e[r(n)] = n;
|
|
28
|
+
}), d(e).map((n) => e[n]);
|
|
29
|
+
}, w = (t, r) => {
|
|
30
|
+
const e = t.indexOf(r);
|
|
56
31
|
return e < 0 ? !1 : (t.splice(e, 1), !0);
|
|
57
|
-
},
|
|
32
|
+
}, N = (t, r) => {
|
|
58
33
|
let e = !1;
|
|
59
|
-
for (;
|
|
34
|
+
for (; w(t, r); )
|
|
60
35
|
e = !0;
|
|
61
36
|
return e;
|
|
62
|
-
},
|
|
63
|
-
const e = t.findIndex(
|
|
37
|
+
}, x = (t, r) => {
|
|
38
|
+
const e = t.findIndex(r);
|
|
64
39
|
return e < 0 ? !1 : (t.splice(e, 1), !0);
|
|
65
|
-
},
|
|
40
|
+
}, P = (t, r) => {
|
|
66
41
|
let e = !1;
|
|
67
|
-
for (;
|
|
42
|
+
for (; x(t, r); )
|
|
68
43
|
e = !0;
|
|
69
44
|
return e;
|
|
70
|
-
},
|
|
71
|
-
const n =
|
|
72
|
-
for (let e = t.next(); !(e.done ?? !1); e = t.next())
|
|
73
|
-
n.push(e.value);
|
|
74
|
-
return n;
|
|
75
|
-
}, Q = (t, n, e) => {
|
|
76
|
-
const r = {
|
|
45
|
+
}, T = (t, r, e) => {
|
|
46
|
+
const n = {
|
|
77
47
|
removals: [],
|
|
78
48
|
swaps: [],
|
|
79
49
|
inserts: []
|
|
80
|
-
}, { removals:
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
for (let s =
|
|
84
|
-
const
|
|
85
|
-
|
|
50
|
+
}, { removals: o, inserts: i, swaps: u } = n, c = /* @__PURE__ */ new Map();
|
|
51
|
+
r.forEach((s, l) => c.set(e(s), l));
|
|
52
|
+
const a = t.map((s, l) => [s, l]).filter(([s]) => !c.has(e(s))).map(([s, l]) => l);
|
|
53
|
+
for (let s = a.length - 1; s >= 0; s--) {
|
|
54
|
+
const l = a[s], f = o.length > 0 ? o[o.length - 1] : void 0;
|
|
55
|
+
f != null && f.at === l + 1 ? (f.at--, f.qt++) : o.push({ at: l, qt: 1 });
|
|
86
56
|
}
|
|
87
57
|
const h = /* @__PURE__ */ new Map();
|
|
88
|
-
t.forEach((s,
|
|
89
|
-
const
|
|
90
|
-
for (const s of
|
|
91
|
-
const
|
|
92
|
-
|
|
58
|
+
t.forEach((s, l) => h.set(e(s), l));
|
|
59
|
+
const g = r.map((s, l) => [s, l]).filter(([s]) => !h.has(e(s))).map(([s, l]) => l);
|
|
60
|
+
for (const s of g) {
|
|
61
|
+
const l = i.length > 0 ? i[i.length - 1] : void 0;
|
|
62
|
+
l != null && l.at + l.values.length === s ? l.values.push(r[s]) : i.push({ at: s, values: [r[s]] });
|
|
93
63
|
}
|
|
94
|
-
const p = t.filter((s,
|
|
64
|
+
const p = t.filter((s, l) => !a.includes(l)), m = /* @__PURE__ */ new Map();
|
|
95
65
|
for (let s = 0; s < p.length; s++)
|
|
96
66
|
m.set(e(p[s]), s);
|
|
97
|
-
const
|
|
98
|
-
for (let s = 0; s <
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
m.delete(
|
|
67
|
+
const y = r.filter((s, l) => !g.includes(l));
|
|
68
|
+
for (let s = 0; s < y.length; s++) {
|
|
69
|
+
const l = e(y[s]), f = m.get(l);
|
|
70
|
+
if (f == null || s === f) continue;
|
|
71
|
+
const A = e(p[s]);
|
|
72
|
+
m.delete(A), u.push({ from: s, to: f });
|
|
103
73
|
}
|
|
104
|
-
return
|
|
105
|
-
},
|
|
106
|
-
const e = [...
|
|
107
|
-
for (const { at:
|
|
108
|
-
e.splice(
|
|
109
|
-
for (const { from:
|
|
110
|
-
const
|
|
111
|
-
e[
|
|
74
|
+
return n;
|
|
75
|
+
}, $ = (t, r) => {
|
|
76
|
+
const e = [...r];
|
|
77
|
+
for (const { at: n, qt: o } of t.removals)
|
|
78
|
+
e.splice(n, o);
|
|
79
|
+
for (const { from: n, to: o } of t.swaps) {
|
|
80
|
+
const i = e[o];
|
|
81
|
+
e[o] = e[n], e[n] = i;
|
|
82
|
+
}
|
|
83
|
+
for (const n of t.inserts)
|
|
84
|
+
e.splice(n.at, 0, ...n.values);
|
|
85
|
+
return e;
|
|
86
|
+
}, C = (t, r = " and ", e = ", ") => t.length === 0 ? "" : t.length === 1 ? String(t[0]) : `${t.slice(0, -1).join(e)}${r}${String(t[t.length - 1])}`, H = (t, r, e = !0) => {
|
|
87
|
+
const n = t.map((c, a) => [c, a]);
|
|
88
|
+
n.sort((c, a) => r(c[0], a[0]));
|
|
89
|
+
const o = new Array(n.length);
|
|
90
|
+
let i = 0, u = n[0][0];
|
|
91
|
+
for (let c = 0; c < n.length; c++) {
|
|
92
|
+
const [a, h] = n[c];
|
|
93
|
+
r(a, u) !== 0 && (i = c, u = a), o[h] = i, e && i++;
|
|
112
94
|
}
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
return o;
|
|
96
|
+
}, S = (t, r) => {
|
|
97
|
+
if (r <= 0)
|
|
98
|
+
throw new Error("Chunk size must be positive");
|
|
99
|
+
const e = [];
|
|
100
|
+
for (let n = 0; n < t.length; n += r)
|
|
101
|
+
e.push(t.slice(n, n + r));
|
|
115
102
|
return e;
|
|
116
|
-
},
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
103
|
+
}, R = (t, r) => {
|
|
104
|
+
const e = [], n = [];
|
|
105
|
+
for (const o of t)
|
|
106
|
+
r(o) ? e.push(o) : n.push(o);
|
|
107
|
+
return [e, n];
|
|
108
|
+
}, V = (t, r) => {
|
|
109
|
+
const e = {};
|
|
110
|
+
for (const n of t) {
|
|
111
|
+
const o = r(n);
|
|
112
|
+
e[o] ? e[o].push(n) : e[o] = [n];
|
|
124
113
|
}
|
|
125
|
-
return
|
|
114
|
+
return e;
|
|
126
115
|
};
|
|
127
116
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
$ as concatArrays,
|
|
139
|
-
R as createFilledArray,
|
|
140
|
-
x as filterArray,
|
|
117
|
+
$ as applyArrayDiffOperations,
|
|
118
|
+
O as areArraysEqual,
|
|
119
|
+
T as arrayDiffOperations,
|
|
120
|
+
q as arrayHasValues,
|
|
121
|
+
E as arrayHead,
|
|
122
|
+
B as arrayTail,
|
|
123
|
+
v as buildArray,
|
|
124
|
+
S as chunk,
|
|
125
|
+
D as compareArrays,
|
|
126
|
+
M as fillArray,
|
|
141
127
|
b as filterMapArray,
|
|
142
128
|
j as filterNullsFromArray,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
G as removeAllFromArrayByPredicate,
|
|
155
|
-
E as removeOneFromArray,
|
|
156
|
-
w as removeOneFromArrayByPredicate,
|
|
157
|
-
C as sortArray,
|
|
158
|
-
W as uniqueByPrimitive,
|
|
159
|
-
V as uniquePrimitives
|
|
129
|
+
V as groupBy,
|
|
130
|
+
_ as isArrayEmpty,
|
|
131
|
+
C as joinArrayWithConjunction,
|
|
132
|
+
R as partition,
|
|
133
|
+
F as range,
|
|
134
|
+
H as rankArray,
|
|
135
|
+
N as removeAllFromArray,
|
|
136
|
+
P as removeAllFromArrayByPredicate,
|
|
137
|
+
w as removeOneFromArray,
|
|
138
|
+
x as removeOneFromArrayByPredicate,
|
|
139
|
+
I as uniqueByPrimitive
|
|
160
140
|
};
|
package/date.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=(t,e)=>{const s=new Date(t);return s.setDate(s.getDate()+e),s},g=(t,e)=>{const s=new Date(t);return s.setHours(s.getHours()+e),s},a=(t,e)=>{const s=new Date(t);return s.setMinutes(s.getMinutes()+e),s},i=(t,e)=>{const n=Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()),r=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return Math.floor((r-n)/864e5)},c=(t,e)=>(e.getTime()-t.getTime())/36e5,D=t=>{const e=new Date(t);return e.setHours(0,0,0,0),e},l=t=>{const e=new Date(t);return e.setHours(23,59,59,999),e},o=t=>{const e=new Date(t),s=e.getDay(),n=e.getDate()-s+(s===0?-6:1);return e.setDate(n),e.setHours(0,0,0,0),e},m=t=>{const e=new Date(t),s=e.getDay(),n=e.getDate()-s+(s===0?0:7);return e.setDate(n),e.setHours(23,59,59,999),e},M=t=>t instanceof Date&&!isNaN(t.getTime()),f=(t,e)=>t.getFullYear()===e.getFullYear(),y=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth(),H=(t,e)=>o(t).getTime()===o(e).getTime(),S=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),Y=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()&&t.getHours()===e.getHours(),h=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()&&t.getHours()===e.getHours()&&t.getMinutes()===e.getMinutes(),F=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()&&t.getHours()===e.getHours()&&t.getMinutes()===e.getMinutes()&&t.getSeconds()===e.getSeconds(),T=t=>{const e=t.getDay();return e===0||e===6},O=(t,e)=>t.getTime()-e.getTime();exports.addDays=u;exports.addHours=g;exports.addMinutes=a;exports.compareDates=O;exports.diffInDays=i;exports.diffInHours=c;exports.endOfDay=l;exports.endOfWeek=m;exports.isSameDay=S;exports.isSameHour=Y;exports.isSameMinute=h;exports.isSameMonth=y;exports.isSameSecond=F;exports.isSameWeek=H;exports.isSameYear=f;exports.isValidDate=M;exports.isWeekend=T;exports.startOfDay=D;exports.startOfWeek=o;
|
package/date.d.ts
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with Date objects.
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive date manipulation, comparison, and
|
|
5
|
+
* formatting utilities. All functions return new Date objects and do not
|
|
6
|
+
* mutate the input dates, following functional programming principles.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Adds the specified number of days to a date.
|
|
12
|
+
*
|
|
13
|
+
* This function creates a new Date object with the specified number of days
|
|
14
|
+
* added. Negative values subtract days.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const date = new Date('2023-01-15')
|
|
19
|
+
* const future = addDays(date, 7)
|
|
20
|
+
* // Result: 2023-01-22
|
|
21
|
+
*
|
|
22
|
+
* const past = addDays(date, -3)
|
|
23
|
+
* // Result: 2023-01-12
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param date - The base date
|
|
27
|
+
* @param days - Number of days to add (can be negative)
|
|
28
|
+
* @returns A new Date object with days added
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare const addDays: (date: Date, days: number) => Date;
|
|
32
|
+
/**
|
|
33
|
+
* Adds the specified number of hours to a date.
|
|
34
|
+
*
|
|
35
|
+
* This function creates a new Date object with the specified number of hours
|
|
36
|
+
* added. Negative values subtract hours.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const date = new Date('2023-01-15T10:00:00')
|
|
41
|
+
* const future = addHours(date, 5)
|
|
42
|
+
* // Result: 2023-01-15T15:00:00
|
|
43
|
+
*
|
|
44
|
+
* const past = addHours(date, -2)
|
|
45
|
+
* // Result: 2023-01-15T08:00:00
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param date - The base date
|
|
49
|
+
* @param hours - Number of hours to add (can be negative)
|
|
50
|
+
* @returns A new Date object with hours added
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export declare const addHours: (date: Date, hours: number) => Date;
|
|
54
|
+
/**
|
|
55
|
+
* Adds the specified number of minutes to a date.
|
|
56
|
+
*
|
|
57
|
+
* This function creates a new Date object with the specified number of minutes
|
|
58
|
+
* added. Negative values subtract minutes.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const date = new Date('2023-01-15T10:30:00')
|
|
63
|
+
* const future = addMinutes(date, 45)
|
|
64
|
+
* // Result: 2023-01-15T11:15:00
|
|
65
|
+
*
|
|
66
|
+
* const past = addMinutes(date, -15)
|
|
67
|
+
* // Result: 2023-01-15T10:15:00
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param date - The base date
|
|
71
|
+
* @param minutes - Number of minutes to add (can be negative)
|
|
72
|
+
* @returns A new Date object with minutes added
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export declare const addMinutes: (date: Date, minutes: number) => Date;
|
|
76
|
+
/**
|
|
77
|
+
* Calculates the difference in days between two dates.
|
|
78
|
+
*
|
|
79
|
+
* Returns a positive number if dateB is after dateA, negative if before.
|
|
80
|
+
* The calculation ignores time components and focuses on calendar days.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const dateA = new Date('2023-01-15')
|
|
85
|
+
* const dateB = new Date('2023-01-20')
|
|
86
|
+
* const diff = diffInDays(dateA, dateB)
|
|
87
|
+
* // Result: 5
|
|
88
|
+
*
|
|
89
|
+
* const diffReverse = diffInDays(dateB, dateA)
|
|
90
|
+
* // Result: -5
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param dateA - The first date
|
|
94
|
+
* @param dateB - The second date
|
|
95
|
+
* @returns The difference in days (dateB - dateA)
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare const diffInDays: (dateA: Date, dateB: Date) => number;
|
|
99
|
+
/**
|
|
100
|
+
* Calculates the difference in hours between two dates.
|
|
101
|
+
*
|
|
102
|
+
* Returns a positive number if dateB is after dateA, negative if before.
|
|
103
|
+
* The result includes fractional hours for precise calculations.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const dateA = new Date('2023-01-15T10:00:00')
|
|
108
|
+
* const dateB = new Date('2023-01-15T15:30:00')
|
|
109
|
+
* const diff = diffInHours(dateA, dateB)
|
|
110
|
+
* // Result: 5.5
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param dateA - The first date
|
|
114
|
+
* @param dateB - The second date
|
|
115
|
+
* @returns The difference in hours (dateB - dateA)
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
export declare const diffInHours: (dateA: Date, dateB: Date) => number;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a new Date representing the start of the day (00:00:00.000).
|
|
121
|
+
*
|
|
122
|
+
* This is useful for date comparisons and range queries where you need
|
|
123
|
+
* to normalize dates to the beginning of the day.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const date = new Date('2023-01-15T14:30:45.123')
|
|
128
|
+
* const start = startOfDay(date)
|
|
129
|
+
* // Result: 2023-01-15T00:00:00.000
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param date - The input date
|
|
133
|
+
* @returns A new Date set to the start of the day
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
export declare const startOfDay: (date: Date) => Date;
|
|
137
|
+
/**
|
|
138
|
+
* Returns a new Date representing the end of the day (23:59:59.999).
|
|
139
|
+
*
|
|
140
|
+
* This is useful for date range queries where you need the last
|
|
141
|
+
* millisecond of a given day.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const date = new Date('2023-01-15T14:30:45.123')
|
|
146
|
+
* const end = endOfDay(date)
|
|
147
|
+
* // Result: 2023-01-15T23:59:59.999
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @param date - The input date
|
|
151
|
+
* @returns A new Date set to the end of the day
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export declare const endOfDay: (date: Date) => Date;
|
|
155
|
+
/**
|
|
156
|
+
* Returns a new Date representing the start of the week (Monday 00:00:00.000).
|
|
157
|
+
*
|
|
158
|
+
* This follows the ISO 8601 standard where Monday is the first day of the week.
|
|
159
|
+
* Useful for weekly reports and date grouping.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const date = new Date('2023-01-18') // Wednesday
|
|
164
|
+
* const start = startOfWeek(date)
|
|
165
|
+
* // Result: 2023-01-16T00:00:00.000 (Monday)
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @param date - The input date
|
|
169
|
+
* @returns A new Date set to the start of the week
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
export declare const startOfWeek: (date: Date) => Date;
|
|
173
|
+
/**
|
|
174
|
+
* Returns a new Date representing the end of the week (Sunday 23:59:59.999).
|
|
175
|
+
*
|
|
176
|
+
* This follows the ISO 8601 standard where Sunday is the last day of the week.
|
|
177
|
+
* Useful for weekly reports and date grouping.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const date = new Date('2023-01-18') // Wednesday
|
|
182
|
+
* const end = endOfWeek(date)
|
|
183
|
+
* // Result: 2023-01-22T23:59:59.999 (Sunday)
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @param date - The input date
|
|
187
|
+
* @returns A new Date set to the end of the week
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
export declare const endOfWeek: (date: Date) => Date;
|
|
191
|
+
/**
|
|
192
|
+
* Checks if a value is a valid Date object.
|
|
193
|
+
*
|
|
194
|
+
* This function checks both that the value is a Date instance and that
|
|
195
|
+
* it represents a valid date (not NaN).
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* isValidDate(new Date()) // true
|
|
200
|
+
* isValidDate(new Date('2023-01-15')) // true
|
|
201
|
+
* isValidDate(new Date('invalid')) // false
|
|
202
|
+
* isValidDate('2023-01-15') // false
|
|
203
|
+
* isValidDate(null) // false
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @param date - The value to check
|
|
207
|
+
* @returns true if the value is a valid Date, false otherwise
|
|
208
|
+
* @public
|
|
209
|
+
*/
|
|
210
|
+
export declare const isValidDate: (date: unknown) => date is Date;
|
|
211
|
+
/**
|
|
212
|
+
* Checks if two dates represent the same calendar year.
|
|
213
|
+
*
|
|
214
|
+
* This comparison ignores the month and day components and only compares the year part.
|
|
215
|
+
* Useful for yearly reports and date grouping.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const date1 = new Date('2023-01-15') // January
|
|
220
|
+
* const date2 = new Date('2023-02-15') // February
|
|
221
|
+
* const date3 = new Date('2024-01-15') // January of next year
|
|
222
|
+
*
|
|
223
|
+
* isSameYear(date1, date2) // true
|
|
224
|
+
* isSameYear(date1, date3) // false
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @param dateA - The first date
|
|
228
|
+
* @param dateB - The second date
|
|
229
|
+
* @returns true if both dates represent the same calendar year
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
export declare const isSameYear: (dateA: Date, dateB: Date) => boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Checks if two dates represent the same calendar month.
|
|
235
|
+
*
|
|
236
|
+
* This comparison ignores the day and time components and only compares the month and year parts.
|
|
237
|
+
* Useful for monthly reports and date grouping.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const date1 = new Date('2023-01-15') // January
|
|
242
|
+
* const date2 = new Date('2023-02-15') // February
|
|
243
|
+
* const date3 = new Date('2024-01-15') // January of next year
|
|
244
|
+
*
|
|
245
|
+
* isSameMonth(date1, date2) // false
|
|
246
|
+
* isSameMonth(date1, date3) // true
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @param dateA - The first date
|
|
250
|
+
* @param dateB - The second date
|
|
251
|
+
* @returns true if both dates represent the same calendar month
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
export declare const isSameMonth: (dateA: Date, dateB: Date) => boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Checks if two dates represent the same calendar week.
|
|
257
|
+
*
|
|
258
|
+
* This comparison uses the ISO 8601 week definition, where weeks start on Monday.
|
|
259
|
+
* Useful for weekly reports and date grouping.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const date1 = new Date('2023-01-15') // Monday
|
|
264
|
+
* const date2 = new Date('2023-01-16') // Tuesday
|
|
265
|
+
* const date3 = new Date('2023-01-22') // Monday of next week
|
|
266
|
+
*
|
|
267
|
+
* isSameWeek(date1, date2) // true
|
|
268
|
+
* isSameWeek(date1, date3) // false
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @param dateA - The first date
|
|
272
|
+
* @param dateB - The second date
|
|
273
|
+
* @returns true if both dates represent the same calendar week
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
export declare const isSameWeek: (dateA: Date, dateB: Date) => boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Checks if two dates represent the same calendar day.
|
|
279
|
+
*
|
|
280
|
+
* This comparison ignores time components and only compares the date parts.
|
|
281
|
+
* Useful for date-based filtering and grouping.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const date1 = new Date('2023-01-15T10:30:00')
|
|
286
|
+
* const date2 = new Date('2023-01-15T18:45:00')
|
|
287
|
+
* const date3 = new Date('2023-01-16T10:30:00')
|
|
288
|
+
*
|
|
289
|
+
* isSameDay(date1, date2) // true
|
|
290
|
+
* isSameDay(date1, date3) // false
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @param dateA - The first date
|
|
294
|
+
* @param dateB - The second date
|
|
295
|
+
* @returns true if both dates represent the same calendar day
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
export declare const isSameDay: (dateA: Date, dateB: Date) => boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Checks if two dates represent the same hour.
|
|
301
|
+
*
|
|
302
|
+
* This comparison ignores date and minute components and only compares the hour parts.
|
|
303
|
+
* Useful for time-based filtering and grouping.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* const date1 = new Date('2023-01-15T10:30:00')
|
|
308
|
+
* const date2 = new Date('2023-01-15T10:45:00')
|
|
309
|
+
* const date3 = new Date('2023-01-16T10:30:00')
|
|
310
|
+
*
|
|
311
|
+
* isSameHour(date1, date2) // true
|
|
312
|
+
* isSameHour(date1, date3) // false
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @param dateA - The first date
|
|
316
|
+
* @param dateB - The second date
|
|
317
|
+
* @returns true if both dates represent the same hour
|
|
318
|
+
* @public
|
|
319
|
+
*/
|
|
320
|
+
export declare const isSameHour: (dateA: Date, dateB: Date) => boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Checks if two dates represent the same minute.
|
|
323
|
+
*
|
|
324
|
+
* This comparison ignores date, hour, and second components and only compares the minute parts.
|
|
325
|
+
* Useful for time-based filtering and grouping.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const date1 = new Date('2023-01-15T10:30:00')
|
|
330
|
+
* const date2 = new Date('2023-01-15T10:30:45')
|
|
331
|
+
* const date3 = new Date('2023-01-16T10:30:00')
|
|
332
|
+
*
|
|
333
|
+
* isSameMinute(date1, date2) // true
|
|
334
|
+
* isSameMinute(date1, date3) // false
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @param dateA - The first date
|
|
338
|
+
* @param dateB - The second date
|
|
339
|
+
* @returns true if both dates represent the same minute
|
|
340
|
+
* @public
|
|
341
|
+
*/
|
|
342
|
+
export declare const isSameMinute: (dateA: Date, dateB: Date) => boolean;
|
|
343
|
+
/**
|
|
344
|
+
* Checks if two dates represent the same second.
|
|
345
|
+
*
|
|
346
|
+
* This comparison ignores date, hour, and minute components and only compares the second parts.
|
|
347
|
+
* Useful for time-based filtering and grouping.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const date1 = new Date('2023-01-15T10:30:00')
|
|
352
|
+
* const date2 = new Date('2023-01-15T10:30:00')
|
|
353
|
+
* const date3 = new Date('2023-01-16T10:30:00')
|
|
354
|
+
*
|
|
355
|
+
* isSameSecond(date1, date2) // true
|
|
356
|
+
* isSameSecond(date1, date3) // false
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* @param dateA - The first date
|
|
360
|
+
* @param dateB - The second date
|
|
361
|
+
* @returns true if both dates represent the same second
|
|
362
|
+
* @public
|
|
363
|
+
*/
|
|
364
|
+
export declare const isSameSecond: (dateA: Date, dateB: Date) => boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Checks if a date falls on a weekend (Saturday or Sunday).
|
|
367
|
+
*
|
|
368
|
+
* This is useful for business logic that needs to handle weekends differently,
|
|
369
|
+
* such as scheduling or date calculations.
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* const saturday = new Date('2023-01-14') // Saturday
|
|
374
|
+
* const monday = new Date('2023-01-16') // Monday
|
|
375
|
+
*
|
|
376
|
+
* isWeekend(saturday) // true
|
|
377
|
+
* isWeekend(monday) // false
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* @param date - The date to check
|
|
381
|
+
* @returns true if the date is a Saturday or Sunday
|
|
382
|
+
* @public
|
|
383
|
+
*/
|
|
384
|
+
export declare const isWeekend: (date: Date) => boolean;
|
|
385
|
+
/**
|
|
386
|
+
* Compares two dates.
|
|
387
|
+
*
|
|
388
|
+
* @param a - The first date
|
|
389
|
+
* @param b - The second date
|
|
390
|
+
* @returns A negative number if `a` is less than `b`, zero if they are equal, or a positive number if `a` is greater than `b`.
|
|
391
|
+
* @public
|
|
392
|
+
*/
|
|
393
|
+
export declare const compareDates: (a: Date, b: Date) => number;
|