@cedx/base 0.31.0 → 0.33.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/ReadMe.md CHANGED
@@ -1,6 +1,4 @@
1
1
  # Cédric Belin's Base
2
- ![.NET](https://badgen.net/badge/.net/%3E%3D9.0/green) ![Version](https://badgen.net/badge/project/v0.31.0/blue) ![Licence](https://badgen.net/badge/licence/MIT/blue)
3
-
4
2
  Base library by [Cédric Belin](https://cedric-belin.fr), full stack developer,
5
3
  implemented in [C#](https://learn.microsoft.com/en-us/dotnet/csharp) and [TypeScript](https://www.typescriptlang.org).
6
4
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Defines the scenario used in data validation.
3
+ */
4
+ export declare const Scenario: Readonly<{
5
+ /**
6
+ * A scenario in which the underlying model is created.
7
+ */
8
+ Creation: "Creation";
9
+ /**
10
+ * A scenario in which the underlying model is updated.
11
+ */
12
+ Update: "Update";
13
+ }>;
14
+ /**
15
+ * Defines the scenario used in data validation.
16
+ */
17
+ export type Scenario = typeof Scenario[keyof typeof Scenario];
18
+ //# sourceMappingURL=Scenario.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Scenario.d.ts","sourceRoot":"","sources":["../../src/Client/Data/Scenario.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Defines the scenario used in data validation.
3
+ */
4
+ export const Scenario = Object.freeze({
5
+ /**
6
+ * A scenario in which the underlying model is created.
7
+ */
8
+ Creation: "Creation",
9
+ /**
10
+ * A scenario in which the underlying model is updated.
11
+ */
12
+ Update: "Update"
13
+ });
package/lib/Date.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Date.d.ts","sourceRoot":"","sources":["../src/Client/Date.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAc1C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAqB9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG7C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAGhD;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAI5B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAM,GAAG,MAAM,CAM7H"}
1
+ {"version":3,"file":"Date.d.ts","sourceRoot":"","sources":["../src/Client/Base/Date.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAc1C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAqB9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG9C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAG7C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAGhD;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAI5B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAM,GAAG,MAAM,CAM7H"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Defines the type of a date range.
3
+ */
4
+ export declare const DateRangeType: Readonly<{
5
+ /**
6
+ * A custom date range.
7
+ */
8
+ Custom: "Custom";
9
+ /**
10
+ * A whole day.
11
+ */
12
+ Day: "Day";
13
+ /**
14
+ * A whole week.
15
+ */
16
+ Week: "Week";
17
+ /**
18
+ * A whole month.
19
+ */
20
+ Month: "Month";
21
+ /**
22
+ * A whole quarter.
23
+ */
24
+ Quarter: "Quarter";
25
+ /**
26
+ * A whole year.
27
+ */
28
+ Year: "Year";
29
+ }>;
30
+ /**
31
+ * Defines the type of a date range.
32
+ */
33
+ export type DateRangeType = typeof DateRangeType[keyof typeof DateRangeType];
34
+ /**
35
+ * Defines a date range.
36
+ */
37
+ export declare class DateRange {
38
+ /**
39
+ * The end date.
40
+ */
41
+ readonly end: Date;
42
+ /**
43
+ * The start date.
44
+ */
45
+ readonly start: Date;
46
+ /**
47
+ * The range type.
48
+ */
49
+ readonly type: DateRangeType;
50
+ /**
51
+ * Creates a new date range.
52
+ * @param start The start date.
53
+ * @param end The end date.
54
+ * @param type The range type.
55
+ */
56
+ constructor(start: Date, end: Date, type?: DateRangeType);
57
+ /**
58
+ * Creates a new date range from the specified JSON object.
59
+ * @param json A JSON object representing a date range.
60
+ * @returns The instance corresponding to the specified JSON object.
61
+ */
62
+ static fromJson(json: Record<string, any>): DateRange;
63
+ /**
64
+ * Creates a date range corresponding to the day including the specified date.
65
+ * @param date The date.
66
+ * @returns The date range corresponding to the day including the specified date.
67
+ */
68
+ static day(date: Date): DateRange;
69
+ /**
70
+ * Creates a date range corresponding to the month including the specified date.
71
+ * @param date The date.
72
+ * @returns The date range corresponding to the month including the specified date.
73
+ */
74
+ static month(date: Date): DateRange;
75
+ /**
76
+ * Creates a date range corresponding to the quarter including the specified date.
77
+ * @param date The date.
78
+ * @returns The date range corresponding to the quarter including the specified date.
79
+ */
80
+ static quarter(date: Date): DateRange;
81
+ /**
82
+ * Creates a date range corresponding to the week including the specified date.
83
+ * @param date The date.
84
+ * @returns The date range corresponding to the week including the specified date.
85
+ */
86
+ static week(date: Date): DateRange;
87
+ /**
88
+ * Creates a date range corresponding to the year including the specified date.
89
+ * @param date The date.
90
+ * @returns The date range corresponding to the year including the specified date.
91
+ */
92
+ static year(date: Date): DateRange;
93
+ /**
94
+ * Returns a value indicating whether this date range is equal to the specified date range.
95
+ * @param other The other date range to compare.
96
+ * @returns `true` if this date range is equal to the specified date range, otherwise `false`.
97
+ */
98
+ equals(other: DateRange): boolean;
99
+ /**
100
+ * The label corresponding to this date range.
101
+ * @param culture The current culture.
102
+ * @returns The label corresponding to this date range.
103
+ */
104
+ getLabel(culture?: Intl.Locale | string): string;
105
+ }
106
+ //# sourceMappingURL=DateRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateRange.d.ts","sourceRoot":"","sources":["../src/Client/Base/DateRange.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,aAAa;IAEzB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE7E;;GAEG;AACH,qBAAa,SAAS;IAErB;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAE7B;;;;;OAKG;gBACS,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAE,aAAoC;IAM9E;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAQrD;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS;IAIjC;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS;IAQnC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS;IAUrC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS;IAOlC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS;IAIlC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAIjC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,GAAE,IAAI,CAAC,MAAM,GAAC,MAA2B,GAAG,MAAM;CAWlE"}
@@ -0,0 +1,136 @@
1
+ import { atMidnight, daysInMonth, getQuarter, getWeekOfYear } from "./Date.js";
2
+ import { TimeSpan } from "./TimeSpan.js";
3
+ /**
4
+ * Defines the type of a date range.
5
+ */
6
+ export const DateRangeType = Object.freeze({
7
+ /**
8
+ * A custom date range.
9
+ */
10
+ Custom: "Custom",
11
+ /**
12
+ * A whole day.
13
+ */
14
+ Day: "Day",
15
+ /**
16
+ * A whole week.
17
+ */
18
+ Week: "Week",
19
+ /**
20
+ * A whole month.
21
+ */
22
+ Month: "Month",
23
+ /**
24
+ * A whole quarter.
25
+ */
26
+ Quarter: "Quarter",
27
+ /**
28
+ * A whole year.
29
+ */
30
+ Year: "Year"
31
+ });
32
+ /**
33
+ * Defines a date range.
34
+ */
35
+ export class DateRange {
36
+ /**
37
+ * The end date.
38
+ */
39
+ end;
40
+ /**
41
+ * The start date.
42
+ */
43
+ start;
44
+ /**
45
+ * The range type.
46
+ */
47
+ type;
48
+ /**
49
+ * Creates a new date range.
50
+ * @param start The start date.
51
+ * @param end The end date.
52
+ * @param type The range type.
53
+ */
54
+ constructor(start, end, type = DateRangeType.Custom) {
55
+ this.start = start;
56
+ this.end = end;
57
+ this.type = type;
58
+ }
59
+ /**
60
+ * Creates a new date range from the specified JSON object.
61
+ * @param json A JSON object representing a date range.
62
+ * @returns The instance corresponding to the specified JSON object.
63
+ */
64
+ static fromJson(json) {
65
+ return new this(new Date(typeof json.start == "string" ? json.start : Date.now()), new Date(typeof json.end == "string" ? json.end : Date.now()), Object.values(DateRangeType).includes(json.type) ? json.type : DateRangeType.Custom);
66
+ }
67
+ /**
68
+ * Creates a date range corresponding to the day including the specified date.
69
+ * @param date The date.
70
+ * @returns The date range corresponding to the day including the specified date.
71
+ */
72
+ static day(date) {
73
+ return new this(atMidnight(date), new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999), DateRangeType.Day);
74
+ }
75
+ /**
76
+ * Creates a date range corresponding to the month including the specified date.
77
+ * @param date The date.
78
+ * @returns The date range corresponding to the month including the specified date.
79
+ */
80
+ static month(date) {
81
+ return new this(new Date(date.getFullYear(), date.getMonth(), 1), new Date(date.getFullYear(), date.getMonth(), daysInMonth(date), 23, 59, 59, 999), DateRangeType.Month);
82
+ }
83
+ /**
84
+ * Creates a date range corresponding to the quarter including the specified date.
85
+ * @param date The date.
86
+ * @returns The date range corresponding to the quarter including the specified date.
87
+ */
88
+ static quarter(date) {
89
+ const firstMonth = (getQuarter(date) * 3) - 3;
90
+ const lastMonth = firstMonth + 2;
91
+ return new this(new Date(date.getFullYear(), firstMonth, 1), new Date(date.getFullYear(), lastMonth, daysInMonth(new Date(date.getFullYear(), lastMonth, 1)), 23, 59, 59, 999), DateRangeType.Quarter);
92
+ }
93
+ /**
94
+ * Creates a date range corresponding to the week including the specified date.
95
+ * @param date The date.
96
+ * @returns The date range corresponding to the week including the specified date.
97
+ */
98
+ static week(date) {
99
+ const delta = -((date.getDay() + 6) % 7);
100
+ const sunday = new Date(date.getTime() + ((delta + 6) * TimeSpan.MillisecondsPerDay));
101
+ sunday.setHours(23, 59, 59, 999);
102
+ return new this(atMidnight(new Date(date.getTime() + (delta * TimeSpan.MillisecondsPerDay))), sunday, DateRangeType.Week);
103
+ }
104
+ /**
105
+ * Creates a date range corresponding to the year including the specified date.
106
+ * @param date The date.
107
+ * @returns The date range corresponding to the year including the specified date.
108
+ */
109
+ static year(date) {
110
+ return new this(new Date(date.getFullYear(), 0, 1), new Date(date.getFullYear(), 11, 31, 23, 59, 59, 999), DateRangeType.Year);
111
+ }
112
+ /**
113
+ * Returns a value indicating whether this date range is equal to the specified date range.
114
+ * @param other The other date range to compare.
115
+ * @returns `true` if this date range is equal to the specified date range, otherwise `false`.
116
+ */
117
+ equals(other) {
118
+ return this.start.getTime() == other.start.getTime() && this.end.getTime() == other.end.getTime();
119
+ }
120
+ /**
121
+ * The label corresponding to this date range.
122
+ * @param culture The current culture.
123
+ * @returns The label corresponding to this date range.
124
+ */
125
+ getLabel(culture = navigator.language) {
126
+ const { start, end, type } = this;
127
+ switch (type) {
128
+ case DateRangeType.Day: return start.toLocaleString(culture, { dateStyle: "medium" });
129
+ case DateRangeType.Week: return `S${getWeekOfYear(start)} ${start.getFullYear()}`;
130
+ case DateRangeType.Month: return start.toLocaleString(culture, { month: "long", year: "numeric" });
131
+ case DateRangeType.Quarter: return `T${getQuarter(start)} ${start.getFullYear()}`;
132
+ case DateRangeType.Year: return start.getFullYear().toString();
133
+ default: return end.toLocaleString(culture, { dateStyle: "medium" });
134
+ }
135
+ }
136
+ }
package/lib/File.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../src/Client/File.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAUzC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAM,GAAG,IAAI,CAkBvE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAatC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAOlD"}
1
+ {"version":3,"file":"File.d.ts","sourceRoot":"","sources":["../src/Client/Base/File.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAUzC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAM,GAAG,IAAI,CAkBvE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAatC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAOlD"}
@@ -1 +1 @@
1
- {"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../src/Client/Number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAG1D"}
1
+ {"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../src/Client/Base/Number.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAG1D"}
package/lib/String.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Converts the first character to uppercase.
2
+ * Converts the first character of the specified string to uppercase.
3
3
  * @param value The string to process.
4
- * @param locale The current locale.
4
+ * @param culture The current culture.
5
5
  * @returns The processed string.
6
6
  */
7
- export declare function capitalize(value: string, locale?: Intl.Locale | string): string;
7
+ export declare function capitalize(value: string, culture?: Intl.Locale | string): string;
8
8
  /**
9
9
  * Replaces all new lines in the specified value by HTML line breaks.
10
10
  * @param value The string to format.
@@ -1 +1 @@
1
- {"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../src/Client/String.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,CAAC,MAAM,GAAC,MAA2B,GAAG,MAAM,CAEjG;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAM,GAAG,MAAM,CAElF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM,EAAE,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAEhF"}
1
+ {"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../src/Client/Base/String.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,MAAM,GAAC,MAA2B,GAAG,MAAM,CAElG;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAM,GAAG,MAAM,CAElF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM,EAAE,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAEhF"}
package/lib/String.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Converts the first character to uppercase.
2
+ * Converts the first character of the specified string to uppercase.
3
3
  * @param value The string to process.
4
- * @param locale The current locale.
4
+ * @param culture The current culture.
5
5
  * @returns The processed string.
6
6
  */
7
- export function capitalize(value, locale = navigator.language) {
8
- return value.charAt(0).toLocaleUpperCase(locale) + value.slice(1);
7
+ export function capitalize(value, culture = navigator.language) {
8
+ return value.length == 0 ? "" : value.charAt(0).toLocaleUpperCase(culture) + value.slice(1);
9
9
  }
10
10
  /**
11
11
  * Replaces all new lines in the specified value by HTML line breaks.
@@ -1 +1 @@
1
- {"version":3,"file":"TimeSpan.d.ts","sourceRoot":"","sources":["../src/Client/TimeSpan.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC"}
1
+ {"version":3,"file":"TimeSpan.d.ts","sourceRoot":"","sources":["../src/Client/Base/TimeSpan.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEpB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC"}
package/package.json CHANGED
@@ -7,23 +7,23 @@
7
7
  "name": "@cedx/base",
8
8
  "repository": "cedx/base",
9
9
  "type": "module",
10
- "version": "0.31.0",
10
+ "version": "0.33.0",
11
11
  "devDependencies": {
12
- "@playwright/browser-chromium": "^1.55.0",
12
+ "@playwright/browser-firefox": "^1.56.1",
13
13
  "@types/bootstrap": "^5.2.10",
14
- "@types/chai": "^5.2.2",
14
+ "@types/chai": "^5.2.3",
15
15
  "@types/mocha": "^10.0.10",
16
- "@types/node": "^24.5.2",
16
+ "@types/node": "^24.10.1",
17
17
  "@types/serve-handler": "^6.1.4",
18
- "chai": "^6.0.1",
19
- "esbuild": "^0.25.10",
20
- "globals": "^16.4.0",
21
- "mocha": "^11.7.2",
22
- "playwright": "^1.55.0",
18
+ "chai": "^6.2.1",
19
+ "esbuild": "^0.27.0",
20
+ "globals": "^16.5.0",
21
+ "mocha": "^11.7.5",
22
+ "playwright": "^1.56.1",
23
23
  "serve-handler": "^6.1.6",
24
- "typedoc": "^0.28.13",
25
- "typescript": "^5.9.2",
26
- "typescript-eslint": "^8.44.0"
24
+ "typedoc": "^0.28.14",
25
+ "typescript": "^5.9.3",
26
+ "typescript-eslint": "^8.46.4"
27
27
  },
28
28
  "engines": {
29
29
  "node": ">=24.0.0"
@@ -0,0 +1,173 @@
1
+ import {atMidnight, daysInMonth, getQuarter, getWeekOfYear} from "./Date.js";
2
+ import {TimeSpan} from "./TimeSpan.js";
3
+
4
+ /**
5
+ * Defines the type of a date range.
6
+ */
7
+ export const DateRangeType = Object.freeze({
8
+
9
+ /**
10
+ * A custom date range.
11
+ */
12
+ Custom: "Custom",
13
+
14
+ /**
15
+ * A whole day.
16
+ */
17
+ Day: "Day",
18
+
19
+ /**
20
+ * A whole week.
21
+ */
22
+ Week: "Week",
23
+
24
+ /**
25
+ * A whole month.
26
+ */
27
+ Month: "Month",
28
+
29
+ /**
30
+ * A whole quarter.
31
+ */
32
+ Quarter: "Quarter",
33
+
34
+ /**
35
+ * A whole year.
36
+ */
37
+ Year: "Year"
38
+ });
39
+
40
+ /**
41
+ * Defines the type of a date range.
42
+ */
43
+ export type DateRangeType = typeof DateRangeType[keyof typeof DateRangeType];
44
+
45
+ /**
46
+ * Defines a date range.
47
+ */
48
+ export class DateRange {
49
+
50
+ /**
51
+ * The end date.
52
+ */
53
+ readonly end: Date;
54
+
55
+ /**
56
+ * The start date.
57
+ */
58
+ readonly start: Date;
59
+
60
+ /**
61
+ * The range type.
62
+ */
63
+ readonly type: DateRangeType;
64
+
65
+ /**
66
+ * Creates a new date range.
67
+ * @param start The start date.
68
+ * @param end The end date.
69
+ * @param type The range type.
70
+ */
71
+ constructor(start: Date, end: Date, type: DateRangeType = DateRangeType.Custom) {
72
+ this.start = start;
73
+ this.end = end;
74
+ this.type = type;
75
+ }
76
+
77
+ /**
78
+ * Creates a new date range from the specified JSON object.
79
+ * @param json A JSON object representing a date range.
80
+ * @returns The instance corresponding to the specified JSON object.
81
+ */
82
+ static fromJson(json: Record<string, any>): DateRange {
83
+ return new this(
84
+ new Date(typeof json.start == "string" ? json.start : Date.now()),
85
+ new Date(typeof json.end == "string" ? json.end : Date.now()),
86
+ Object.values(DateRangeType).includes(json.type as DateRangeType) ? json.type as DateRangeType : DateRangeType.Custom
87
+ );
88
+ }
89
+
90
+ /**
91
+ * Creates a date range corresponding to the day including the specified date.
92
+ * @param date The date.
93
+ * @returns The date range corresponding to the day including the specified date.
94
+ */
95
+ static day(date: Date): DateRange {
96
+ return new this(atMidnight(date), new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999), DateRangeType.Day);
97
+ }
98
+
99
+ /**
100
+ * Creates a date range corresponding to the month including the specified date.
101
+ * @param date The date.
102
+ * @returns The date range corresponding to the month including the specified date.
103
+ */
104
+ static month(date: Date): DateRange {
105
+ return new this(
106
+ new Date(date.getFullYear(), date.getMonth(), 1),
107
+ new Date(date.getFullYear(), date.getMonth(), daysInMonth(date), 23, 59, 59, 999),
108
+ DateRangeType.Month
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Creates a date range corresponding to the quarter including the specified date.
114
+ * @param date The date.
115
+ * @returns The date range corresponding to the quarter including the specified date.
116
+ */
117
+ static quarter(date: Date): DateRange {
118
+ const firstMonth = (getQuarter(date) * 3) - 3;
119
+ const lastMonth = firstMonth + 2;
120
+ return new this(
121
+ new Date(date.getFullYear(), firstMonth, 1),
122
+ new Date(date.getFullYear(), lastMonth, daysInMonth(new Date(date.getFullYear(), lastMonth, 1)), 23, 59, 59, 999),
123
+ DateRangeType.Quarter
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Creates a date range corresponding to the week including the specified date.
129
+ * @param date The date.
130
+ * @returns The date range corresponding to the week including the specified date.
131
+ */
132
+ static week(date: Date): DateRange {
133
+ const delta = -((date.getDay() + 6) % 7);
134
+ const sunday = new Date(date.getTime() + ((delta + 6) * TimeSpan.MillisecondsPerDay));
135
+ sunday.setHours(23, 59, 59, 999);
136
+ return new this(atMidnight(new Date(date.getTime() + (delta * TimeSpan.MillisecondsPerDay))), sunday, DateRangeType.Week);
137
+ }
138
+
139
+ /**
140
+ * Creates a date range corresponding to the year including the specified date.
141
+ * @param date The date.
142
+ * @returns The date range corresponding to the year including the specified date.
143
+ */
144
+ static year(date: Date): DateRange {
145
+ return new this(new Date(date.getFullYear(), 0, 1), new Date(date.getFullYear(), 11, 31, 23, 59, 59, 999), DateRangeType.Year);
146
+ }
147
+
148
+ /**
149
+ * Returns a value indicating whether this date range is equal to the specified date range.
150
+ * @param other The other date range to compare.
151
+ * @returns `true` if this date range is equal to the specified date range, otherwise `false`.
152
+ */
153
+ equals(other: DateRange): boolean {
154
+ return this.start.getTime() == other.start.getTime() && this.end.getTime() == other.end.getTime();
155
+ }
156
+
157
+ /**
158
+ * The label corresponding to this date range.
159
+ * @param culture The current culture.
160
+ * @returns The label corresponding to this date range.
161
+ */
162
+ getLabel(culture: Intl.Locale|string = navigator.language): string {
163
+ const {start, end, type} = this;
164
+ switch (type) {
165
+ case DateRangeType.Day: return start.toLocaleString(culture, {dateStyle: "medium"});
166
+ case DateRangeType.Week: return `S${getWeekOfYear(start)} ${start.getFullYear()}`;
167
+ case DateRangeType.Month: return start.toLocaleString(culture, {month: "long", year: "numeric"});
168
+ case DateRangeType.Quarter: return `T${getQuarter(start)} ${start.getFullYear()}`;
169
+ case DateRangeType.Year: return start.getFullYear().toString();
170
+ default: return end.toLocaleString(culture, {dateStyle: "medium"});
171
+ }
172
+ }
173
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Converts the first character to uppercase.
2
+ * Converts the first character of the specified string to uppercase.
3
3
  * @param value The string to process.
4
- * @param locale The current locale.
4
+ * @param culture The current culture.
5
5
  * @returns The processed string.
6
6
  */
7
- export function capitalize(value: string, locale: Intl.Locale|string = navigator.language): string {
8
- return value.charAt(0).toLocaleUpperCase(locale) + value.slice(1);
7
+ export function capitalize(value: string, culture: Intl.Locale|string = navigator.language): string {
8
+ return value.length == 0 ? "" : value.charAt(0).toLocaleUpperCase(culture) + value.slice(1);
9
9
  }
10
10
 
11
11
  /**
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.json",
3
- "include": ["../*.ts"],
3
+ "include": ["**/*.ts"],
4
4
  "compilerOptions": {
5
5
  "composite": true,
6
6
  "declaration": true,
7
7
  "declarationMap": true,
8
8
  "noEmit": false,
9
9
  "outDir": "../../../lib",
10
- "rootDir": "..",
10
+ "rootDir": ".",
11
11
  "tsBuildInfoFile": "../../../var/Base.tsbuildinfo"
12
12
  }
13
13
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Defines the scenario used in data validation.
3
+ */
4
+ export const Scenario = Object.freeze({
5
+
6
+ /**
7
+ * A scenario in which the underlying model is created.
8
+ */
9
+ Creation: "Creation",
10
+
11
+ /**
12
+ * A scenario in which the underlying model is updated.
13
+ */
14
+ Update: "Update"
15
+ });
16
+
17
+ /**
18
+ * Defines the scenario used in data validation.
19
+ */
20
+ export type Scenario = typeof Scenario[keyof typeof Scenario];
File without changes
File without changes
File without changes
File without changes