chronos-ts 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,50 @@
1
- export { Period } from './period';
2
- export { Precision } from './precision';
3
- export { Interval } from './interval';
1
+ /**
2
+ * Chronos v2 - A comprehensive TypeScript library for date and time manipulation
3
+ *
4
+ * @description
5
+ * Chronos is a powerful, modern TypeScript library for handling dates, times,
6
+ * intervals, periods, and timezones. Inspired by Carbon PHP, it provides an
7
+ * intuitive and fluent API for all your time-related needs.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Chronos, ChronosInterval, ChronosPeriod, ChronosTimezone } from 'chronos-ts';
12
+ *
13
+ * // Create dates
14
+ * const now = Chronos.now();
15
+ * const birthday = Chronos.create(1990, 5, 15);
16
+ *
17
+ * // Manipulate
18
+ * const nextWeek = now.addWeeks(1);
19
+ * const endOfMonth = now.endOf('month');
20
+ *
21
+ * // Compare
22
+ * if (now.isAfter(birthday)) {
23
+ * console.log('Birthday has passed');
24
+ * }
25
+ *
26
+ * // Format
27
+ * console.log(now.format('MMMM D, YYYY')); // "January 15, 2024"
28
+ *
29
+ * // Intervals
30
+ * const duration = ChronosInterval.hours(5).addMinutes(30);
31
+ * console.log(duration.forHumans()); // "5 hours 30 minutes"
32
+ *
33
+ * // Periods
34
+ * const week = ChronosPeriod.currentWeek();
35
+ * for (const day of week) {
36
+ * console.log(day.format('dddd'));
37
+ * }
38
+ *
39
+ * // Timezones
40
+ * const tz = ChronosTimezone.create('America/New_York');
41
+ * console.log(tz.getOffsetString()); // "-05:00"
42
+ * ```
43
+ *
44
+ * @packageDocumentation
45
+ */
46
+ export { Chronos, ChronosInterval, ChronosPeriod, ChronosPeriodCollection, ChronosTimezone, TIMEZONES, Timezones, type TimezoneId, } from './core';
47
+ export { DayOfWeek, Month, PeriodBoundary, type TimeUnit, type TimeUnitPlural, type TimeUnitShort, type AnyTimeUnit, type Duration, type DateInput, type ChronosLike, type ChronosConfig, type DateTimeComponents, type DateTimeSetter, type ISODuration, type FormatTokens, type FormatPreset, type CompareOperator, type CompareGranularity, type PeriodOptions, type TimezoneInput, type TimezoneInfo, type TimezoneOffset, type DSTransition, type LocaleConfig, type HumanDiffOptions, type DiffResult, type ChronosSerializable, type ChronosJSON, type TimeRange, type BusinessHours, type CalendarWeek, type CalendarMonth, type DeepPartial, type NumericKeys, type TypeGuard, type Chainable, MILLISECONDS_PER_SECOND, MILLISECONDS_PER_MINUTE, MILLISECONDS_PER_HOUR, MILLISECONDS_PER_DAY, MILLISECONDS_PER_WEEK, MILLISECONDS_PER_MONTH, MILLISECONDS_PER_YEAR, SECONDS_PER_MINUTE, MINUTES_PER_HOUR, HOURS_PER_DAY, DAYS_PER_WEEK, MONTHS_PER_YEAR, DAYS_PER_YEAR, DAYS_PER_LEAP_YEAR, AVERAGE_DAYS_PER_MONTH, AVERAGE_DAYS_PER_YEAR, } from './types';
48
+ export { isDate, isValidDateInput, isChronosLike, isDuration, isISODuration, isLeapYear, isValidDate, normalizeUnit, pluralizeUnit, getMillisecondsPerUnit, getDaysInMonth, getDaysInYear, getDayOfYear, getISOWeek, getISOWeekYear, getQuarter, startOf, endOf, addDuration, subtractDuration, addUnits, diffInUnits, parseISODuration, durationToISO, compareAtGranularity, isSameAt, cloneDate, clamp, ordinalSuffix, padStart, } from './utils';
49
+ export { getLocale, registerLocale, getAvailableLocales, defaultLocale, en, es, fr, de, ja, zh, pt, it, ar, ru, } from './locales';
50
+ export { Chronos as default } from './core';
package/dist/index.js CHANGED
@@ -1,9 +1,150 @@
1
1
  "use strict";
