corebasic 1.0.211 → 1.0.212
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/index.ts +23 -0
- package/libs/{auth.js → auth.ts} +3 -3
- package/libs/{compression.js → compression.ts} +1 -1
- package/libs/dip/suffix/date.ts +121 -0
- package/libs/dip/suffix/{index.js → index.ts} +7 -18
- package/libs/dip/suffix/{policy.js → policy.ts} +2 -2
- package/libs/dip/suffix/{suffix.js → suffix.ts} +2 -2
- package/libs/dip/suffix/tests/{date.test.js → date.test.ts} +1 -1
- package/libs/dip/suffix/tests/{index.test.js → index.test.ts} +1 -1
- package/libs/dip/suffix/tests/{policy.applySuffixPolicy.test.js → policy.applySuffixPolicy.test.ts} +1 -1
- package/libs/dip/suffix/tests/{policy.test.js → policy.test.ts} +1 -1
- package/libs/dip/suffix/tests/{suffix.test.js → suffix.test.ts} +1 -1
- package/libs/{dip.js → dip.ts} +1 -1
- package/libs/{elabase.js → elabase.ts} +4 -4
- package/libs/{features.js → features.ts} +5 -5
- package/libs/{messaging.js → messaging.ts} +1 -1
- package/libs/{session.js → session.ts} +2 -2
- package/libs/{utils.js → utils.ts} +80 -9
- package/package.json +2 -2
- package/index.js +0 -23
- package/libs/dip/suffix/date.js +0 -103
- /package/libs/{ObjectId.js → ObjectId.ts} +0 -0
- /package/libs/{cpp.js → cpp.ts} +0 -0
- /package/libs/dip/suffix/{query.js → query.ts} +0 -0
- /package/libs/{dipper.js → dipper.ts} +0 -0
- /package/libs/{kafka.js → kafka.ts} +0 -0
- /package/libs/{mobilecodes.js → mobilecodes.ts} +0 -0
package/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import * as Elabase from './libs/elabase.ts'
|
|
4
|
+
import * as Dip from './libs/dip.ts'
|
|
5
|
+
import * as Kafka from './libs/kafka.ts'
|
|
6
|
+
import * as Utils from './libs/utils.ts'
|
|
7
|
+
import * as Session from './libs/session.ts'
|
|
8
|
+
import * as Auth from './libs/auth.ts'
|
|
9
|
+
import * as Features from './libs/features.ts'
|
|
10
|
+
import * as Messaging from './libs/messaging.ts'
|
|
11
|
+
import * as Compression from './libs/compression.ts'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
Elabase,
|
|
15
|
+
Dip,
|
|
16
|
+
Kafka,
|
|
17
|
+
Utils,
|
|
18
|
+
Session,
|
|
19
|
+
Auth,
|
|
20
|
+
Features,
|
|
21
|
+
Messaging,
|
|
22
|
+
Compression
|
|
23
|
+
}
|
package/libs/{auth.js → auth.ts}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import otpGenerator from 'otp-generator'
|
|
3
3
|
|
|
4
|
-
import * as Dip from './dip.
|
|
5
|
-
import * as Utils from './utils.
|
|
6
|
-
import * as Session from './session.
|
|
4
|
+
import * as Dip from './dip.ts'
|
|
5
|
+
import * as Utils from './utils.ts'
|
|
6
|
+
import * as Session from './session.ts'
|
|
7
7
|
|
|
8
8
|
let validateFn, validateErrMessage
|
|
9
9
|
export const validate = (callback, errMessage) => {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {getNormalizedBounds} from './index.ts'
|
|
2
|
+
import {addUTCYears, addUTCMonths, addUTCDays} from '../../utils.ts'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const MONTH_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
|
6
|
+
const MONTH_LONG = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export function formatDate(value, format) {
|
|
10
|
+
|
|
11
|
+
const dateObj = value instanceof Date ? value : new Date(value)
|
|
12
|
+
|
|
13
|
+
if (Number.isNaN(dateObj.getTime()))
|
|
14
|
+
throw new Error(`Error: Invalid date: ${value} in suffix policy specified for key in Dip`)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const utcMs = dateObj.getTime();
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// Constant millisecond values for the extreme timezone edges
|
|
21
|
+
const TWELVE_HOURS_MS = 43200000; // 12 * 60 * 60 * 1000
|
|
22
|
+
const FOURTEEN_HOURS_MS = 50400000; // 14 * 60 * 60 * 1000
|
|
23
|
+
|
|
24
|
+
// Create dates for the absolute furthest west, UTC, and furthest east
|
|
25
|
+
const dWest = new Date(utcMs - TWELVE_HOURS_MS);
|
|
26
|
+
const dEast = new Date(utcMs + FOURTEEN_HOURS_MS);
|
|
27
|
+
|
|
28
|
+
// Extract individual components using UTC methods
|
|
29
|
+
const y1 = dWest.getUTCFullYear(), m1 = dWest.getUTCMonth(), d1 = dWest.getUTCDate();
|
|
30
|
+
const y2 = dateObj.getUTCFullYear(), m2 = dateObj.getUTCMonth(), d2 = dateObj.getUTCDate();
|
|
31
|
+
const y3 = dEast.getUTCFullYear(), m3 = dEast.getUTCMonth(), d3 = dEast.getUTCDate();
|
|
32
|
+
|
|
33
|
+
// Fast, loop-free deduplication using inline conditions
|
|
34
|
+
const years = [y1];
|
|
35
|
+
if (y2 !== y1) years.push(y2);
|
|
36
|
+
if (y3 !== y2 && y3 !== y1) years.push(y3);
|
|
37
|
+
|
|
38
|
+
const months = [m1];
|
|
39
|
+
if (m2 !== m1) months.push(m2);
|
|
40
|
+
if (m3 !== m2 && m3 !== m1) months.push(m3);
|
|
41
|
+
|
|
42
|
+
const dates = [d1];
|
|
43
|
+
if (d2 !== d1) dates.push(d2);
|
|
44
|
+
if (d3 !== d2 && d3 !== d1) dates.push(d3);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// years and months and dates are already deduplicated
|
|
49
|
+
|
|
50
|
+
const separator = '|'
|
|
51
|
+
|
|
52
|
+
const replacements = {
|
|
53
|
+
YYYY: _ => years.join(separator),
|
|
54
|
+
YY: _ => years.map(y => String(y).slice(-2)).join(separator),
|
|
55
|
+
MMMM: _ => months.map(m => MONTH_LONG[m]).join(separator),
|
|
56
|
+
MMM: _ => months.map(m => MONTH_SHORT[m]).join(separator),
|
|
57
|
+
MM: _ => months.map(m => String(m + 1).padStart(2, "0")).join(separator),
|
|
58
|
+
DD: _ => dates.map(d => String(d).padStart(2, "0")).join(separator),
|
|
59
|
+
D: _ => dates.join(separator),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return format.replace(/YYYY|MMMM|MMM|YY|MM|DD|D/g, token => replacements[token]());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// 📋 Supported Formats
|
|
67
|
+
// YYYY: 4-digit year (e.g., 2026)
|
|
68
|
+
// YY: 2-digit year (e.g., 26)
|
|
69
|
+
// MMMM: Full month name (e.g., July)
|
|
70
|
+
// MMM: Short month name (e.g., Jul)
|
|
71
|
+
// MM: 2-digit padded month (e.g., 07)
|
|
72
|
+
// DD: 2-digit padded day (e.g., 09)
|
|
73
|
+
// D: Unpadded day (e.g., 9)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// // let a = new Date()
|
|
78
|
+
// // let a = "2026-11-1"
|
|
79
|
+
// let a = new Date().getTime()
|
|
80
|
+
// let b = formatDate(a, "YYYY/DD-MMMM")
|
|
81
|
+
// console.log(b)
|
|
82
|
+
//
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
export function fillDates(bounds_t, format) {
|
|
87
|
+
const result = [];
|
|
88
|
+
|
|
89
|
+
let step;
|
|
90
|
+
if (format.includes("D"))
|
|
91
|
+
step = "day";
|
|
92
|
+
else if (format.includes("M"))
|
|
93
|
+
step = "month";
|
|
94
|
+
else
|
|
95
|
+
step = "year";
|
|
96
|
+
|
|
97
|
+
let bounds = { ...bounds_t, from: new Date(bounds_t.from), to: new Date(bounds_t.to) }
|
|
98
|
+
|
|
99
|
+
bounds = getNormalizedBounds(bounds, "date")
|
|
100
|
+
|
|
101
|
+
while (bounds.from <= bounds.to) {
|
|
102
|
+
result.push(formatDate(bounds.from, format));
|
|
103
|
+
|
|
104
|
+
switch (step) {
|
|
105
|
+
case "day":
|
|
106
|
+
addUTCDays(bounds.from, 1)
|
|
107
|
+
break;
|
|
108
|
+
case "month":
|
|
109
|
+
addUTCMonths(bounds.from, 1)
|
|
110
|
+
break;
|
|
111
|
+
case "year":
|
|
112
|
+
addUTCYears(bounds.from, 1)
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return [...new Set(result)];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
@@ -203,8 +203,8 @@ export function extractBounds(values) {
|
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
// Converts exclusive bounds ($gt/$lt) into inclusive bounds
|
|
207
|
-
export function getNormalizedBounds(bounds_t, type
|
|
206
|
+
// Converts exclusive bounds ($gt/$lt) into inclusive bounds
|
|
207
|
+
export function getNormalizedBounds(bounds_t, type) {
|
|
208
208
|
let bounds = {...bounds_t}
|
|
209
209
|
|
|
210
210
|
if (type === "number") {
|
|
@@ -213,22 +213,11 @@ export function getNormalizedBounds(bounds_t, type, step) {
|
|
|
213
213
|
if (bounds.toOp === "$lt")
|
|
214
214
|
bounds.to--;
|
|
215
215
|
} else if (type === "date") {
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
} else if (step === "month") {
|
|
222
|
-
if (bounds.fromOp === "$gt")
|
|
223
|
-
bounds.from.setMonth(bounds.from.getMonth() + 1);
|
|
224
|
-
if (bounds.toOp === "$lt")
|
|
225
|
-
bounds.to.setMonth(bounds.to.getMonth() - 1);
|
|
226
|
-
} else {
|
|
227
|
-
if (bounds.fromOp === "$gt")
|
|
228
|
-
bounds.from.setFullYear(bounds.from.getFullYear() + 1);
|
|
229
|
-
if (bounds.toOp === "$lt")
|
|
230
|
-
bounds.to.setFullYear(bounds.to.getFullYear() - 1);
|
|
231
|
-
}
|
|
216
|
+
if (bounds.fromOp === "$gt")
|
|
217
|
+
bounds.from = new Date(bounds.from.getTime() + 1);
|
|
218
|
+
|
|
219
|
+
if (bounds.toOp === "$lt")
|
|
220
|
+
bounds.to = new Date(bounds.to.getTime() - 1);
|
|
232
221
|
}
|
|
233
222
|
|
|
234
223
|
return bounds
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {entries, reduceRanges, extractBounds, getNormalizedBounds} from './index.
|
|
2
|
-
import {formatDate, fillDates} from './date.
|
|
1
|
+
import {entries, reduceRanges, extractBounds, getNormalizedBounds} from './index.ts'
|
|
2
|
+
import {formatDate, fillDates} from './date.ts'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
package/libs/dip/suffix/tests/{policy.applySuffixPolicy.test.js → policy.applySuffixPolicy.test.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import {applySuffixPolicy} from "../policy.
|
|
3
|
+
import {applySuffixPolicy} from "../policy.ts";
|
|
4
4
|
|
|
5
5
|
// -----------------------------------------------------------------------------
|
|
6
6
|
// applySuffixPolicy()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, test } from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
|
-
import {matchPolicy, overlaps, contains, intersects, applySuffixPolicy} from "../policy.
|
|
3
|
+
import {matchPolicy, overlaps, contains, intersects, applySuffixPolicy} from "../policy.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/* ============================================================
|
package/libs/{dip.js → dip.ts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import {default as dipper, shard_stats as ShardStats} from './dipper.
|
|
3
|
-
import * as Utils from './utils.
|
|
4
|
-
import * as Cpp from './cpp.
|
|
5
|
-
import {applySuffixPolicy} from './dip/suffix/policy.
|
|
2
|
+
import {default as dipper, shard_stats as ShardStats} from './dipper.ts'
|
|
3
|
+
import * as Utils from './utils.ts'
|
|
4
|
+
import * as Cpp from './cpp.ts'
|
|
5
|
+
import {applySuffixPolicy} from './dip/suffix/policy.ts'
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as Dip from './dip.
|
|
2
|
-
import * as Kafka from './kafka.
|
|
3
|
-
import * as Utils from './utils.
|
|
4
|
-
import * as Session from './session.
|
|
5
|
-
import * as Messaging from './messaging.
|
|
1
|
+
import * as Dip from './dip.ts'
|
|
2
|
+
import * as Kafka from './kafka.ts'
|
|
3
|
+
import * as Utils from './utils.ts'
|
|
4
|
+
import * as Session from './session.ts'
|
|
5
|
+
import * as Messaging from './messaging.ts'
|
|
6
6
|
import axios from 'axios'
|
|
7
7
|
import jwt from 'jsonwebtoken'
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as ObjectId from './ObjectId.
|
|
2
|
-
import * as Mobile from './mobilecodes.
|
|
1
|
+
import * as ObjectId from './ObjectId.ts'
|
|
2
|
+
import * as Mobile from './mobilecodes.ts'
|
|
3
3
|
|
|
4
4
|
// Parse JSON file: fileToJson
|
|
5
5
|
import {readFile,writeFile} from 'fs/promises';
|
|
@@ -167,18 +167,62 @@ export function sum(array) { // Eg: sum([10,20,undefined, NaN, 40])
|
|
|
167
167
|
return res;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
|
|
171
|
+
export function addMonths(date, monthsToAdd) { // simpler alternative to setNextMonth because rollover always changes the day number
|
|
172
|
+
const day = date.getDate();
|
|
173
|
+
date.setMonth(date.getMonth() + monthsToAdd);
|
|
174
|
+
// If the day rolled over, clamp to last day of target month
|
|
175
|
+
if (date.getDate() !== day) {
|
|
176
|
+
date.setDate(0);
|
|
177
|
+
}
|
|
178
|
+
return date;
|
|
179
|
+
}
|
|
180
|
+
export function addYears(date, yearsToAdd) { // Reuse addMonths to cleanly clamp Feb 29 to Feb 28 instead of 1 March on non-leap years
|
|
181
|
+
return addMonths(date, yearsToAdd * 12)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function addUTCMonths(date, monthsToAdd) { // simpler alternative to setUTCNextMonth because rollover always changes the day number
|
|
185
|
+
const day = date.getUTCDate();
|
|
186
|
+
date.setUTCMonth(date.getUTCMonth() + monthsToAdd);
|
|
187
|
+
// If the day rolled over, clamp to last day of target month
|
|
188
|
+
if (date.getUTCDate() !== day) {
|
|
189
|
+
date.setUTCDate(0);
|
|
190
|
+
}
|
|
191
|
+
return date;
|
|
192
|
+
}
|
|
193
|
+
export function addUTCYears(date, yearsToAdd) { // Reuse addMonths to cleanly clamp Feb 29 to Feb 28 instead of 1 March on non-leap years
|
|
194
|
+
return addUTCMonths(date, yearsToAdd * 12)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function addDays(date, daysToAdd) {
|
|
198
|
+
date.setDate(date.getDate() + daysToAdd)
|
|
199
|
+
return date
|
|
200
|
+
}
|
|
201
|
+
export function addHours(date, hoursToAdd) {
|
|
202
|
+
date.setHours(date.getHours() + hoursToAdd)
|
|
203
|
+
return date
|
|
204
|
+
}
|
|
205
|
+
export function addUTCDays(date, daysToAdd) {
|
|
206
|
+
date.setUTCDate(date.getUTCDate() + daysToAdd)
|
|
207
|
+
return date
|
|
208
|
+
}
|
|
209
|
+
export function addUTCHours(date, hoursToAdd) {
|
|
210
|
+
date.setUTCHours(date.getUTCHours() + hoursToAdd)
|
|
211
|
+
return date
|
|
212
|
+
}
|
|
213
|
+
|
|
170
214
|
export function validityToMillisecs(start, validity) { // start is in ms
|
|
171
215
|
const now = new Date(start)
|
|
172
216
|
|
|
173
|
-
let count =
|
|
174
|
-
|
|
175
|
-
|
|
217
|
+
let [count, period] = validity.trim().split(' ').filter(item => item.trim())
|
|
218
|
+
count = parseIntValue(count)
|
|
219
|
+
period = period.toLowerCase()
|
|
176
220
|
|
|
177
221
|
const timeline = {
|
|
178
|
-
year: _ =>
|
|
179
|
-
years: _ =>
|
|
180
|
-
month: _ =>
|
|
181
|
-
months: _ =>
|
|
222
|
+
year: _ => addYears(now, count),
|
|
223
|
+
years: _ => addYears(now, count),
|
|
224
|
+
month: _ => addMonths(now, count),
|
|
225
|
+
months: _ => addMonths(now, count),
|
|
182
226
|
day: _ => now.setDate(now.getDate() + count),
|
|
183
227
|
days: _ => now.setDate(now.getDate() + count),
|
|
184
228
|
week: _ => now.setDate(now.getDate() + (count * 7)),
|
|
@@ -193,6 +237,33 @@ export function validityToMillisecs(start, validity) { // start is in ms
|
|
|
193
237
|
|
|
194
238
|
return now.getTime()
|
|
195
239
|
}
|
|
240
|
+
export function validityToUTCMillisecs(start, validity) { // start is in ms
|
|
241
|
+
const now = new Date(start)
|
|
242
|
+
|
|
243
|
+
let [count, period] = validity.trim().split(' ').filter(item => item.trim())
|
|
244
|
+
count = parseIntValue(count)
|
|
245
|
+
period = period.toLowerCase()
|
|
246
|
+
|
|
247
|
+
const timeline = {
|
|
248
|
+
year: _ => addUTCYears(now, count),
|
|
249
|
+
years: _ => addUTCYears(now, count),
|
|
250
|
+
month: _ => addUTCMonths(now, count),
|
|
251
|
+
months: _ => addUTCMonths(now, count),
|
|
252
|
+
day: _ => now.setUTCDate(now.getUTCDate() + count),
|
|
253
|
+
days: _ => now.setUTCDate(now.getUTCDate() + count),
|
|
254
|
+
week: _ => now.setUTCDate(now.getUTCDate() + (count * 7)),
|
|
255
|
+
weeks: _ => now.setUTCDate(now.getUTCDate() + (count * 7)),
|
|
256
|
+
hour: _ => now.setUTCHours(now.getUTCHours() + count),
|
|
257
|
+
hours: _ => now.setUTCHours(now.getUTCHours() + count),
|
|
258
|
+
minute: _ => now.setUTCMinutes(now.getUTCMinutes() + count),
|
|
259
|
+
minutes: _ => now.setUTCMinutes(now.getUTCMinutes() + count),
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
timeline[period]()
|
|
263
|
+
|
|
264
|
+
return now.getTime()
|
|
265
|
+
}
|
|
266
|
+
|
|
196
267
|
|
|
197
268
|
// ----------------
|
|
198
269
|
// JSON
|
package/package.json
CHANGED
package/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import * as Elabase from './libs/elabase.js'
|
|
4
|
-
import * as Dip from './libs/dip.js'
|
|
5
|
-
import * as Kafka from './libs/kafka.js'
|
|
6
|
-
import * as Utils from './libs/utils.js'
|
|
7
|
-
import * as Session from './libs/session.js'
|
|
8
|
-
import * as Auth from './libs/auth.js'
|
|
9
|
-
import * as Features from './libs/features.js'
|
|
10
|
-
import * as Messaging from './libs/messaging.js'
|
|
11
|
-
import * as Compression from './libs/compression.js'
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
Elabase,
|
|
15
|
-
Dip,
|
|
16
|
-
Kafka,
|
|
17
|
-
Utils,
|
|
18
|
-
Session,
|
|
19
|
-
Auth,
|
|
20
|
-
Features,
|
|
21
|
-
Messaging,
|
|
22
|
-
Compression
|
|
23
|
-
}
|
package/libs/dip/suffix/date.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {getNormalizedBounds} from './index.js'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const MONTH_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
|
5
|
-
const MONTH_LONG = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
|
6
|
-
|
|
7
|
-
export function formatDate(value, format) {
|
|
8
|
-
const date = new Date(value)
|
|
9
|
-
|
|
10
|
-
if (Number.isNaN(date.getTime()))
|
|
11
|
-
throw new Error(`Error: Invalid date: ${value} in suffix policy specified for key in Dip`)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const day = date.getDate();
|
|
15
|
-
const monthIndex = date.getMonth();
|
|
16
|
-
const year = date.getFullYear();
|
|
17
|
-
|
|
18
|
-
// Pad single digits with a leading zero
|
|
19
|
-
const dd = String(day).padStart(2, '0');
|
|
20
|
-
const mm = String(monthIndex + 1).padStart(2, '0');
|
|
21
|
-
const yy = String(year).slice(-2);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// return format
|
|
25
|
-
// .replace('YYYY', year)
|
|
26
|
-
// .replace('YY', yy)
|
|
27
|
-
// .replace('MMMM', MONTH_LONG[monthIndex])
|
|
28
|
-
// .replace('MMM', MONTH_SHORT[monthIndex])
|
|
29
|
-
// .replace('MM', mm)
|
|
30
|
-
// .replace('DD', dd)
|
|
31
|
-
// .replace('D', day);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const replacements = {
|
|
35
|
-
YYYY: String(year),
|
|
36
|
-
YY: String(year).slice(-2),
|
|
37
|
-
MMMM: MONTH_LONG[monthIndex],
|
|
38
|
-
MMM: MONTH_SHORT[monthIndex],
|
|
39
|
-
MM: String(monthIndex + 1).padStart(2, "0"),
|
|
40
|
-
DD: String(day).padStart(2, "0"),
|
|
41
|
-
D: String(day),
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return format.replace(/YYYY|MMMM|MMM|YY|MM|DD|D/g, token => replacements[token]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// 📋 Supported Formats
|
|
49
|
-
// YYYY: 4-digit year (e.g., 2026)
|
|
50
|
-
// YY: 2-digit year (e.g., 26)
|
|
51
|
-
// MMMM: Full month name (e.g., July)
|
|
52
|
-
// MMM: Short month name (e.g., Jul)
|
|
53
|
-
// MM: 2-digit padded month (e.g., 07)
|
|
54
|
-
// DD: 2-digit padded day (e.g., 09)
|
|
55
|
-
// D: Unpadded day (e.g., 9)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// // let a = new Date()
|
|
60
|
-
// // let a = "2026-11-1"
|
|
61
|
-
// let a = new Date().getTime()
|
|
62
|
-
// let b = formatDate(a, "YYYY/DD-MMMM")
|
|
63
|
-
// console.log(b)
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export function fillDates(bounds_t, format) {
|
|
69
|
-
const result = [];
|
|
70
|
-
|
|
71
|
-
let step;
|
|
72
|
-
if (format.includes("D"))
|
|
73
|
-
step = "day";
|
|
74
|
-
else if (format.includes("M"))
|
|
75
|
-
step = "month";
|
|
76
|
-
else
|
|
77
|
-
step = "year";
|
|
78
|
-
|
|
79
|
-
let bounds = { ...bounds_t, from: new Date(bounds_t.from), to: new Date(bounds_t.to) }
|
|
80
|
-
|
|
81
|
-
bounds = getNormalizedBounds(bounds, "date", step)
|
|
82
|
-
|
|
83
|
-
while (bounds.from <= bounds.to) {
|
|
84
|
-
result.push(formatDate(bounds.from, format));
|
|
85
|
-
|
|
86
|
-
switch (step) {
|
|
87
|
-
case "day":
|
|
88
|
-
bounds.from.setDate(bounds.from.getDate() + 1);
|
|
89
|
-
break;
|
|
90
|
-
case "month":
|
|
91
|
-
bounds.from.setMonth(bounds.from.getMonth() + 1);
|
|
92
|
-
break;
|
|
93
|
-
case "year":
|
|
94
|
-
bounds.from.setFullYear(bounds.from.getFullYear() + 1);
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return [...new Set(result)];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
File without changes
|
/package/libs/{cpp.js → cpp.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|