@aurodesignsystem/auro-library 4.1.0 → 4.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Semantic Release Automated Changelog
2
2
 
3
+ # [4.2.0](https://github.com/AlaskaAirlines/auro-library/compare/v4.1.1...v4.2.0) (2025-04-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * add dateAndFormatMatch to date utilities ([4ce4779](https://github.com/AlaskaAirlines/auro-library/commit/4ce47799514a528d351ec829b8fc8f3f093868cf))
9
+
10
+ ## [4.1.1](https://github.com/AlaskaAirlines/auro-library/compare/v4.1.0...v4.1.1) (2025-04-09)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * update wca writing script not to write lines with [@tags](https://github.com/tags) ([8ff5eab](https://github.com/AlaskaAirlines/auro-library/commit/8ff5eab39a656bcf2eac1d4439cb0d44d3208d48))
16
+
3
17
  # [4.1.0](https://github.com/AlaskaAirlines/auro-library/compare/v4.0.0...v4.1.0) (2025-04-02)
4
18
 
5
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurodesignsystem/auro-library",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "This repository holds shared scripts, utilities, and workflows utilized across repositories along the Auro Design System.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,7 @@
1
1
  export default (code, sourcePath) => {
2
2
  const defaultTag = (code.match(/static register\(name \= (.+)\)/) || code.match(/customElements.get\((.+?)\)/))[1];
3
3
  const className = code.match(/export class (.+) extends/)?.[1];
4
- const classDesc = code.match(/\/\*\*((.|\n)*?)(\*\n|\*\/)/)?.[1] || '';
4
+ const classDesc = code.match(/\/\*\*((.|\n)*?)(\*\n|\*\/|[@])/)?.[1] || '';
5
5
 
6
6
  if (!defaultTag || !className) {
7
7
  return code;
@@ -90,7 +90,7 @@ export class AuroDateUtilities {
90
90
  const parsedDate = this.parseDate(dateStr, format);
91
91
 
92
92
  if (!parsedDate) {
93
- return parsedDate;
93
+ throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
94
94
  }
95
95
 
96
96
  const { month, day, year } = parsedDate;
@@ -124,32 +124,169 @@ export class AuroDateUtilities {
124
124
  return undefined;
125
125
  }
126
126
 
127
- // Define mappings for date components with named capture groups
128
- const formatPatterns = {
129
- 'yyyy': '(?<year>\\d{4})',
130
- 'mm': '(?<month>\\d{2})',
131
- 'dd': '(?<day>\\d{2})'
127
+ // Assume the separator is a "/" a defined in our code base
128
+ const separator = '/';
129
+
130
+ // Get the parts of the date and format
131
+ const valueParts = dateStr.split(separator);
132
+ const formatParts = format.split(separator);
133
+
134
+ // Check if the value and format have the correct number of parts
135
+ if (valueParts.length !== formatParts.length) {
136
+ throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
137
+ }
138
+
139
+ // Holds the result to be returned
140
+ const result = {
141
+ day: undefined,
142
+ month: undefined,
143
+ year: undefined
132
144
  };
133
145
 
134
- // Escape slashes and replace format components with regex patterns
135
- let regexPattern = format.replace(/(?:yyyy|mm|dd)/gu, (match) => formatPatterns[match]);
136
- regexPattern = `^${regexPattern}$`;
146
+ // Iterate over the format and value parts and assign them to the result
147
+ formatParts.forEach((formatPart, index) => {
148
+
149
+ const valuePart = valueParts[index];
137
150
 
138
- const regex = new RegExp(regexPattern, 'u');
139
- const match = dateStr.match(regex);
151
+ if (formatPart.toLowerCase().match("m")) {
152
+ result.month = valuePart;
153
+ } else if (formatPart.toLowerCase().match("d")) {
154
+ result.day = valuePart;
155
+ } else if (formatPart.toLowerCase().match("y")) {
156
+ result.year = valuePart;
157
+ }
158
+ });
140
159
 
141
- if (match && match.groups) {
142
- return {
143
- year: match.groups.year,
144
- month: match.groups.month,
145
- day: match.groups.day
146
- };
160
+ // If we found all the parts, return the result
161
+ if (result.day && result.month && result.year) {
162
+ return result;
147
163
  }
148
164
 
149
- return undefined;
165
+ // Throw an error to let the dev know we were unable to parse the date string
166
+ throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
150
167
  };
151
- }
152
168
 
169
+ /**
170
+ * Determines if a string date value matches the format provided.
171
+ * @param {string} value = The date string value.
172
+ * @param { string} format = The date format to match against.
173
+ * @returns {boolean}
174
+ */
175
+ this.dateAndFormatMatch = (value, format) => {
176
+
177
+ // Ensure we have both values we need to do the comparison
178
+ if (!value || !format) {
179
+ throw new Error('AuroFormValidation | dateFormatMatches: value and format are required');
180
+ }
181
+
182
+ // If the lengths are different, they cannot match
183
+ if (value.length !== format.length) {
184
+ return false;
185
+ }
186
+
187
+ // Get the parts of the date
188
+ const dateParts = this.parseDate(value, format);
189
+
190
+ // Range definitions
191
+ const maxDay = 31;
192
+ const maxMonth = 12;
193
+ const minYear = 1000;
194
+ const maxYear = 9999;
195
+
196
+ // Validator for day
197
+ const dayValueIsValid = (day) => {
198
+
199
+ // Guard clause: ensure day exists.
200
+ if (!day) {
201
+ return false;
202
+ }
203
+
204
+ // Convert day to number
205
+ const numDay = parseInt(day, 10);
206
+
207
+ // Guard clause: ensure day is a valid integer
208
+ if (isNaN(numDay)) {
209
+ throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
210
+ }
211
+
212
+ // Guard clause: ensure day is within the valid range
213
+ if (numDay < 1 || numDay > maxDay) {
214
+ return false;
215
+ }
216
+
217
+ // Default return
218
+ return true;
219
+ };
220
+
221
+ // Validator for month
222
+ const monthValueIsValid = (month) => {
223
+
224
+ // Guard clause: ensure month exists.
225
+ if (!month) {
226
+ return false;
227
+ }
228
+
229
+ // Convert month to number
230
+ const numMonth = parseInt(month, 10);
231
+
232
+ // Guard clause: ensure month is a valid integer
233
+ if (isNaN(numMonth)) {
234
+ throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
235
+ }
236
+
237
+ // Guard clause: ensure month is within the valid range
238
+ if (numMonth < 1 || numMonth > maxMonth) {
239
+ return false;
240
+ }
241
+
242
+ // Default return
243
+ return true;
244
+ };
245
+
246
+ // Validator for year
247
+ const yearIsValid = (year) => {
248
+
249
+ // Guard clause: ensure year exists.
250
+ if (!year) {
251
+ return false;
252
+ }
253
+
254
+ // Convert year to number
255
+ const numYear = parseInt(year, 10);
256
+
257
+ // Guard clause: ensure year is a valid integer
258
+ if (isNaN(numYear)) {
259
+ throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
260
+ }
261
+
262
+ // Guard clause: ensure year is within the valid range
263
+ if (numYear < minYear || numYear > maxYear) {
264
+ return false;
265
+ }
266
+
267
+ // Default return
268
+ return true;
269
+ };
270
+
271
+ // Self-contained checks for month, day, and year
272
+ const checks = [
273
+ monthValueIsValid(dateParts.month),
274
+ dayValueIsValid(dateParts.day),
275
+ yearIsValid(dateParts.year)
276
+ ];
277
+
278
+ // If any of the checks failed, the date format does not match and the result is invalid
279
+ const isInvalid = checks.includes(false);
280
+
281
+ // If the check is invalid, return false
282
+ if (isInvalid) {
283
+ return false;
284
+ }
285
+
286
+ // Default case
287
+ return true;
288
+ };
289
+ }
153
290
  }
154
291
 
155
292
  // Export a class instance
@@ -162,4 +299,5 @@ export const {
162
299
  validDateStr,
163
300
  toNorthAmericanFormat,
164
301
  parseDate,
302
+ dateAndFormatMatch
165
303
  } = dateUtilities;