chronos-date 1.0.2 → 1.1.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.
Files changed (76) hide show
  1. package/dist/basic-DIp_pxR2.cjs +450 -0
  2. package/dist/basic-Dputob9z.mjs +366 -0
  3. package/dist/constants.cjs +27 -1
  4. package/dist/constants.mjs +5 -1
  5. package/dist/convert-CNVL-mop.mjs +22 -0
  6. package/dist/convert-dQuGWhVm.cjs +33 -0
  7. package/dist/greet-B8ZtypgG.cjs +40 -0
  8. package/dist/greet-B9j4afzD.mjs +35 -0
  9. package/dist/guards.cjs +119 -1
  10. package/dist/guards.mjs +110 -1
  11. package/dist/helpers-CrMc9iJZ.mjs +185 -0
  12. package/dist/helpers-M_SfAbAv.cjs +262 -0
  13. package/dist/index.cjs +1461 -1
  14. package/dist/index.mjs +1458 -1
  15. package/dist/non-primitives-CT4vszrX.cjs +52 -0
  16. package/dist/non-primitives-DrQfPj1r.mjs +22 -0
  17. package/dist/plugins/banglaPlugin.cjs +121 -1
  18. package/dist/plugins/banglaPlugin.mjs +120 -1
  19. package/dist/plugins/businessPlugin.cjs +118 -1
  20. package/dist/plugins/businessPlugin.mjs +117 -1
  21. package/dist/plugins/dateRangePlugin.cjs +46 -1
  22. package/dist/plugins/dateRangePlugin.mjs +45 -1
  23. package/dist/plugins/dayPartPlugin.cjs +26 -1
  24. package/dist/plugins/dayPartPlugin.mjs +25 -1
  25. package/dist/plugins/durationPlugin.cjs +91 -1
  26. package/dist/plugins/durationPlugin.mjs +90 -1
  27. package/dist/plugins/fromNowPlugin.cjs +80 -1
  28. package/dist/plugins/fromNowPlugin.mjs +79 -1
  29. package/dist/plugins/greetingPlugin.cjs +19 -1
  30. package/dist/plugins/greetingPlugin.mjs +18 -1
  31. package/dist/plugins/palindromePlugin.cjs +22 -1
  32. package/dist/plugins/palindromePlugin.mjs +21 -1
  33. package/dist/plugins/relativeTimePlugin.cjs +74 -1
  34. package/dist/plugins/relativeTimePlugin.mjs +73 -1
  35. package/dist/plugins/roundPlugin.cjs +69 -1
  36. package/dist/plugins/roundPlugin.mjs +68 -1
  37. package/dist/plugins/seasonPlugin.cjs +31 -1
  38. package/dist/plugins/seasonPlugin.mjs +30 -1
  39. package/dist/plugins/timeZonePlugin.cjs +139 -1
  40. package/dist/plugins/timeZonePlugin.mjs +138 -1
  41. package/dist/plugins/zodiacPlugin.cjs +51 -1
  42. package/dist/plugins/zodiacPlugin.mjs +50 -1
  43. package/dist/primitives-BME3_QrA.cjs +49 -0
  44. package/dist/primitives-DEt6I7Sy.mjs +19 -0
  45. package/dist/seasons-CHnjrIKK.mjs +352 -0
  46. package/dist/seasons-CcZicoe1.cjs +418 -0
  47. package/dist/timezone-BfBXeMK_.mjs +5573 -0
  48. package/dist/timezone-DYVJJYKz.cjs +5609 -0
  49. package/dist/types.mjs +1 -1
  50. package/dist/utilities-BU4MSYS7.mjs +43 -0
  51. package/dist/utilities-CGL7F6R9.cjs +72 -0
  52. package/dist/utilities-CtOZhIYv.mjs +241 -0
  53. package/dist/utilities-bXwTPJaD.cjs +318 -0
  54. package/dist/utils.cjs +76 -1
  55. package/dist/utils.mjs +44 -1
  56. package/package.json +1 -1
  57. package/dist/basic-CKxaRSHQ.cjs +0 -1
  58. package/dist/basic-e46DaNAi.mjs +0 -1
  59. package/dist/convert-Bmp63ats.mjs +0 -1
  60. package/dist/convert-DrLrcgqz.cjs +0 -1
  61. package/dist/greet-BBsrvmkn.mjs +0 -1
  62. package/dist/greet-C-6mruI9.cjs +0 -1
  63. package/dist/helpers-DGzYnP81.cjs +0 -1
  64. package/dist/helpers-N1X_Rj_V.mjs +0 -1
  65. package/dist/non-primitives-B2EE6D6s.mjs +0 -1
  66. package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
  67. package/dist/primitives-Cxss_JVF.mjs +0 -1
  68. package/dist/primitives-Db2FUp4e.cjs +0 -1
  69. package/dist/seasons-ChAIVphi.mjs +0 -1
  70. package/dist/seasons-oABOhHcX.cjs +0 -1
  71. package/dist/timezone-B10UItNO.mjs +0 -1
  72. package/dist/timezone-CWxbK_7I.cjs +0 -1
  73. package/dist/utilities-B8dOAQVD.cjs +0 -1
  74. package/dist/utilities-BJE06bms.mjs +0 -1
  75. package/dist/utilities-D2-p26DX.cjs +0 -1
  76. package/dist/utilities-DV_ohS37.mjs +0 -1
