chronos-date 1.0.2 → 1.1.1
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/basic-DqKyujoj.mjs +382 -0
- package/dist/basic-DsQqC5nZ.cjs +466 -0
- package/dist/constants.cjs +43 -1
- package/dist/constants.d.cts +17 -1
- package/dist/constants.d.mts +17 -1
- package/dist/constants.mjs +21 -1
- package/dist/convert-DbgntRVW.cjs +49 -0
- package/dist/convert-mMaI4YP0.mjs +38 -0
- package/dist/greet-D07t2_e6.mjs +51 -0
- package/dist/greet-hjVsd2dt.cjs +56 -0
- package/dist/guards.cjs +140 -1
- package/dist/guards.d.cts +18 -2
- package/dist/guards.d.mts +18 -2
- package/dist/guards.mjs +131 -1
- package/dist/helpers-CQzi908i.cjs +278 -0
- package/dist/helpers-DEf4sevD.mjs +201 -0
- package/dist/index.cjs +1477 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +1474 -1
- package/dist/non-primitives-D9zxCwX8.cjs +68 -0
- package/dist/non-primitives-DBtomDty.mjs +38 -0
- package/dist/plugins/banglaPlugin.cjs +137 -1
- package/dist/plugins/banglaPlugin.d.cts +19 -3
- package/dist/plugins/banglaPlugin.d.mts +19 -3
- package/dist/plugins/banglaPlugin.mjs +136 -1
- package/dist/plugins/businessPlugin.cjs +134 -1
- package/dist/plugins/businessPlugin.d.cts +17 -1
- package/dist/plugins/businessPlugin.d.mts +17 -1
- package/dist/plugins/businessPlugin.mjs +133 -1
- package/dist/plugins/dateRangePlugin.cjs +62 -1
- package/dist/plugins/dateRangePlugin.d.cts +19 -3
- package/dist/plugins/dateRangePlugin.d.mts +19 -3
- package/dist/plugins/dateRangePlugin.mjs +61 -1
- package/dist/plugins/dayPartPlugin.cjs +42 -1
- package/dist/plugins/dayPartPlugin.d.cts +17 -1
- package/dist/plugins/dayPartPlugin.d.mts +17 -1
- package/dist/plugins/dayPartPlugin.mjs +41 -1
- package/dist/plugins/durationPlugin.cjs +107 -1
- package/dist/plugins/durationPlugin.d.cts +17 -1
- package/dist/plugins/durationPlugin.d.mts +17 -1
- package/dist/plugins/durationPlugin.mjs +106 -1
- package/dist/plugins/fromNowPlugin.cjs +96 -1
- package/dist/plugins/fromNowPlugin.d.cts +17 -1
- package/dist/plugins/fromNowPlugin.d.mts +17 -1
- package/dist/plugins/fromNowPlugin.mjs +95 -1
- package/dist/plugins/greetingPlugin.cjs +35 -1
- package/dist/plugins/greetingPlugin.d.cts +17 -1
- package/dist/plugins/greetingPlugin.d.mts +17 -1
- package/dist/plugins/greetingPlugin.mjs +34 -1
- package/dist/plugins/palindromePlugin.cjs +38 -1
- package/dist/plugins/palindromePlugin.d.cts +17 -1
- package/dist/plugins/palindromePlugin.d.mts +17 -1
- package/dist/plugins/palindromePlugin.mjs +37 -1
- package/dist/plugins/relativeTimePlugin.cjs +90 -1
- package/dist/plugins/relativeTimePlugin.d.cts +17 -1
- package/dist/plugins/relativeTimePlugin.d.mts +17 -1
- package/dist/plugins/relativeTimePlugin.mjs +89 -1
- package/dist/plugins/roundPlugin.cjs +85 -1
- package/dist/plugins/roundPlugin.d.cts +17 -1
- package/dist/plugins/roundPlugin.d.mts +17 -1
- package/dist/plugins/roundPlugin.mjs +84 -1
- package/dist/plugins/seasonPlugin.cjs +47 -1
- package/dist/plugins/seasonPlugin.d.cts +17 -1
- package/dist/plugins/seasonPlugin.d.mts +17 -1
- package/dist/plugins/seasonPlugin.mjs +46 -1
- package/dist/plugins/timeZonePlugin.cjs +155 -1
- package/dist/plugins/timeZonePlugin.d.cts +17 -1
- package/dist/plugins/timeZonePlugin.d.mts +17 -1
- package/dist/plugins/timeZonePlugin.mjs +154 -1
- package/dist/plugins/zodiacPlugin.cjs +67 -1
- package/dist/plugins/zodiacPlugin.d.cts +17 -1
- package/dist/plugins/zodiacPlugin.d.mts +17 -1
- package/dist/plugins/zodiacPlugin.mjs +66 -1
- package/dist/primitives-CtuSNmV7.cjs +65 -0
- package/dist/primitives-dXzXlzJw.mjs +35 -0
- package/dist/seasons-B7kK88zq.cjs +434 -0
- package/dist/{seasons-CioTH5Dm.d.mts → seasons-B_kjFWIX.d.mts} +16 -0
- package/dist/{seasons-CsVeJ27s.d.cts → seasons-CpUn45n6.d.cts} +16 -0
- package/dist/seasons-Cq3ah3pV.mjs +368 -0
- package/dist/timezone-BNnHFgki.cjs +5625 -0
- package/dist/timezone-Db2CeL32.mjs +5589 -0
- package/dist/{types-B2fgrJ86.d.mts → types-Cb4gxrgJ.d.mts} +29 -15
- package/dist/{types-DPTQ_yLx.d.cts → types-CdmsXbU_.d.cts} +29 -15
- package/dist/types.cjs +16 -0
- package/dist/types.d.cts +18 -2
- package/dist/types.d.mts +18 -2
- package/dist/types.mjs +17 -1
- package/dist/utilities-BGX8dviZ.mjs +257 -0
- package/dist/utilities-BKtVo78T.mjs +59 -0
- package/dist/utilities-CpF3uys3.cjs +88 -0
- package/dist/utilities-D47SN9EZ.cjs +334 -0
- package/dist/utils.cjs +92 -1
- package/dist/utils.d.cts +20 -4
- package/dist/utils.d.mts +20 -4
- package/dist/utils.mjs +60 -1
- package/package.json +10 -4
- package/dist/basic-CKxaRSHQ.cjs +0 -1
- package/dist/basic-e46DaNAi.mjs +0 -1
- package/dist/convert-Bmp63ats.mjs +0 -1
- package/dist/convert-DrLrcgqz.cjs +0 -1
- package/dist/greet-BBsrvmkn.mjs +0 -1
- package/dist/greet-C-6mruI9.cjs +0 -1
- package/dist/helpers-DGzYnP81.cjs +0 -1
- package/dist/helpers-N1X_Rj_V.mjs +0 -1
- package/dist/non-primitives-B2EE6D6s.mjs +0 -1
- package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
- package/dist/primitives-Cxss_JVF.mjs +0 -1
- package/dist/primitives-Db2FUp4e.cjs +0 -1
- package/dist/seasons-ChAIVphi.mjs +0 -1
- package/dist/seasons-oABOhHcX.cjs +0 -1
- package/dist/timezone-B10UItNO.mjs +0 -1
- package/dist/timezone-CWxbK_7I.cjs +0 -1
- package/dist/utilities-B8dOAQVD.cjs +0 -1
- package/dist/utilities-BJE06bms.mjs +0 -1
- package/dist/utilities-D2-p26DX.cjs +0 -1
- package/dist/utilities-DV_ohS37.mjs +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { isValidTime } from "./guards.mjs";
|
|
18
|
+
import { n as extractHourMinute, p as getTotalMinutes } from "./utilities-BGX8dviZ.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/utils/greet.ts
|
|
21
|
+
/**
|
|
22
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
23
|
+
*
|
|
24
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
25
|
+
* @returns The appropriate greeting message.
|
|
26
|
+
*/
|
|
27
|
+
function getGreeting(configs) {
|
|
28
|
+
const { morningEnds = "11:59", noonEnds = "12:59", afternoonEnds = "17:59", eveningEnds = "23:59", midnightEnds = "02:59", currentTime, appendToMsg = "", prependToMsg = "", morningMessage = "Good Morning!", noonMessage = "Good Noon!", afternoonMessage = "Good Afternoon!", eveningMessage = "Good Evening!", midnightMessage = "Hello, Night Owl!", defaultMessage = "Greetings!" } = configs || {};
|
|
29
|
+
let hour;
|
|
30
|
+
let minute;
|
|
31
|
+
if (currentTime && isValidTime(currentTime)) [hour, minute] = extractHourMinute(currentTime);
|
|
32
|
+
else {
|
|
33
|
+
const now = /* @__PURE__ */ new Date();
|
|
34
|
+
hour = now.getHours();
|
|
35
|
+
minute = now.getMinutes();
|
|
36
|
+
}
|
|
37
|
+
const currentTotalMinutes = hour * 60 + minute;
|
|
38
|
+
const morningEndMinutes = getTotalMinutes(morningEnds);
|
|
39
|
+
const noonEndMinutes = getTotalMinutes(noonEnds);
|
|
40
|
+
const afternoonEndMinutes = getTotalMinutes(afternoonEnds);
|
|
41
|
+
const eveningEndMinutes = getTotalMinutes(eveningEnds);
|
|
42
|
+
if (currentTotalMinutes <= getTotalMinutes(midnightEnds)) return prependToMsg.concat(midnightMessage.concat(appendToMsg));
|
|
43
|
+
else if (currentTotalMinutes <= morningEndMinutes) return prependToMsg.concat(morningMessage.concat(appendToMsg));
|
|
44
|
+
else if (currentTotalMinutes <= noonEndMinutes) return prependToMsg.concat(noonMessage.concat(appendToMsg));
|
|
45
|
+
else if (currentTotalMinutes <= afternoonEndMinutes) return prependToMsg.concat(afternoonMessage.concat(appendToMsg));
|
|
46
|
+
else if (currentTotalMinutes <= eveningEndMinutes) return prependToMsg.concat(eveningMessage.concat(appendToMsg));
|
|
47
|
+
else return prependToMsg.concat(defaultMessage.concat(appendToMsg));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { getGreeting as t };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const require_guards = require('./guards.cjs');
|
|
18
|
+
const require_utilities = require('./utilities-D47SN9EZ.cjs');
|
|
19
|
+
|
|
20
|
+
//#region src/utils/greet.ts
|
|
21
|
+
/**
|
|
22
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
23
|
+
*
|
|
24
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
25
|
+
* @returns The appropriate greeting message.
|
|
26
|
+
*/
|
|
27
|
+
function getGreeting(configs) {
|
|
28
|
+
const { morningEnds = "11:59", noonEnds = "12:59", afternoonEnds = "17:59", eveningEnds = "23:59", midnightEnds = "02:59", currentTime, appendToMsg = "", prependToMsg = "", morningMessage = "Good Morning!", noonMessage = "Good Noon!", afternoonMessage = "Good Afternoon!", eveningMessage = "Good Evening!", midnightMessage = "Hello, Night Owl!", defaultMessage = "Greetings!" } = configs || {};
|
|
29
|
+
let hour;
|
|
30
|
+
let minute;
|
|
31
|
+
if (currentTime && require_guards.isValidTime(currentTime)) [hour, minute] = require_utilities.extractHourMinute(currentTime);
|
|
32
|
+
else {
|
|
33
|
+
const now = /* @__PURE__ */ new Date();
|
|
34
|
+
hour = now.getHours();
|
|
35
|
+
minute = now.getMinutes();
|
|
36
|
+
}
|
|
37
|
+
const currentTotalMinutes = hour * 60 + minute;
|
|
38
|
+
const morningEndMinutes = require_utilities.getTotalMinutes(morningEnds);
|
|
39
|
+
const noonEndMinutes = require_utilities.getTotalMinutes(noonEnds);
|
|
40
|
+
const afternoonEndMinutes = require_utilities.getTotalMinutes(afternoonEnds);
|
|
41
|
+
const eveningEndMinutes = require_utilities.getTotalMinutes(eveningEnds);
|
|
42
|
+
if (currentTotalMinutes <= require_utilities.getTotalMinutes(midnightEnds)) return prependToMsg.concat(midnightMessage.concat(appendToMsg));
|
|
43
|
+
else if (currentTotalMinutes <= morningEndMinutes) return prependToMsg.concat(morningMessage.concat(appendToMsg));
|
|
44
|
+
else if (currentTotalMinutes <= noonEndMinutes) return prependToMsg.concat(noonMessage.concat(appendToMsg));
|
|
45
|
+
else if (currentTotalMinutes <= afternoonEndMinutes) return prependToMsg.concat(afternoonMessage.concat(appendToMsg));
|
|
46
|
+
else if (currentTotalMinutes <= eveningEndMinutes) return prependToMsg.concat(eveningMessage.concat(appendToMsg));
|
|
47
|
+
else return prependToMsg.concat(defaultMessage.concat(appendToMsg));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
Object.defineProperty(exports, 'getGreeting', {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return getGreeting;
|
|
55
|
+
}
|
|
56
|
+
});
|
package/dist/guards.cjs
CHANGED
|
@@ -1 +1,140 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
|
+
const require_timezone = require('./timezone-BNnHFgki.cjs');
|
|
19
|
+
const require_primitives = require('./primitives-CtuSNmV7.cjs');
|
|
20
|
+
const require_non_primitives = require('./non-primitives-D9zxCwX8.cjs');
|
|
21
|
+
const require_utilities = require('./utilities-CpF3uys3.cjs');
|
|
22
|
+
|
|
23
|
+
//#region src/guards.ts
|
|
24
|
+
/**
|
|
25
|
+
* * Type guard to check if a value is a Date object.
|
|
26
|
+
* @param value - The value to check.
|
|
27
|
+
* @returns `true` if the value is a Date object, otherwise `false`.
|
|
28
|
+
*/
|
|
29
|
+
function isDate(value) {
|
|
30
|
+
return value instanceof Date;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* * Type guard to check if a value is a valid date string.
|
|
34
|
+
* @param value - The value to check.
|
|
35
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
36
|
+
*/
|
|
37
|
+
function isDateString(value) {
|
|
38
|
+
return require_primitives.isNonEmptyString(value) && !isNaN(Date.parse(value));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* * Checks if the provided value is a valid time string in "HH:MM" format.
|
|
42
|
+
*
|
|
43
|
+
* @param value - The value to check.
|
|
44
|
+
* @returns `true` if the value is a valid time string, `false` otherwise.
|
|
45
|
+
*/
|
|
46
|
+
function isValidTime(value) {
|
|
47
|
+
if (!require_primitives.isNonEmptyString(value)) return false;
|
|
48
|
+
const [hourStr, minuteStr] = value.split(":");
|
|
49
|
+
if (!require_utilities.isNumericString(hourStr) || !require_utilities.isNumericString(minuteStr)) return false;
|
|
50
|
+
const hour = Number(hourStr);
|
|
51
|
+
const minute = Number(minuteStr);
|
|
52
|
+
return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* * Checks if the provided value is a valid `UTCOffset` (e.g. `UTC-01:30`).
|
|
56
|
+
*
|
|
57
|
+
* @param value - The value to check.
|
|
58
|
+
* @returns `true` if the value is a valid utc offset, `false` otherwise.
|
|
59
|
+
*/
|
|
60
|
+
function isValidUTCOffset(value) {
|
|
61
|
+
return require_primitives.isNonEmptyString(value) ? /^UTC[+-]?\d{1,2}:\d{2}$/.test(value) : false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* * Validates whether the provided value is a recognized IANA time zone identifier (excluding `"Factory"`), based on the {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* - Relies on a large constant map of time zone identifiers, which can increase bundle size in browser environments. Matches against `597` identifiers.
|
|
68
|
+
* - Prefer {@link isNativeTimeZoneId} when you want a lightweight, native-only validation approach. Matches against `418` identifiers.
|
|
69
|
+
*
|
|
70
|
+
* @param value Time zone identifier to validate.
|
|
71
|
+
* @returns `true` if the value is a valid IANA time zone identifier, otherwise `false`.
|
|
72
|
+
*/
|
|
73
|
+
function isValidTimeZoneId(value) {
|
|
74
|
+
return require_primitives.isNonEmptyString(value) ? new Set([...require_timezone.IANA_TZ_IDS]).has(value) : false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* * Validates whether the provided value is a supported time zone identifier using the native JavaScript API (`Intl.supportedValuesOf('timeZone')`).
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* - Uses only native {@link Intl} capabilities—minimal code footprint, highly performant. Matches against `418` identifiers.
|
|
81
|
+
* - Prefer {@link isValidTimeZoneId} when validation must align strictly with the full
|
|
82
|
+
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}. Matches against `597` identifiers.
|
|
83
|
+
*
|
|
84
|
+
* @param value Time zone identifier to validate.
|
|
85
|
+
* @returns `true` if the value is a valid native JS-supported time zone identifier, otherwise `false`.
|
|
86
|
+
*/
|
|
87
|
+
function isNativeTimeZoneId(value) {
|
|
88
|
+
return require_primitives.isNonEmptyString(value) ? new Set(require_timezone.NATIVE_TZ_IDS).has(value) : false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* * Checks if the year is a leap year.
|
|
92
|
+
*
|
|
93
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
94
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
95
|
+
* @param year The year to check.
|
|
96
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
97
|
+
*/
|
|
98
|
+
function isLeapYear(year) {
|
|
99
|
+
const $year = require_utilities.normalizeNumber(year);
|
|
100
|
+
return $year ? $year % 4 === 0 && $year % 100 !== 0 || $year % 400 === 0 : false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* * Checks if a value is a date-like object from `Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, or `Temporal`
|
|
104
|
+
* @param value Value to check if it is date-like object.
|
|
105
|
+
* @returns `true` if the value is date-like object, otherwise `false`.
|
|
106
|
+
*/
|
|
107
|
+
function isDateLike(value) {
|
|
108
|
+
if (value instanceof Date) return true;
|
|
109
|
+
if (require_non_primitives.isObject(value)) {
|
|
110
|
+
if (require_non_primitives.isFunction(value?.format) && require_non_primitives.isFunction(value?.toJSON) && require_non_primitives.isFunction(value?.toISOString)) return true;
|
|
111
|
+
if (require_non_primitives.isFunction(value?.toISO) && require_non_primitives.isFunction(value?.toFormat) && require_primitives.isBoolean(value?.isValid)) return true;
|
|
112
|
+
if (require_non_primitives.isFunction(value?.plus) && require_non_primitives.isFunction(value?.minus) && require_non_primitives.isFunction(value?.equals) && require_non_primitives.isFunction(value?.getClass)) return true;
|
|
113
|
+
if (require_non_primitives.isFunction(value?.toJSON) && require_non_primitives.isFunction(value?.toString) && [
|
|
114
|
+
"Instant",
|
|
115
|
+
"Duration",
|
|
116
|
+
"PlainDate",
|
|
117
|
+
"PlainTime",
|
|
118
|
+
"PlainDateTime",
|
|
119
|
+
"PlainMonthDay",
|
|
120
|
+
"PlainYearMonth",
|
|
121
|
+
"ZonedDateTime"
|
|
122
|
+
].includes(value?.constructor?.name)) return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
/** Checks if a value represents time value (number) with different forms of {@link TimeWithUnit units} */
|
|
127
|
+
function isTimeWithUnit(value) {
|
|
128
|
+
return require_primitives.isNonEmptyString(value) && /^-?\d*\.?\d+ *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.test(value);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
exports.isDate = isDate;
|
|
133
|
+
exports.isDateLike = isDateLike;
|
|
134
|
+
exports.isDateString = isDateString;
|
|
135
|
+
exports.isLeapYear = isLeapYear;
|
|
136
|
+
exports.isNativeTimeZoneId = isNativeTimeZoneId;
|
|
137
|
+
exports.isTimeWithUnit = isTimeWithUnit;
|
|
138
|
+
exports.isValidTime = isValidTime;
|
|
139
|
+
exports.isValidTimeZoneId = isValidTimeZoneId;
|
|
140
|
+
exports.isValidUTCOffset = isValidUTCOffset;
|
package/dist/guards.d.cts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Dt as TimeWithUnit, Lt as UTCOffset, Sn as Numeric, X as $TimeZoneIdentifier, jt as TimeZoneIdNative, ot as DateLike, rt as ClockTime } from "./types-CdmsXbU_.cjs";
|
|
2
18
|
|
|
3
19
|
//#region src/guards.d.ts
|
|
4
20
|
/**
|
|
@@ -64,7 +80,7 @@ declare function isLeapYear(year: Numeric): boolean;
|
|
|
64
80
|
* @param value Value to check if it is date-like object.
|
|
65
81
|
* @returns `true` if the value is date-like object, otherwise `false`.
|
|
66
82
|
*/
|
|
67
|
-
declare function isDateLike(value: unknown):
|
|
83
|
+
declare function isDateLike(value: unknown): value is DateLike;
|
|
68
84
|
/** Checks if a value represents time value (number) with different forms of {@link TimeWithUnit units} */
|
|
69
85
|
declare function isTimeWithUnit(value: unknown): value is TimeWithUnit;
|
|
70
86
|
//#endregion
|
package/dist/guards.d.mts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Dt as TimeWithUnit, Lt as UTCOffset, Sn as Numeric, X as $TimeZoneIdentifier, jt as TimeZoneIdNative, ot as DateLike, rt as ClockTime } from "./types-Cb4gxrgJ.mjs";
|
|
2
18
|
|
|
3
19
|
//#region src/guards.d.ts
|
|
4
20
|
/**
|
|
@@ -64,7 +80,7 @@ declare function isLeapYear(year: Numeric): boolean;
|
|
|
64
80
|
* @param value Value to check if it is date-like object.
|
|
65
81
|
* @returns `true` if the value is date-like object, otherwise `false`.
|
|
66
82
|
*/
|
|
67
|
-
declare function isDateLike(value: unknown):
|
|
83
|
+
declare function isDateLike(value: unknown): value is DateLike;
|
|
68
84
|
/** Checks if a value represents time value (number) with different forms of {@link TimeWithUnit units} */
|
|
69
85
|
declare function isTimeWithUnit(value: unknown): value is TimeWithUnit;
|
|
70
86
|
//#endregion
|
package/dist/guards.mjs
CHANGED
|
@@ -1 +1,131 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { n as NATIVE_TZ_IDS, t as IANA_TZ_IDS } from "./timezone-Db2CeL32.mjs";
|
|
18
|
+
import { n as isNonEmptyString, t as isBoolean } from "./primitives-dXzXlzJw.mjs";
|
|
19
|
+
import { r as isObject, t as isFunction } from "./non-primitives-DBtomDty.mjs";
|
|
20
|
+
import { a as isNumericString, n as normalizeNumber } from "./utilities-BKtVo78T.mjs";
|
|
21
|
+
|
|
22
|
+
//#region src/guards.ts
|
|
23
|
+
/**
|
|
24
|
+
* * Type guard to check if a value is a Date object.
|
|
25
|
+
* @param value - The value to check.
|
|
26
|
+
* @returns `true` if the value is a Date object, otherwise `false`.
|
|
27
|
+
*/
|
|
28
|
+
function isDate(value) {
|
|
29
|
+
return value instanceof Date;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* * Type guard to check if a value is a valid date string.
|
|
33
|
+
* @param value - The value to check.
|
|
34
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
35
|
+
*/
|
|
36
|
+
function isDateString(value) {
|
|
37
|
+
return isNonEmptyString(value) && !isNaN(Date.parse(value));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* * Checks if the provided value is a valid time string in "HH:MM" format.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to check.
|
|
43
|
+
* @returns `true` if the value is a valid time string, `false` otherwise.
|
|
44
|
+
*/
|
|
45
|
+
function isValidTime(value) {
|
|
46
|
+
if (!isNonEmptyString(value)) return false;
|
|
47
|
+
const [hourStr, minuteStr] = value.split(":");
|
|
48
|
+
if (!isNumericString(hourStr) || !isNumericString(minuteStr)) return false;
|
|
49
|
+
const hour = Number(hourStr);
|
|
50
|
+
const minute = Number(minuteStr);
|
|
51
|
+
return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* * Checks if the provided value is a valid `UTCOffset` (e.g. `UTC-01:30`).
|
|
55
|
+
*
|
|
56
|
+
* @param value - The value to check.
|
|
57
|
+
* @returns `true` if the value is a valid utc offset, `false` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
function isValidUTCOffset(value) {
|
|
60
|
+
return isNonEmptyString(value) ? /^UTC[+-]?\d{1,2}:\d{2}$/.test(value) : false;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* * Validates whether the provided value is a recognized IANA time zone identifier (excluding `"Factory"`), based on the {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* - Relies on a large constant map of time zone identifiers, which can increase bundle size in browser environments. Matches against `597` identifiers.
|
|
67
|
+
* - Prefer {@link isNativeTimeZoneId} when you want a lightweight, native-only validation approach. Matches against `418` identifiers.
|
|
68
|
+
*
|
|
69
|
+
* @param value Time zone identifier to validate.
|
|
70
|
+
* @returns `true` if the value is a valid IANA time zone identifier, otherwise `false`.
|
|
71
|
+
*/
|
|
72
|
+
function isValidTimeZoneId(value) {
|
|
73
|
+
return isNonEmptyString(value) ? new Set([...IANA_TZ_IDS]).has(value) : false;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* * Validates whether the provided value is a supported time zone identifier using the native JavaScript API (`Intl.supportedValuesOf('timeZone')`).
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* - Uses only native {@link Intl} capabilities—minimal code footprint, highly performant. Matches against `418` identifiers.
|
|
80
|
+
* - Prefer {@link isValidTimeZoneId} when validation must align strictly with the full
|
|
81
|
+
* {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones IANA TZ Database}. Matches against `597` identifiers.
|
|
82
|
+
*
|
|
83
|
+
* @param value Time zone identifier to validate.
|
|
84
|
+
* @returns `true` if the value is a valid native JS-supported time zone identifier, otherwise `false`.
|
|
85
|
+
*/
|
|
86
|
+
function isNativeTimeZoneId(value) {
|
|
87
|
+
return isNonEmptyString(value) ? new Set(NATIVE_TZ_IDS).has(value) : false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* * Checks if the year is a leap year.
|
|
91
|
+
*
|
|
92
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
93
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
94
|
+
* @param year The year to check.
|
|
95
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
96
|
+
*/
|
|
97
|
+
function isLeapYear(year) {
|
|
98
|
+
const $year = normalizeNumber(year);
|
|
99
|
+
return $year ? $year % 4 === 0 && $year % 100 !== 0 || $year % 400 === 0 : false;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* * Checks if a value is a date-like object from `Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, or `Temporal`
|
|
103
|
+
* @param value Value to check if it is date-like object.
|
|
104
|
+
* @returns `true` if the value is date-like object, otherwise `false`.
|
|
105
|
+
*/
|
|
106
|
+
function isDateLike(value) {
|
|
107
|
+
if (value instanceof Date) return true;
|
|
108
|
+
if (isObject(value)) {
|
|
109
|
+
if (isFunction(value?.format) && isFunction(value?.toJSON) && isFunction(value?.toISOString)) return true;
|
|
110
|
+
if (isFunction(value?.toISO) && isFunction(value?.toFormat) && isBoolean(value?.isValid)) return true;
|
|
111
|
+
if (isFunction(value?.plus) && isFunction(value?.minus) && isFunction(value?.equals) && isFunction(value?.getClass)) return true;
|
|
112
|
+
if (isFunction(value?.toJSON) && isFunction(value?.toString) && [
|
|
113
|
+
"Instant",
|
|
114
|
+
"Duration",
|
|
115
|
+
"PlainDate",
|
|
116
|
+
"PlainTime",
|
|
117
|
+
"PlainDateTime",
|
|
118
|
+
"PlainMonthDay",
|
|
119
|
+
"PlainYearMonth",
|
|
120
|
+
"ZonedDateTime"
|
|
121
|
+
].includes(value?.constructor?.name)) return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
/** Checks if a value represents time value (number) with different forms of {@link TimeWithUnit units} */
|
|
126
|
+
function isTimeWithUnit(value) {
|
|
127
|
+
return isNonEmptyString(value) && /^-?\d*\.?\d+ *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.test(value);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { isDate, isDateLike, isDateString, isLeapYear, isNativeTimeZoneId, isTimeWithUnit, isValidTime, isValidTimeZoneId, isValidUTCOffset };
|