nhb-toolbox 4.10.95 → 4.10.97
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/dist/chronos.js +32 -28
- package/dist/chronos.js.map +1 -1
- package/dist/chronos.mjs +9 -5
- package/dist/chronos.mjs.map +1 -1
- package/dist/{chunk-1.js → chunk-nhb.js} +96 -28
- package/dist/chunk-nhb.js.map +1 -0
- package/dist/{chunk-1.mjs → chunk-nhb.mjs} +96 -29
- package/dist/chunk-nhb.mjs.map +1 -0
- package/dist/index.js +453 -366
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +273 -186
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-1.js.map +0 -1
- package/dist/chunk-1.mjs.map +0 -1
package/dist/chronos.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNhb_js = require('./chunk-nhb.js');
|
|
4
4
|
|
|
5
5
|
// src/date/constants.ts
|
|
6
6
|
var DAYS = /* @__PURE__ */ Object.freeze([
|
|
@@ -448,6 +448,9 @@ var ZODIAC_SIGNS = /* @__PURE__ */ Object.freeze([
|
|
|
448
448
|
|
|
449
449
|
// src/date/Chronos.ts
|
|
450
450
|
var Chronos = class _Chronos {
|
|
451
|
+
static {
|
|
452
|
+
chunkNhb_js.__name(this, "Chronos");
|
|
453
|
+
}
|
|
451
454
|
#date;
|
|
452
455
|
#offset;
|
|
453
456
|
#ORIGIN;
|
|
@@ -646,7 +649,7 @@ var Chronos = class _Chronos {
|
|
|
646
649
|
ddd: DAYS[day],
|
|
647
650
|
D: String(date),
|
|
648
651
|
DD: String(date).padStart(2, "0"),
|
|
649
|
-
Do:
|
|
652
|
+
Do: chunkNhb_js.getOrdinal(date),
|
|
650
653
|
H: String(hours),
|
|
651
654
|
HH: String(hours).padStart(2, "0"),
|
|
652
655
|
h: String(hours % 12 || 12),
|
|
@@ -686,7 +689,7 @@ var Chronos = class _Chronos {
|
|
|
686
689
|
}
|
|
687
690
|
/** @private Returns ISO string with local time zone offset */
|
|
688
691
|
#toLocalISOString() {
|
|
689
|
-
const pad = (n, p = 2) => String(n).padStart(p, "0");
|
|
692
|
+
const pad = /* @__PURE__ */ chunkNhb_js.__name((n, p = 2) => String(n).padStart(p, "0"), "pad");
|
|
690
693
|
return `${this.year}-${pad(this.month + 1)}-${pad(this.date)}T${pad(this.hour)}:${pad(this.minute)}:${pad(this.second)}.${pad(this.millisecond, 3)}${this.getUTCOffset()}`;
|
|
691
694
|
}
|
|
692
695
|
/**
|
|
@@ -977,12 +980,12 @@ var Chronos = class _Chronos {
|
|
|
977
980
|
timeZone(zone) {
|
|
978
981
|
let targetOffset;
|
|
979
982
|
let stringOffset;
|
|
980
|
-
if (
|
|
981
|
-
targetOffset =
|
|
983
|
+
if (chunkNhb_js.isValidUTCOffSet(zone)) {
|
|
984
|
+
targetOffset = chunkNhb_js.extractMinutesFromUTC(zone);
|
|
982
985
|
stringOffset = zone;
|
|
983
986
|
} else {
|
|
984
987
|
targetOffset = TIME_ZONES[zone] ?? TIME_ZONES["UTC"];
|
|
985
|
-
stringOffset =
|
|
988
|
+
stringOffset = chunkNhb_js.formatUTCOffset(targetOffset);
|
|
986
989
|
}
|
|
987
990
|
const previousOffset = this.getTimeZoneOffsetMinutes();
|
|
988
991
|
const relativeOffset = targetOffset - previousOffset;
|
|
@@ -999,7 +1002,7 @@ var Chronos = class _Chronos {
|
|
|
999
1002
|
*/
|
|
1000
1003
|
isLeapYear() {
|
|
1001
1004
|
const year = this.#date.getFullYear();
|
|
1002
|
-
return
|
|
1005
|
+
return chunkNhb_js.isLeapYear(year);
|
|
1003
1006
|
}
|
|
1004
1007
|
/** @instance Checks if the current date is today. */
|
|
1005
1008
|
isToday() {
|
|
@@ -1208,7 +1211,7 @@ var Chronos = class _Chronos {
|
|
|
1208
1211
|
isPalindromeDate(shortYear = false) {
|
|
1209
1212
|
const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
|
|
1210
1213
|
const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
|
|
1211
|
-
return
|
|
1214
|
+
return chunkNhb_js.isPalindrome(padded) || chunkNhb_js.isPalindrome(normal);
|
|
1212
1215
|
}
|
|
1213
1216
|
/**
|
|
1214
1217
|
* @instance Checks if the date is within daylight saving time (DST).
|
|
@@ -1286,25 +1289,25 @@ var Chronos = class _Chronos {
|
|
|
1286
1289
|
const lvlIdx = unitOrder.indexOf(level);
|
|
1287
1290
|
const parts = [];
|
|
1288
1291
|
if (lvlIdx >= 0 && years > 0 && lvlIdx >= unitOrder.indexOf("year")) {
|
|
1289
|
-
parts?.push(
|
|
1292
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(years, "year"));
|
|
1290
1293
|
}
|
|
1291
1294
|
if (lvlIdx >= unitOrder.indexOf("month") && months > 0) {
|
|
1292
|
-
parts?.push(
|
|
1295
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(months, "month"));
|
|
1293
1296
|
}
|
|
1294
1297
|
if (lvlIdx >= unitOrder.indexOf("week") && weeks > 0) {
|
|
1295
|
-
parts?.push(
|
|
1298
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(weeks, "week"));
|
|
1296
1299
|
}
|
|
1297
1300
|
if (lvlIdx >= unitOrder.indexOf("day") && days > 0) {
|
|
1298
|
-
parts?.push(
|
|
1301
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(days, "day"));
|
|
1299
1302
|
}
|
|
1300
1303
|
if (lvlIdx >= unitOrder.indexOf("hour") && hours > 0) {
|
|
1301
|
-
parts?.push(
|
|
1304
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(hours, "hour"));
|
|
1302
1305
|
}
|
|
1303
1306
|
if (lvlIdx >= unitOrder.indexOf("minute") && minutes > 0) {
|
|
1304
|
-
parts?.push(
|
|
1307
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(minutes, "minute"));
|
|
1305
1308
|
}
|
|
1306
1309
|
if (lvlIdx >= unitOrder.indexOf("second") && (seconds > 0 || parts?.length === 0)) {
|
|
1307
|
-
parts?.push(
|
|
1310
|
+
parts?.push(chunkNhb_js.formatUnitWithPlural(seconds, "second"));
|
|
1308
1311
|
}
|
|
1309
1312
|
let prefix = "";
|
|
1310
1313
|
let suffix = "";
|
|
@@ -1872,7 +1875,7 @@ var Chronos = class _Chronos {
|
|
|
1872
1875
|
getUTCOffset() {
|
|
1873
1876
|
const offset = -this.#date.getTimezoneOffset();
|
|
1874
1877
|
const sign = offset >= 0 ? "+" : "-";
|
|
1875
|
-
const pad = (n) => String(Math.floor(Math.abs(n))).padStart(2, "0");
|
|
1878
|
+
const pad = /* @__PURE__ */ chunkNhb_js.__name((n) => String(Math.floor(Math.abs(n))).padStart(2, "0"), "pad");
|
|
1876
1879
|
return `${sign}${pad(offset / 60)}:${pad(offset % 60)}`;
|
|
1877
1880
|
}
|
|
1878
1881
|
/**
|
|
@@ -1906,7 +1909,7 @@ var Chronos = class _Chronos {
|
|
|
1906
1909
|
* @returns The UTC offset in minutes maintaining the current timezone regardless of system having different one.
|
|
1907
1910
|
*/
|
|
1908
1911
|
getTimeZoneOffsetMinutes() {
|
|
1909
|
-
return
|
|
1912
|
+
return chunkNhb_js.extractMinutesFromUTC(this.#offset);
|
|
1910
1913
|
}
|
|
1911
1914
|
/** @instance Returns new Chronos instance in UTC */
|
|
1912
1915
|
toUTC() {
|
|
@@ -2036,31 +2039,31 @@ var Chronos = class _Chronos {
|
|
|
2036
2039
|
const date = new Date(this.#date);
|
|
2037
2040
|
switch (unit) {
|
|
2038
2041
|
case "millisecond": {
|
|
2039
|
-
const rounded =
|
|
2042
|
+
const rounded = chunkNhb_js.roundToNearest(date.getMilliseconds(), nearest);
|
|
2040
2043
|
date.setMilliseconds(rounded);
|
|
2041
2044
|
break;
|
|
2042
2045
|
}
|
|
2043
2046
|
case "second": {
|
|
2044
2047
|
const fullSecond = date.getSeconds() + date.getMilliseconds() / 1e3;
|
|
2045
|
-
const rounded =
|
|
2048
|
+
const rounded = chunkNhb_js.roundToNearest(fullSecond, nearest);
|
|
2046
2049
|
date.setSeconds(rounded, 0);
|
|
2047
2050
|
break;
|
|
2048
2051
|
}
|
|
2049
2052
|
case "minute": {
|
|
2050
2053
|
const fullMinute = date.getMinutes() + date.getSeconds() / 60 + date.getMilliseconds() / 6e4;
|
|
2051
|
-
const rounded =
|
|
2054
|
+
const rounded = chunkNhb_js.roundToNearest(fullMinute, nearest);
|
|
2052
2055
|
date.setMinutes(rounded, 0, 0);
|
|
2053
2056
|
break;
|
|
2054
2057
|
}
|
|
2055
2058
|
case "hour": {
|
|
2056
2059
|
const fullHour = date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600 + date.getMilliseconds() / 36e5;
|
|
2057
|
-
const rounded =
|
|
2060
|
+
const rounded = chunkNhb_js.roundToNearest(fullHour, nearest);
|
|
2058
2061
|
date.setHours(rounded, 0, 0, 0);
|
|
2059
2062
|
break;
|
|
2060
2063
|
}
|
|
2061
2064
|
case "day": {
|
|
2062
2065
|
const fullDay = date.getDate() + (date.getHours() / 24 + date.getMinutes() / 1440 + date.getSeconds() / 86400 + date.getMilliseconds() / 864e5);
|
|
2063
|
-
const rounded =
|
|
2066
|
+
const rounded = chunkNhb_js.roundToNearest(fullDay, nearest);
|
|
2064
2067
|
date.setDate(rounded);
|
|
2065
2068
|
date.setHours(0, 0, 0, 0);
|
|
2066
2069
|
break;
|
|
@@ -2084,7 +2087,7 @@ var Chronos = class _Chronos {
|
|
|
2084
2087
|
}
|
|
2085
2088
|
case "month": {
|
|
2086
2089
|
const fullMonth = date.getMonth() + date.getDate() / this.lastDateOfMonth;
|
|
2087
|
-
const roundedMonth =
|
|
2090
|
+
const roundedMonth = chunkNhb_js.roundToNearest(fullMonth, nearest);
|
|
2088
2091
|
date.setMonth(roundedMonth, 1);
|
|
2089
2092
|
date.setHours(0, 0, 0, 0);
|
|
2090
2093
|
break;
|
|
@@ -2096,7 +2099,7 @@ var Chronos = class _Chronos {
|
|
|
2096
2099
|
const isLeap = new Date(date.getFullYear(), 1, 29).getDate() === 29;
|
|
2097
2100
|
const totalDays = isLeap ? 366 : 365;
|
|
2098
2101
|
const fullYear = date.getFullYear() + dayOfYear / totalDays;
|
|
2099
|
-
const roundedYear =
|
|
2102
|
+
const roundedYear = chunkNhb_js.roundToNearest(fullYear, nearest);
|
|
2100
2103
|
date.setFullYear(roundedYear, 0, 1);
|
|
2101
2104
|
date.setHours(0, 0, 0, 0);
|
|
2102
2105
|
break;
|
|
@@ -2243,6 +2246,7 @@ var Chronos = class _Chronos {
|
|
|
2243
2246
|
function normalizeOffset(timeStr) {
|
|
2244
2247
|
return timeStr.replace(/([+-]\d{2})(?!:)/, "$1:00");
|
|
2245
2248
|
}
|
|
2249
|
+
chunkNhb_js.__name(normalizeOffset, "normalizeOffset");
|
|
2246
2250
|
const timeWithDate = `${new _Chronos().#format("YYYY-MM-DD")}T${normalizeOffset(
|
|
2247
2251
|
time
|
|
2248
2252
|
)}`;
|
|
@@ -2292,7 +2296,7 @@ var Chronos = class _Chronos {
|
|
|
2292
2296
|
} else {
|
|
2293
2297
|
year = date instanceof _Chronos ? date.year : new _Chronos(date).year;
|
|
2294
2298
|
}
|
|
2295
|
-
return
|
|
2299
|
+
return chunkNhb_js.isLeapYear(year);
|
|
2296
2300
|
}
|
|
2297
2301
|
/**
|
|
2298
2302
|
* @static Checks if the given value is a valid `Date` object.
|
|
@@ -2312,7 +2316,7 @@ var Chronos = class _Chronos {
|
|
|
2312
2316
|
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
2313
2317
|
*/
|
|
2314
2318
|
static isDateString(value) {
|
|
2315
|
-
return
|
|
2319
|
+
return chunkNhb_js.isString(value) && !isNaN(Date.parse(value));
|
|
2316
2320
|
}
|
|
2317
2321
|
/**
|
|
2318
2322
|
* @static Checks if the given value is an instance of `Chronos`.
|
|
@@ -2326,7 +2330,7 @@ var Chronos = class _Chronos {
|
|
|
2326
2330
|
};
|
|
2327
2331
|
|
|
2328
2332
|
// src/date/chronos-fn.ts
|
|
2329
|
-
var chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
2333
|
+
var chronos = /* @__PURE__ */ chunkNhb_js.__name((valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
2330
2334
|
let newChronos;
|
|
2331
2335
|
if (typeof valueOrYear === "number" && typeof month === "number") {
|
|
2332
2336
|
newChronos = new Chronos(
|
|
@@ -2342,7 +2346,7 @@ var chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
|
2342
2346
|
newChronos = /* @__PURE__ */ new Chronos(valueOrYear);
|
|
2343
2347
|
}
|
|
2344
2348
|
return newChronos;
|
|
2345
|
-
};
|
|
2349
|
+
}, "chronos");
|
|
2346
2350
|
var typedChronos = chronos;
|
|
2347
2351
|
typedChronos.now = Chronos.now;
|
|
2348
2352
|
typedChronos.min = Chronos.min;
|