@@ -1 +1,45 @@
1
- import{o as e,s as t,u as n}from"../basic-e46DaNAi.mjs";import{r}from"../primitives-Cxss_JVF.mjs";import{a as i}from"../non-primitives-B2EE6D6s.mjs";const a=a=>{let{internalDate:o,cast:s,withOrigin:c,offset:l}=a[t];a.prototype.getDatesInRange=function(t){let u=this.clone(),d=this.addWeeks(4),{format:f=`local`,onlyDays:p,skipDays:m,roundDate:h=!1}=t??{};if(t){if(`from`in t||`to`in t)t?.from&&(u=s(t.from)),t?.to&&(d=s(t.to));else if(`span`in t||`unit`in t){let{span:e=4,unit:n=`week`}=t;d=u.add(e,n)}}h&&(u=u.startOf(`day`),d=d.startOf(`day`));let g=i(p)?p:i(m)?m:[],_=new Set(g.map(t=>r(t)?t:e.indexOf(t))),v=[],y=o(u).getTime(),b=o(d).getTime(),x=(y<=b?1:-1)*n,S=Math.floor(Math.abs(b-y)/n);for(let e=0;e<=S;e++){let t=y+e*x,n=new Date(t).getDay();if(i(p)?_.has(n):!_.has(n)){let e=c(new a(t),`clone`,l(this),u.timeZoneName,u.timeZoneId,u.$tzTracker);v.push(f===`local`?e.toLocalISOString():e.toISOString())}}return v}};export{a as dateRangePlugin};
1
+ import { o as DAYS, s as INTERNALS, u as MS_PER_DAY } from "../basic-Dputob9z.mjs";
2
+ import { r as isNumber } from "../primitives-DEt6I7Sy.mjs";
3
+ import { a as isValidArray } from "../non-primitives-DrQfPj1r.mjs";
4
+
5
+ //#region src/plugins/dateRangePlugin.ts
6
+ /** * Plugin to inject `getDatesInRange` related method */
7
+ const dateRangePlugin = ($Chronos) => {
8
+ const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[INTERNALS];
9
+ $Chronos.prototype.getDatesInRange = function(options) {
10
+ let startDate = this.clone(), endDate = this.addWeeks(4);
11
+ const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
12
+ if (options) {
13
+ if ("from" in options || "to" in options) {
14
+ if (options?.from) startDate = cast(options.from);
15
+ if (options?.to) endDate = cast(options.to);
16
+ } else if ("span" in options || "unit" in options) {
17
+ const { span = 4, unit = "week" } = options;
18
+ endDate = startDate.add(span, unit);
19
+ }
20
+ }
21
+ if (roundDate) {
22
+ startDate = startDate.startOf("day");
23
+ endDate = endDate.startOf("day");
24
+ }
25
+ const skippedDays = isValidArray(onlyDays) ? onlyDays : isValidArray(skipDays) ? skipDays : [];
26
+ const skipSet = new Set(skippedDays.map((day) => isNumber(day) ? day : DAYS.indexOf(day)));
27
+ const dates = [];
28
+ const startTime = $Date(startDate).getTime();
29
+ const endTime = $Date(endDate).getTime();
30
+ const step = (startTime <= endTime ? 1 : -1) * MS_PER_DAY;
31
+ const totalDays = Math.floor(Math.abs(endTime - startTime) / MS_PER_DAY);
32
+ for (let i = 0; i <= totalDays; i++) {
33
+ const ts = startTime + i * step;
34
+ const wDay = new Date(ts).getDay();
35
+ if (isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
36
+ const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
37
+ dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
38
+ }
39
+ }
40
+ return dates;
41
+ };
42
+ };
43
+
44
+ //#endregion
45
+ export { dateRangePlugin };
@@ -1 +1,26 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=require(`../non-primitives-Bu3a4WL4.cjs`),n=n=>{n.prototype.getPartOfDay=function(n){let r=this.hour,i={...e.a,...t.n(n)&&n};for(let[e,[t,n]]of Object.entries(i)){let i=Number(t),a=Number(n);if(i<=a){if(r>=i&&r<=a)return e}else if(r>=i||r<=a)return e}return`night`}};exports.dayPartPlugin=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+ const require_non_primitives = require('../non-primitives-CT4vszrX.cjs');
4
+
5
+ //#region src/plugins/dayPartPlugin.ts
6
+ /** * Plugin to inject `getPartOfDay` method */
7
+ const dayPartPlugin = ($Chronos) => {
8
+ $Chronos.prototype.getPartOfDay = function(config) {
9
+ const hour = this.hour;
10
+ const ranges = {
11
+ ...require_basic.DATE_PART_RANGES,
12
+ ...require_non_primitives.isNotEmptyObject(config) && config
13
+ };
14
+ for (const [part, [start, end]] of Object.entries(ranges)) {
15
+ const from = Number(start);
16
+ const to = Number(end);
17
+ if (from <= to) {
18
+ if (hour >= from && hour <= to) return part;
19
+ } else if (hour >= from || hour <= to) return part;
20
+ }
21
+ return "night";
22
+ };
23
+ };
24
+
25
+ //#endregion
26
+ exports.dayPartPlugin = dayPartPlugin;
@@ -1 +1,25 @@
1
- import{a as e}from"../basic-e46DaNAi.mjs";import{n as t}from"../non-primitives-B2EE6D6s.mjs";const n=n=>{n.prototype.getPartOfDay=function(n){let r=this.hour,i={...e,...t(n)&&n};for(let[e,[t,n]]of Object.entries(i)){let i=Number(t),a=Number(n);if(i<=a){if(r>=i&&r<=a)return e}else if(r>=i||r<=a)return e}return`night`}};export{n as dayPartPlugin};
1
+ import { a as DATE_PART_RANGES } from "../basic-Dputob9z.mjs";
2
+ import { n as isNotEmptyObject } from "../non-primitives-DrQfPj1r.mjs";
3
+
4
+ //#region src/plugins/dayPartPlugin.ts
5
+ /** * Plugin to inject `getPartOfDay` method */
6
+ const dayPartPlugin = ($Chronos) => {
7
+ $Chronos.prototype.getPartOfDay = function(config) {
8
+ const hour = this.hour;
9
+ const ranges = {
10
+ ...DATE_PART_RANGES,
11
+ ...isNotEmptyObject(config) && config
12
+ };
13
+ for (const [part, [start, end]] of Object.entries(ranges)) {
14
+ const from = Number(start);
15
+ const to = Number(end);
16
+ if (from <= to) {
17
+ if (hour >= from && hour <= to) return part;
18
+ } else if (hour >= from || hour <= to) return part;
19
+ }
20
+ return "night";
21
+ };
22
+ };
23
+
24
+ //#endregion
25
+ export { dayPartPlugin };
@@ -1 +1,91 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=t=>{let{toNewDate:n}=t[e.s],r=(e,t,n)=>{let r=Object.entries(e),i={...e};if(!t&&!n)for(let[e,t]of r)t!==0&&(i[e]=t*-1);else if(t)for(let[e,t]of r)i[e]=Math.abs(t);return i};t.prototype.duration=function(e,t=!0){let i=this.toDate(),a=n(this,e),o=a>i,s=o?i:a,c=o?a:i,l=e=>c[`get${e}`]()-s[`get${e}`](),u=l(`FullYear`),d=l(`Month`),f=l(`Date`),p=l(`Hours`),m=l(`Minutes`),h=l(`Seconds`),g=l(`Milliseconds`);if(g<0&&(g+=1e3,h--),h<0&&(h+=60,m--),m<0&&(m+=60,p--),p<0&&(p+=24,f--),f<0){let e=new Date(c.getFullYear(),c.getMonth(),0);f+=e.getDate(),d--}return d<0&&(d+=12,u--),r({years:u,months:d,days:f,hours:p,minutes:m,seconds:h,milliseconds:g},t,o)},t.prototype.durationString=function(e){let{toTime:t,absolute:n=!0,maxUnits:r=7,separator:i=`, `,style:a=`full`,showZero:o=!1}=e??{},s=this.duration(t,n),c={years:`y`,months:`mo`,days:`d`,hours:`h`,minutes:`m`,seconds:`s`,milliseconds:`ms`},l=(e,t)=>a===`short`?`${t}${c[e]}`:`${t} ${Math.abs(t)===1?e.slice(0,-1):e}`,u=Object.entries(s).filter(([e,t])=>o||Math.abs(t)>0).slice(0,r).map(([e,t])=>l(e,t));return u.length?u.join(i):a===`short`?`0s`:`0 seconds`}};exports.durationPlugin=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+
4
+ //#region src/plugins/durationPlugin.ts
5
+ /** * Plugin to inject `duration` related methods */
6
+ const durationPlugin = ($Chronos) => {
7
+ const { toNewDate } = $Chronos[require_basic.INTERNALS];
8
+ /**
9
+ * @private Normalizes duration values based on sign and `absolute` flag.
10
+ * @param result The raw time breakdown to normalize.
11
+ * @param absolute If true, ensures all values are positive.
12
+ * @param isFuture Whether the duration was forward (true) or backward (false).
13
+ * @returns The normalized duration object.
14
+ */
15
+ const _normalizeDuration = (result, absolute, isFuture) => {
16
+ const entries = Object.entries(result);
17
+ const updated = { ...result };
18
+ if (!absolute && !isFuture) {
19
+ for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
20
+ } else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
21
+ return updated;
22
+ };
23
+ $Chronos.prototype.duration = function(toTime, absolute = true) {
24
+ const now = this.toDate();
25
+ const target = toNewDate(this, toTime);
26
+ const isFuture = target > now;
27
+ const from = isFuture ? now : target;
28
+ const to = isFuture ? target : now;
29
+ /** Get difference between `to` and `from` for specific unit */
30
+ const _getDiff = (suffix) => {
31
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
32
+ };
33
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
34
+ if (ms < 0) {
35
+ ms += 1e3;
36
+ s--;
37
+ }
38
+ if (s < 0) {
39
+ s += 60;
40
+ m--;
41
+ }
42
+ if (m < 0) {
43
+ m += 60;
44
+ h--;
45
+ }
46
+ if (h < 0) {
47
+ h += 24;
48
+ d--;
49
+ }
50
+ if (d < 0) {
51
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
52
+ d += prevMonth.getDate();
53
+ mo--;
54
+ }
55
+ if (mo < 0) {
56
+ mo += 12;
57
+ y--;
58
+ }
59
+ return _normalizeDuration({
60
+ years: y,
61
+ months: mo,
62
+ days: d,
63
+ hours: h,
64
+ minutes: m,
65
+ seconds: s,
66
+ milliseconds: ms
67
+ }, absolute, isFuture);
68
+ };
69
+ $Chronos.prototype.durationString = function(options) {
70
+ const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
71
+ const duration = this.duration(toTime, absolute);
72
+ const units = {
73
+ years: "y",
74
+ months: "mo",
75
+ days: "d",
76
+ hours: "h",
77
+ minutes: "m",
78
+ seconds: "s",
79
+ milliseconds: "ms"
80
+ };
81
+ const _formatUnit = (unit, value) => {
82
+ if (style === "short") return `${value}${units[unit]}`;
83
+ return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
84
+ };
85
+ const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
86
+ return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
87
+ };
88
+ };
89
+
90
+ //#endregion
91
+ exports.durationPlugin = durationPlugin;
@@ -1 +1,90 @@
1
- import{s as e}from"../basic-e46DaNAi.mjs";const t=t=>{let{toNewDate:n}=t[e],r=(e,t,n)=>{let r=Object.entries(e),i={...e};if(!t&&!n)for(let[e,t]of r)t!==0&&(i[e]=t*-1);else if(t)for(let[e,t]of r)i[e]=Math.abs(t);return i};t.prototype.duration=function(e,t=!0){let i=this.toDate(),a=n(this,e),o=a>i,s=o?i:a,c=o?a:i,l=e=>c[`get${e}`]()-s[`get${e}`](),u=l(`FullYear`),d=l(`Month`),f=l(`Date`),p=l(`Hours`),m=l(`Minutes`),h=l(`Seconds`),g=l(`Milliseconds`);if(g<0&&(g+=1e3,h--),h<0&&(h+=60,m--),m<0&&(m+=60,p--),p<0&&(p+=24,f--),f<0){let e=new Date(c.getFullYear(),c.getMonth(),0);f+=e.getDate(),d--}return d<0&&(d+=12,u--),r({years:u,months:d,days:f,hours:p,minutes:m,seconds:h,milliseconds:g},t,o)},t.prototype.durationString=function(e){let{toTime:t,absolute:n=!0,maxUnits:r=7,separator:i=`, `,style:a=`full`,showZero:o=!1}=e??{},s=this.duration(t,n),c={years:`y`,months:`mo`,days:`d`,hours:`h`,minutes:`m`,seconds:`s`,milliseconds:`ms`},l=(e,t)=>a===`short`?`${t}${c[e]}`:`${t} ${Math.abs(t)===1?e.slice(0,-1):e}`,u=Object.entries(s).filter(([e,t])=>o||Math.abs(t)>0).slice(0,r).map(([e,t])=>l(e,t));return u.length?u.join(i):a===`short`?`0s`:`0 seconds`}};export{t as durationPlugin};
1
+ import { s as INTERNALS } from "../basic-Dputob9z.mjs";
2
+
3
+ //#region src/plugins/durationPlugin.ts
4
+ /** * Plugin to inject `duration` related methods */
5
+ const durationPlugin = ($Chronos) => {
6
+ const { toNewDate } = $Chronos[INTERNALS];
7
+ /**
8
+ * @private Normalizes duration values based on sign and `absolute` flag.
9
+ * @param result The raw time breakdown to normalize.
10
+ * @param absolute If true, ensures all values are positive.
11
+ * @param isFuture Whether the duration was forward (true) or backward (false).
12
+ * @returns The normalized duration object.
13
+ */
14
+ const _normalizeDuration = (result, absolute, isFuture) => {
15
+ const entries = Object.entries(result);
16
+ const updated = { ...result };
17
+ if (!absolute && !isFuture) {
18
+ for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
19
+ } else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
20
+ return updated;
21
+ };
22
+ $Chronos.prototype.duration = function(toTime, absolute = true) {
23
+ const now = this.toDate();
24
+ const target = toNewDate(this, toTime);
25
+ const isFuture = target > now;
26
+ const from = isFuture ? now : target;
27
+ const to = isFuture ? target : now;
28
+ /** Get difference between `to` and `from` for specific unit */
29
+ const _getDiff = (suffix) => {
30
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
31
+ };
32
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
33
+ if (ms < 0) {
34
+ ms += 1e3;
35
+ s--;
36
+ }
37
+ if (s < 0) {
38
+ s += 60;
39
+ m--;
40
+ }
41
+ if (m < 0) {
42
+ m += 60;
43
+ h--;
44
+ }
45
+ if (h < 0) {
46
+ h += 24;
47
+ d--;
48
+ }
49
+ if (d < 0) {
50
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
51
+ d += prevMonth.getDate();
52
+ mo--;
53
+ }
54
+ if (mo < 0) {
55
+ mo += 12;
56
+ y--;
57
+ }
58
+ return _normalizeDuration({
59
+ years: y,
60
+ months: mo,
61
+ days: d,
62
+ hours: h,
63
+ minutes: m,
64
+ seconds: s,
65
+ milliseconds: ms
66
+ }, absolute, isFuture);
67
+ };
68
+ $Chronos.prototype.durationString = function(options) {
69
+ const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
70
+ const duration = this.duration(toTime, absolute);
71
+ const units = {
72
+ years: "y",
73
+ months: "mo",
74
+ days: "d",
75
+ hours: "h",
76
+ minutes: "m",
77
+ seconds: "s",
78
+ milliseconds: "ms"
79
+ };
80
+ const _formatUnit = (unit, value) => {
81
+ if (style === "short") return `${value}${units[unit]}`;
82
+ return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
83
+ };
84
+ const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
85
+ return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
86
+ };
87
+ };
88
+
89
+ //#endregion
90
+ export { durationPlugin };
@@ -1 +1,80 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=require(`../convert-DrLrcgqz.cjs`),n=n=>{let{toNewDate:r}=n[e.s];n.prototype.fromNow=function(e=`second`,n=!0,i){let a=r(this,i),o=this.toDate(),s=o>a,c=s?a:o,l=s?o:a,u=e=>l[`get${e}`]()-c[`get${e}`](),d=u(`FullYear`),f=u(`Month`),p=u(`Date`),m=u(`Hours`),h=u(`Minutes`),g=u(`Seconds`),_=u(`Milliseconds`);if(_<0&&(_+=1e3,g--),g<0&&(g+=60,h--),h<0&&(h+=60,m--),m<0&&(m+=24,p--),p<0){let e=new Date(l.getFullYear(),l.getMonth(),0);p+=e.getDate(),f--}f<0&&(f+=12,d--);let v=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],y=v.indexOf(e),b=[],x=(e,n)=>{b.push(t.t(e,n))},S=e=>y>=v.indexOf(e);d>0&&x(d,`year`),S(`month`)&&f>0&&x(f,`month`),S(`day`)&&p>0&&x(p,`day`),S(`hour`)&&m>0&&x(m,`hour`),S(`minute`)&&h>0&&x(h,`minute`),S(`second`)&&g>0&&x(g,`second`),S(`millisecond`)&&(_>0||b?.length===0)&&x(_,`millisecond`);let C=``,w=``;return n&&(s?C=`in `:w=` ago`),`${C}${b.length?b?.join(` `):`0 ${e}s`}${w}`}};exports.fromNowPlugin=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+ const require_convert = require('../convert-dQuGWhVm.cjs');
4
+
5
+ //#region src/plugins/fromNowPlugin.ts
6
+ /** * Plugin to inject `fromNow` method */
7
+ const fromNowPlugin = ($Chronos) => {
8
+ const { toNewDate } = $Chronos[require_basic.INTERNALS];
9
+ $Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
10
+ const now = toNewDate(this, time);
11
+ const target = this.toDate();
12
+ const isFuture = target > now;
13
+ const from = isFuture ? now : target;
14
+ const to = isFuture ? target : now;
15
+ /** Get difference between `to` and `from` for specific unit */
16
+ const _getDiff = (suffix) => {
17
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
18
+ };
19
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
20
+ if (ms < 0) {
21
+ ms += 1e3;
22
+ s--;
23
+ }
24
+ if (s < 0) {
25
+ s += 60;
26
+ m--;
27
+ }
28
+ if (m < 0) {
29
+ m += 60;
30
+ h--;
31
+ }
32
+ if (h < 0) {
33
+ h += 24;
34
+ d--;
35
+ }
36
+ if (d < 0) {
37
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
38
+ d += prevMonth.getDate();
39
+ mo--;
40
+ }
41
+ if (mo < 0) {
42
+ mo += 12;
43
+ y--;
44
+ }
45
+ const unitOrder = [
46
+ "year",
47
+ "month",
48
+ "day",
49
+ "hour",
50
+ "minute",
51
+ "second",
52
+ "millisecond"
53
+ ];
54
+ const lvlIdx = unitOrder.indexOf(level);
55
+ const parts = [];
56
+ /** Push value-unit string to `parts` array */
57
+ const _pushToParts = (value, unit) => {
58
+ parts.push(require_convert.formatUnitWithPlural(value, unit));
59
+ };
60
+ /** Check if a unit level is required */
61
+ const _isLevelRequired = (unit) => {
62
+ return lvlIdx >= unitOrder.indexOf(unit);
63
+ };
64
+ if (y > 0) _pushToParts(y, "year");
65
+ if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
66
+ if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
67
+ if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
68
+ if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
69
+ if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
70
+ if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
71
+ let prefix = "";
72
+ let suffix = "";
73
+ if (wSP) if (isFuture) prefix = "in ";
74
+ else suffix = " ago";
75
+ return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
76
+ };
77
+ };
78
+
79
+ //#endregion
80
+ exports.fromNowPlugin = fromNowPlugin;
@@ -1 +1,79 @@
1
- import{s as e}from"../basic-e46DaNAi.mjs";import{t}from"../convert-Bmp63ats.mjs";const n=n=>{let{toNewDate:r}=n[e];n.prototype.fromNow=function(e=`second`,n=!0,i){let a=r(this,i),o=this.toDate(),s=o>a,c=s?a:o,l=s?o:a,u=e=>l[`get${e}`]()-c[`get${e}`](),d=u(`FullYear`),f=u(`Month`),p=u(`Date`),m=u(`Hours`),h=u(`Minutes`),g=u(`Seconds`),_=u(`Milliseconds`);if(_<0&&(_+=1e3,g--),g<0&&(g+=60,h--),h<0&&(h+=60,m--),m<0&&(m+=24,p--),p<0){let e=new Date(l.getFullYear(),l.getMonth(),0);p+=e.getDate(),f--}f<0&&(f+=12,d--);let v=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],y=v.indexOf(e),b=[],x=(e,n)=>{b.push(t(e,n))},S=e=>y>=v.indexOf(e);d>0&&x(d,`year`),S(`month`)&&f>0&&x(f,`month`),S(`day`)&&p>0&&x(p,`day`),S(`hour`)&&m>0&&x(m,`hour`),S(`minute`)&&h>0&&x(h,`minute`),S(`second`)&&g>0&&x(g,`second`),S(`millisecond`)&&(_>0||b?.length===0)&&x(_,`millisecond`);let C=``,w=``;return n&&(s?C=`in `:w=` ago`),`${C}${b.length?b?.join(` `):`0 ${e}s`}${w}`}};export{n as fromNowPlugin};
1
+ import { s as INTERNALS } from "../basic-Dputob9z.mjs";
2
+ import { t as formatUnitWithPlural } from "../convert-CNVL-mop.mjs";
3
+
4
+ //#region src/plugins/fromNowPlugin.ts
5
+ /** * Plugin to inject `fromNow` method */
6
+ const fromNowPlugin = ($Chronos) => {
7
+ const { toNewDate } = $Chronos[INTERNALS];
8
+ $Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
9
+ const now = toNewDate(this, time);
10
+ const target = this.toDate();
11
+ const isFuture = target > now;
12
+ const from = isFuture ? now : target;
13
+ const to = isFuture ? target : now;
14
+ /** Get difference between `to` and `from` for specific unit */
15
+ const _getDiff = (suffix) => {
16
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
17
+ };
18
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
19
+ if (ms < 0) {
20
+ ms += 1e3;
21
+ s--;
22
+ }
23
+ if (s < 0) {
24
+ s += 60;
25
+ m--;
26
+ }
27
+ if (m < 0) {
28
+ m += 60;
29
+ h--;
30
+ }
31
+ if (h < 0) {
32
+ h += 24;
33
+ d--;
34
+ }
35
+ if (d < 0) {
36
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
37
+ d += prevMonth.getDate();
38
+ mo--;
39
+ }
40
+ if (mo < 0) {
41
+ mo += 12;
42
+ y--;
43
+ }
44
+ const unitOrder = [
45
+ "year",
46
+ "month",
47
+ "day",
48
+ "hour",
49
+ "minute",
50
+ "second",
51
+ "millisecond"
52
+ ];
53
+ const lvlIdx = unitOrder.indexOf(level);
54
+ const parts = [];
55
+ /** Push value-unit string to `parts` array */
56
+ const _pushToParts = (value, unit) => {
57
+ parts.push(formatUnitWithPlural(value, unit));
58
+ };
59
+ /** Check if a unit level is required */
60
+ const _isLevelRequired = (unit) => {
61
+ return lvlIdx >= unitOrder.indexOf(unit);
62
+ };
63
+ if (y > 0) _pushToParts(y, "year");
64
+ if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
65
+ if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
66
+ if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
67
+ if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
68
+ if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
69
+ if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
70
+ let prefix = "";
71
+ let suffix = "";
72
+ if (wSP) if (isFuture) prefix = "in ";
73
+ else suffix = " ago";
74
+ return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
75
+ };
76
+ };
77
+
78
+ //#endregion
79
+ export { fromNowPlugin };
@@ -1 +1,19 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../greet-C-6mruI9.cjs`),t=t=>{t.prototype.getGreeting=function(t){return e.t({currentTime:this.formatStrict(`HH:mm`),...t})},t.prototype.greet=function(e){return this.getGreeting(e)}};exports.greetingPlugin=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_greet = require('../greet-B8ZtypgG.cjs');
3
+
4
+ //#region src/plugins/greetingPlugin.ts
5
+ /** * Plugin to inject `getGreeting`/`greet` method */
6
+ const greetingPlugin = ($Chronos) => {
7
+ $Chronos.prototype.getGreeting = function(configs) {
8
+ return require_greet.getGreeting({
9
+ currentTime: this.formatStrict("HH:mm"),
10
+ ...configs
11
+ });
12
+ };
13
+ $Chronos.prototype.greet = function(configs) {
14
+ return this.getGreeting(configs);
15
+ };
16
+ };
17
+
18
+ //#endregion
19
+ exports.greetingPlugin = greetingPlugin;
@@ -1 +1,18 @@
1
- import{t as e}from"../greet-BBsrvmkn.mjs";const t=t=>{t.prototype.getGreeting=function(t){return e({currentTime:this.formatStrict(`HH:mm`),...t})},t.prototype.greet=function(e){return this.getGreeting(e)}};export{t as greetingPlugin};
1
+ import { t as getGreeting } from "../greet-B9j4afzD.mjs";
2
+
3
+ //#region src/plugins/greetingPlugin.ts
4
+ /** * Plugin to inject `getGreeting`/`greet` method */
5
+ const greetingPlugin = ($Chronos) => {
6
+ $Chronos.prototype.getGreeting = function(configs) {
7
+ return getGreeting({
8
+ currentTime: this.formatStrict("HH:mm"),
9
+ ...configs
10
+ });
11
+ };
12
+ $Chronos.prototype.greet = function(configs) {
13
+ return this.getGreeting(configs);
14
+ };
15
+ };
16
+
17
+ //#endregion
18
+ export { greetingPlugin };
@@ -1 +1,22 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../convert-DrLrcgqz.cjs`),t=t=>{let n=t.toLowerCase().replace(/[^a-z0-9]/g,``);return n===e.n(n)},n=e=>{e.prototype.isPalindromeDate=function(e=!1){let n=this.formatStrict(e?`YY-MM-DD`:`YYYY-MM-DD`),r=this.formatStrict(e?`YY-M-D`:`YYYY-M-D`);return t(n)||t(r)}};exports.palindromePlugin=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_convert = require('../convert-dQuGWhVm.cjs');
3
+
4
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
5
+ const isPalindrome = (input) => {
6
+ const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
7
+ return normalized === require_convert.reverseString(normalized);
8
+ };
9
+
10
+ //#endregion
11
+ //#region src/plugins/palindromePlugin.ts
12
+ /** * Plugin to inject `isPalindromeDate` method */
13
+ const palindromePlugin = ($Chronos) => {
14
+ $Chronos.prototype.isPalindromeDate = function(shortYear = false) {
15
+ const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
16
+ const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
17
+ return isPalindrome(padded) || isPalindrome(normal);
18
+ };
19
+ };
20
+
21
+ //#endregion
22
+ exports.palindromePlugin = palindromePlugin;
@@ -1 +1,21 @@
1
- import{n as e}from"../convert-Bmp63ats.mjs";const t=t=>{let n=t.toLowerCase().replace(/[^a-z0-9]/g,``);return n===e(n)},n=e=>{e.prototype.isPalindromeDate=function(e=!1){let n=this.formatStrict(e?`YY-MM-DD`:`YYYY-MM-DD`),r=this.formatStrict(e?`YY-M-D`:`YYYY-M-D`);return t(n)||t(r)}};export{n as palindromePlugin};
1
+ import { n as reverseString } from "../convert-CNVL-mop.mjs";
2
+
3
+ //#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/string/guards.js
4
+ const isPalindrome = (input) => {
5
+ const normalized = input.toLowerCase().replace(/[^a-z0-9]/g, "");
6
+ return normalized === reverseString(normalized);
7
+ };
8
+
9
+ //#endregion
10
+ //#region src/plugins/palindromePlugin.ts
11
+ /** * Plugin to inject `isPalindromeDate` method */
12
+ const palindromePlugin = ($Chronos) => {
13
+ $Chronos.prototype.isPalindromeDate = function(shortYear = false) {
14
+ const padded = this.formatStrict(shortYear ? "YY-MM-DD" : "YYYY-MM-DD");
15
+ const normal = this.formatStrict(shortYear ? "YY-M-D" : "YYYY-M-D");
16
+ return isPalindrome(padded) || isPalindrome(normal);
17
+ };
18
+ };
19
+
20
+ //#endregion
21
+ export { palindromePlugin };
@@ -1 +1,74 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=t=>{let{toNewDate:n}=t[e.s];t.prototype.getRelativeYear=function(e){let t=this.toDate(),r=n(this,e),i=t.getFullYear()-r.getFullYear();return(r.getMonth()<t.getMonth()||r.getMonth()===t.getMonth()&&r.getDate()<t.getDate())&&i--,i},t.prototype.getRelativeMonth=function(e){let t=this.toDate(),r=n(this,e),i=(t.getFullYear()-r.getFullYear())*12+(t.getMonth()-r.getMonth());return r.getDate()<t.getDate()&&i--,i},t.prototype.getRelativeWeek=function(e){let t=this.getRelativeDay(e);return Math.floor(t/7)},t.prototype.getRelativeDay=function(e){let t=n(this,e);t.setHours(0,0,0,0);let r=new Date(this.toDate());r.setHours(0,0,0,0);let i=r.getTime()-t.getTime();return Math.floor(i/(1e3*60*60*24))},t.prototype.getRelativeHour=function(e){let t=this.getTimeStamp()-n(this,e).getTime();return Math.floor(t/(1e3*60*60))},t.prototype.getRelativeMinute=function(e){let t=this.getTimeStamp()-n(this,e).getTime();return Math.floor(t/(1e3*60))},t.prototype.getRelativeSecond=function(e){let t=this.getTimeStamp()-n(this,e).getTime();return Math.floor(t/1e3)},t.prototype.getRelativeMilliSecond=function(e){return this.getTimeStamp()-n(this,e).getTime()},t.prototype.compare=function(e=`minute`,t){switch(e){case`year`:return this.getRelativeYear(t);case`month`:return this.getRelativeMonth(t);case`day`:return this.getRelativeDay(t);case`week`:return this.getRelativeWeek(t);case`hour`:return this.getRelativeHour(t);case`minute`:return this.getRelativeMinute(t);case`second`:return this.getRelativeSecond(t);case`millisecond`:return this.getRelativeMilliSecond(t);default:throw RangeError(`Unsupported time unit: ${e}`)}},t.prototype.isToday=function(){return this.getRelativeDay()===0},t.prototype.isTomorrow=function(){return this.getRelativeDay()===1},t.prototype.isYesterday=function(){return this.getRelativeDay()===-1}};exports.relativeTimePlugin=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+
4
+ //#region src/plugins/relativeTimePlugin.ts
5
+ /** * Plugin to inject `relative time` related methods */
6
+ const relativeTimePlugin = ($Chronos) => {
7
+ const { toNewDate } = $Chronos[require_basic.INTERNALS];
8
+ $Chronos.prototype.getRelativeYear = function(time) {
9
+ const $date = this.toDate();
10
+ const now = toNewDate(this, time);
11
+ let years = $date.getFullYear() - now.getFullYear();
12
+ if (now.getMonth() < $date.getMonth() || now.getMonth() === $date.getMonth() && now.getDate() < $date.getDate()) years--;
13
+ return years;
14
+ };
15
+ $Chronos.prototype.getRelativeMonth = function(time) {
16
+ const $date = this.toDate();
17
+ const now = toNewDate(this, time);
18
+ let months = ($date.getFullYear() - now.getFullYear()) * 12 + ($date.getMonth() - now.getMonth());
19
+ if (now.getDate() < $date.getDate()) months--;
20
+ return months;
21
+ };
22
+ $Chronos.prototype.getRelativeWeek = function(time) {
23
+ const relativeDays = this.getRelativeDay(time);
24
+ return Math.floor(relativeDays / 7);
25
+ };
26
+ $Chronos.prototype.getRelativeDay = function(time) {
27
+ const now = toNewDate(this, time);
28
+ now.setHours(0, 0, 0, 0);
29
+ const $date = new Date(this.toDate());
30
+ $date.setHours(0, 0, 0, 0);
31
+ const diffTime = $date.getTime() - now.getTime();
32
+ return Math.floor(diffTime / (1e3 * 60 * 60 * 24));
33
+ };
34
+ $Chronos.prototype.getRelativeHour = function(time) {
35
+ const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
36
+ return Math.floor(diff / (1e3 * 60 * 60));
37
+ };
38
+ $Chronos.prototype.getRelativeMinute = function(time) {
39
+ const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
40
+ return Math.floor(diff / (1e3 * 60));
41
+ };
42
+ $Chronos.prototype.getRelativeSecond = function(time) {
43
+ const diff = this.getTimeStamp() - toNewDate(this, time).getTime();
44
+ return Math.floor(diff / 1e3);
45
+ };
46
+ $Chronos.prototype.getRelativeMilliSecond = function(time) {
47
+ return this.getTimeStamp() - toNewDate(this, time).getTime();
48
+ };
49
+ $Chronos.prototype.compare = function(unit = "minute", time) {
50
+ switch (unit) {
51
+ case "year": return this.getRelativeYear(time);
52
+ case "month": return this.getRelativeMonth(time);
53
+ case "day": return this.getRelativeDay(time);
54
+ case "week": return this.getRelativeWeek(time);
55
+ case "hour": return this.getRelativeHour(time);
56
+ case "minute": return this.getRelativeMinute(time);
57
+ case "second": return this.getRelativeSecond(time);
58
+ case "millisecond": return this.getRelativeMilliSecond(time);
59
+ default: throw new RangeError(`Unsupported time unit: ${unit}`);
60
+ }
61
+ };
62
+ $Chronos.prototype.isToday = function() {
63
+ return this.getRelativeDay() === 0;
64
+ };
65
+ $Chronos.prototype.isTomorrow = function() {
66
+ return this.getRelativeDay() === 1;
67
+ };
68
+ $Chronos.prototype.isYesterday = function() {
69
+ return this.getRelativeDay() === -1;
70
+ };
71
+ };
72
+
73
+ //#endregion
74
+ exports.relativeTimePlugin = relativeTimePlugin;