2
+ /**
3
+ * Chronos v2 - A comprehensive TypeScript library for date and time manipulation
4
+ *
5
+ * @description
6
+ * Chronos is a powerful, modern TypeScript library for handling dates, times,
7
+ * intervals, periods, and timezones. Inspired by Carbon PHP, it provides an
8
+ * intuitive and fluent API for all your time-related needs.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { Chronos, ChronosInterval, ChronosPeriod, ChronosTimezone } from 'chronos-ts';
13
+ *
14
+ * // Create dates
15
+ * const now = Chronos.now();
16
+ * const birthday = Chronos.create(1990, 5, 15);
17
+ *
18
+ * // Manipulate
19
+ * const nextWeek = now.addWeeks(1);
20
+ * const endOfMonth = now.endOf('month');
21
+ *
22
+ * // Compare
23
+ * if (now.isAfter(birthday)) {
24
+ * console.log('Birthday has passed');
25
+ * }
26
+ *
27
+ * // Format
28
+ * console.log(now.format('MMMM D, YYYY')); // "January 15, 2024"
29
+ *
30
+ * // Intervals
31
+ * const duration = ChronosInterval.hours(5).addMinutes(30);
32
+ * console.log(duration.forHumans()); // "5 hours 30 minutes"
33
+ *
34
+ * // Periods
35
+ * const week = ChronosPeriod.currentWeek();
36
+ * for (const day of week) {
37
+ * console.log(day.format('dddd'));
38
+ * }
39
+ *
40
+ * // Timezones
41
+ * const tz = ChronosTimezone.create('America/New_York');
42
+ * console.log(tz.getOffsetString()); // "-05:00"
43
+ * ```
44
+ *
45
+ * @packageDocumentation
46
+ */
2
47
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Interval = exports.Precision = exports.Period = void 0;
4
- var period_1 = require("./period");
5
- Object.defineProperty(exports, "Period", { enumerable: true, get: function () { return period_1.Period; } });
6
- var precision_1 = require("./precision");
7
- Object.defineProperty(exports, "Precision", { enumerable: true, get: function () { return precision_1.Precision; } });
8
- var interval_1 = require("./interval");
9
- Object.defineProperty(exports, "Interval", { enumerable: true, get: function () { return interval_1.Interval; } });
48
+ exports.durationToISO = exports.parseISODuration = exports.diffInUnits = exports.addUnits = exports.subtractDuration = exports.addDuration = exports.endOf = exports.startOf = exports.getQuarter = exports.getISOWeekYear = exports.getISOWeek = exports.getDayOfYear = exports.getDaysInYear = exports.getDaysInMonth = exports.getMillisecondsPerUnit = exports.pluralizeUnit = exports.normalizeUnit = exports.isValidDate = exports.isLeapYear = exports.isISODuration = exports.isDuration = exports.isChronosLike = exports.isValidDateInput = exports.isDate = exports.AVERAGE_DAYS_PER_YEAR = exports.AVERAGE_DAYS_PER_MONTH = exports.DAYS_PER_LEAP_YEAR = exports.DAYS_PER_YEAR = exports.MONTHS_PER_YEAR = exports.DAYS_PER_WEEK = exports.HOURS_PER_DAY = exports.MINUTES_PER_HOUR = exports.SECONDS_PER_MINUTE = exports.MILLISECONDS_PER_YEAR = exports.MILLISECONDS_PER_MONTH = exports.MILLISECONDS_PER_WEEK = exports.MILLISECONDS_PER_DAY = exports.MILLISECONDS_PER_HOUR = exports.MILLISECONDS_PER_MINUTE = exports.MILLISECONDS_PER_SECOND = exports.PeriodBoundary = exports.Month = exports.DayOfWeek = exports.Timezones = exports.TIMEZONES = exports.ChronosTimezone = exports.ChronosPeriodCollection = exports.ChronosPeriod = exports.ChronosInterval = exports.Chronos = void 0;
49
+ exports.default = exports.ru = exports.ar = exports.it = exports.pt = exports.zh = exports.ja = exports.de = exports.fr = exports.es = exports.en = exports.defaultLocale = exports.getAvailableLocales = exports.registerLocale = exports.getLocale = exports.padStart = exports.ordinalSuffix = exports.clamp = exports.cloneDate = exports.isSameAt = exports.compareAtGranularity = void 0;
50
+ // ============================================================================
51
+ // Core Classes
52
+ // ============================================================================
53
+ var core_1 = require("./core");
54
+ Object.defineProperty(exports, "Chronos", { enumerable: true, get: function () { return core_1.Chronos; } });
55
+ Object.defineProperty(exports, "ChronosInterval", { enumerable: true, get: function () { return core_1.ChronosInterval; } });
56
+ Object.defineProperty(exports, "ChronosPeriod", { enumerable: true, get: function () { return core_1.ChronosPeriod; } });
57
+ Object.defineProperty(exports, "ChronosPeriodCollection", { enumerable: true, get: function () { return core_1.ChronosPeriodCollection; } });
58
+ Object.defineProperty(exports, "ChronosTimezone", { enumerable: true, get: function () { return core_1.ChronosTimezone; } });
59
+ Object.defineProperty(exports, "TIMEZONES", { enumerable: true, get: function () { return core_1.TIMEZONES; } });
60
+ Object.defineProperty(exports, "Timezones", { enumerable: true, get: function () { return core_1.Timezones; } });
61
+ // ============================================================================
62
+ // Types
63
+ // ============================================================================
64
+ var types_1 = require("./types");
65
+ // Enums
66
+ Object.defineProperty(exports, "DayOfWeek", { enumerable: true, get: function () { return types_1.DayOfWeek; } });
67
+ Object.defineProperty(exports, "Month", { enumerable: true, get: function () { return types_1.Month; } });
68
+ Object.defineProperty(exports, "PeriodBoundary", { enumerable: true, get: function () { return types_1.PeriodBoundary; } });
69
+ // Constants
70
+ Object.defineProperty(exports, "MILLISECONDS_PER_SECOND", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_SECOND; } });
71
+ Object.defineProperty(exports, "MILLISECONDS_PER_MINUTE", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_MINUTE; } });
72
+ Object.defineProperty(exports, "MILLISECONDS_PER_HOUR", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_HOUR; } });
73
+ Object.defineProperty(exports, "MILLISECONDS_PER_DAY", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_DAY; } });
74
+ Object.defineProperty(exports, "MILLISECONDS_PER_WEEK", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_WEEK; } });
75
+ Object.defineProperty(exports, "MILLISECONDS_PER_MONTH", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_MONTH; } });
76
+ Object.defineProperty(exports, "MILLISECONDS_PER_YEAR", { enumerable: true, get: function () { return types_1.MILLISECONDS_PER_YEAR; } });
77
+ Object.defineProperty(exports, "SECONDS_PER_MINUTE", { enumerable: true, get: function () { return types_1.SECONDS_PER_MINUTE; } });
78
+ Object.defineProperty(exports, "MINUTES_PER_HOUR", { enumerable: true, get: function () { return types_1.MINUTES_PER_HOUR; } });
79
+ Object.defineProperty(exports, "HOURS_PER_DAY", { enumerable: true, get: function () { return types_1.HOURS_PER_DAY; } });
80
+ Object.defineProperty(exports, "DAYS_PER_WEEK", { enumerable: true, get: function () { return types_1.DAYS_PER_WEEK; } });
81
+ Object.defineProperty(exports, "MONTHS_PER_YEAR", { enumerable: true, get: function () { return types_1.MONTHS_PER_YEAR; } });
82
+ Object.defineProperty(exports, "DAYS_PER_YEAR", { enumerable: true, get: function () { return types_1.DAYS_PER_YEAR; } });
83
+ Object.defineProperty(exports, "DAYS_PER_LEAP_YEAR", { enumerable: true, get: function () { return types_1.DAYS_PER_LEAP_YEAR; } });
84
+ Object.defineProperty(exports, "AVERAGE_DAYS_PER_MONTH", { enumerable: true, get: function () { return types_1.AVERAGE_DAYS_PER_MONTH; } });
85
+ Object.defineProperty(exports, "AVERAGE_DAYS_PER_YEAR", { enumerable: true, get: function () { return types_1.AVERAGE_DAYS_PER_YEAR; } });
86
+ // ============================================================================
87
+ // Utilities
88
+ // ============================================================================
89
+ var utils_1 = require("./utils");
90
+ // Type Guards
91
+ Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return utils_1.isDate; } });
92
+ Object.defineProperty(exports, "isValidDateInput", { enumerable: true, get: function () { return utils_1.isValidDateInput; } });
93
+ Object.defineProperty(exports, "isChronosLike", { enumerable: true, get: function () { return utils_1.isChronosLike; } });
94
+ Object.defineProperty(exports, "isDuration", { enumerable: true, get: function () { return utils_1.isDuration; } });
95
+ Object.defineProperty(exports, "isISODuration", { enumerable: true, get: function () { return utils_1.isISODuration; } });
96
+ Object.defineProperty(exports, "isLeapYear", { enumerable: true, get: function () { return utils_1.isLeapYear; } });
97
+ Object.defineProperty(exports, "isValidDate", { enumerable: true, get: function () { return utils_1.isValidDate; } });
98
+ // Unit Utilities
99
+ Object.defineProperty(exports, "normalizeUnit", { enumerable: true, get: function () { return utils_1.normalizeUnit; } });
100
+ Object.defineProperty(exports, "pluralizeUnit", { enumerable: true, get: function () { return utils_1.pluralizeUnit; } });
101
+ Object.defineProperty(exports, "getMillisecondsPerUnit", { enumerable: true, get: function () { return utils_1.getMillisecondsPerUnit; } });
102
+ // Date Utilities
103
+ Object.defineProperty(exports, "getDaysInMonth", { enumerable: true, get: function () { return utils_1.getDaysInMonth; } });
104
+ Object.defineProperty(exports, "getDaysInYear", { enumerable: true, get: function () { return utils_1.getDaysInYear; } });
105
+ Object.defineProperty(exports, "getDayOfYear", { enumerable: true, get: function () { return utils_1.getDayOfYear; } });
106
+ Object.defineProperty(exports, "getISOWeek", { enumerable: true, get: function () { return utils_1.getISOWeek; } });
107
+ Object.defineProperty(exports, "getISOWeekYear", { enumerable: true, get: function () { return utils_1.getISOWeekYear; } });
108
+ Object.defineProperty(exports, "getQuarter", { enumerable: true, get: function () { return utils_1.getQuarter; } });
109
+ Object.defineProperty(exports, "startOf", { enumerable: true, get: function () { return utils_1.startOf; } });
110
+ Object.defineProperty(exports, "endOf", { enumerable: true, get: function () { return utils_1.endOf; } });
111
+ // Arithmetic
112
+ Object.defineProperty(exports, "addDuration", { enumerable: true, get: function () { return utils_1.addDuration; } });
113
+ Object.defineProperty(exports, "subtractDuration", { enumerable: true, get: function () { return utils_1.subtractDuration; } });
114
+ Object.defineProperty(exports, "addUnits", { enumerable: true, get: function () { return utils_1.addUnits; } });
115
+ Object.defineProperty(exports, "diffInUnits", { enumerable: true, get: function () { return utils_1.diffInUnits; } });
116
+ // Parsing
117
+ Object.defineProperty(exports, "parseISODuration", { enumerable: true, get: function () { return utils_1.parseISODuration; } });
118
+ Object.defineProperty(exports, "durationToISO", { enumerable: true, get: function () { return utils_1.durationToISO; } });
119
+ // Comparison
120
+ Object.defineProperty(exports, "compareAtGranularity", { enumerable: true, get: function () { return utils_1.compareAtGranularity; } });
121
+ Object.defineProperty(exports, "isSameAt", { enumerable: true, get: function () { return utils_1.isSameAt; } });
122
+ // Helpers
123
+ Object.defineProperty(exports, "cloneDate", { enumerable: true, get: function () { return utils_1.cloneDate; } });
124
+ Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return utils_1.clamp; } });
125
+ Object.defineProperty(exports, "ordinalSuffix", { enumerable: true, get: function () { return utils_1.ordinalSuffix; } });
126
+ Object.defineProperty(exports, "padStart", { enumerable: true, get: function () { return utils_1.padStart; } });
127
+ // ============================================================================
128
+ // Locales
129
+ // ============================================================================
130
+ var locales_1 = require("./locales");
131
+ Object.defineProperty(exports, "getLocale", { enumerable: true, get: function () { return locales_1.getLocale; } });
132
+ Object.defineProperty(exports, "registerLocale", { enumerable: true, get: function () { return locales_1.registerLocale; } });
133
+ Object.defineProperty(exports, "getAvailableLocales", { enumerable: true, get: function () { return locales_1.getAvailableLocales; } });
134
+ Object.defineProperty(exports, "defaultLocale", { enumerable: true, get: function () { return locales_1.defaultLocale; } });
135
+ Object.defineProperty(exports, "en", { enumerable: true, get: function () { return locales_1.en; } });
136
+ Object.defineProperty(exports, "es", { enumerable: true, get: function () { return locales_1.es; } });
137
+ Object.defineProperty(exports, "fr", { enumerable: true, get: function () { return locales_1.fr; } });
138
+ Object.defineProperty(exports, "de", { enumerable: true, get: function () { return locales_1.de; } });
139
+ Object.defineProperty(exports, "ja", { enumerable: true, get: function () { return locales_1.ja; } });
140
+ Object.defineProperty(exports, "zh", { enumerable: true, get: function () { return locales_1.zh; } });
141
+ Object.defineProperty(exports, "pt", { enumerable: true, get: function () { return locales_1.pt; } });
142
+ Object.defineProperty(exports, "it", { enumerable: true, get: function () { return locales_1.it; } });
143
+ Object.defineProperty(exports, "ar", { enumerable: true, get: function () { return locales_1.ar; } });
144
+ Object.defineProperty(exports, "ru", { enumerable: true, get: function () { return locales_1.ru; } });
145
+ // ============================================================================
146
+ // Default Export
147
+ // ============================================================================
148
+ // Export Chronos as default for convenience
149
+ var core_2 = require("./core");
150
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return core_2.Chronos; } });
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Locale configuration for Chronos
3
+ * @module locales
4
+ */
5
+ import { LocaleConfig } from '../types';
6
+ export type { LocaleConfig } from '../types';
7
+ /**
8
+ * English (US) locale configuration
9
+ */
10
+ export declare const en: LocaleConfig;
11
+ /**
12
+ * French locale configuration
13
+ */
14
+ export declare const fr: LocaleConfig;
15
+ /**
16
+ * Spanish locale configuration
17
+ */
18
+ export declare const es: LocaleConfig;
19
+ /**
20
+ * Italian locale configuration
21
+ */
22
+ export declare const it: LocaleConfig;
23
+ /**
24
+ * Arabic locale configuration (Modern Standard Arabic)
25
+ */
26
+ export declare const ar: LocaleConfig;
27
+ /**
28
+ * Russian locale configuration
29
+ */
30
+ export declare const ru: LocaleConfig;
31
+ /**
32
+ * German locale configuration
33
+ */
34
+ export declare const de: LocaleConfig;
35
+ /**
36
+ * Japanese locale configuration
37
+ */
38
+ export declare const ja: LocaleConfig;
39
+ /**
40
+ * Chinese (Simplified) locale configuration
41
+ */
42
+ export declare const zh: LocaleConfig;
43
+ /**
44
+ * Portuguese (Brazil) locale configuration
45
+ */
46
+ export declare const pt: LocaleConfig;
47
+ /**
48
+ * All available locales
49
+ */
50
+ export declare const locales: Record<string, LocaleConfig>;
51
+ /**
52
+ * Default locale
53
+ */
54
+ export declare const defaultLocale: LocaleConfig;
55
+ /**
56
+ * Get a locale by code
57
+ */
58
+ export declare function getLocale(code: string): LocaleConfig;
59
+ /**
60
+ * Register a new locale
61
+ */
62
+ export declare function registerLocale(config: LocaleConfig): void;
63
+ /**
64
+ * Get available locale codes
65
+ */
66
+ export declare function getAvailableLocales(): string[];