@aurodesignsystem-dev/auro-library 0.0.0-pr187.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/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +664 -0
- package/LICENSE +201 -0
- package/README.md +235 -0
- package/bin/generateDocs.mjs +210 -0
- package/bin/generateDocs_index.mjs +210 -0
- package/package.json +92 -0
- package/scripts/build/generateDocs.mjs +24 -0
- package/scripts/build/generateReadme.mjs +60 -0
- package/scripts/build/generateWcaComponent.mjs +43 -0
- package/scripts/build/postCss.mjs +66 -0
- package/scripts/build/postinstall.mjs +31 -0
- package/scripts/build/pre-commit.mjs +17 -0
- package/scripts/build/prepWcaCompatibleCode.mjs +19 -0
- package/scripts/build/processors/defaultDocsProcessor.mjs +83 -0
- package/scripts/build/processors/defaultDotGithubSync.mjs +83 -0
- package/scripts/build/staticStyles-template.js +2 -0
- package/scripts/build/syncGithubFiles.mjs +25 -0
- package/scripts/build/versionWriter.js +26 -0
- package/scripts/runtime/FocusTrap/FocusTrap.mjs +194 -0
- package/scripts/runtime/FocusTrap/index.mjs +1 -0
- package/scripts/runtime/FocusTrap/test/FocusTrap.test.js +168 -0
- package/scripts/runtime/Focusables/Focusables.mjs +157 -0
- package/scripts/runtime/Focusables/index.mjs +1 -0
- package/scripts/runtime/Focusables/test/Focusables.test.js +165 -0
- package/scripts/runtime/dateUtilities/baseDateUtilities.mjs +58 -0
- package/scripts/runtime/dateUtilities/dateConstraints.mjs +11 -0
- package/scripts/runtime/dateUtilities/dateFormatter.mjs +104 -0
- package/scripts/runtime/dateUtilities/dateUtilities.mjs +218 -0
- package/scripts/runtime/dateUtilities/index.mjs +26 -0
- package/scripts/runtime/dependencyTagVersioning.mjs +42 -0
- package/scripts/runtime/floatingUI.mjs +646 -0
- package/scripts/test-plugin/iterateWithA11Check.mjs +82 -0
- package/scripts/utils/auroFileHandler.mjs +70 -0
- package/scripts/utils/auroLibraryUtils.mjs +206 -0
- package/scripts/utils/auroTemplateFiller.mjs +178 -0
- package/scripts/utils/logger.mjs +73 -0
- package/scripts/utils/runtimeUtils.mjs +70 -0
- package/scripts/utils/sharedFileProcessorUtils.mjs +270 -0
- package/shellScripts/README.md +58 -0
- package/shellScripts/automation.sh +104 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { fixture, html, expect, elementUpdated } from '@open-wc/testing';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
isFocusableComponent,
|
|
6
|
+
getFocusableElements
|
|
7
|
+
} from '../Focusables.mjs';
|
|
8
|
+
|
|
9
|
+
describe('isFocusableComponent', () => {
|
|
10
|
+
it('returns true for enabled custom focusable components', async () => {
|
|
11
|
+
for (const tag of [
|
|
12
|
+
'auro-checkbox', 'auro-radio', 'auro-dropdown', 'auro-button', 'auro-combobox',
|
|
13
|
+
'auro-input', 'auro-counter', 'auro-select', 'auro-datepicker',
|
|
14
|
+
'auro-hyperlink', 'auro-accordion'
|
|
15
|
+
]) {
|
|
16
|
+
const el = document.createElement(tag);
|
|
17
|
+
if (tag === 'auro-hyperlink') {
|
|
18
|
+
el.setAttribute('href', '#');
|
|
19
|
+
}
|
|
20
|
+
document.body.appendChild(el);
|
|
21
|
+
expect(isFocusableComponent(el)).to.be.true;
|
|
22
|
+
el.remove();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('returns false for custom components with disabled attribute', async () => {
|
|
27
|
+
for (const tag of [
|
|
28
|
+
'auro-checkbox', 'auro-radio', 'auro-dropdown', 'auro-button', 'auro-combobox',
|
|
29
|
+
'auro-input', 'auro-counter', 'auro-select', 'auro-datepicker',
|
|
30
|
+
'auro-hyperlink', 'auro-accordion'
|
|
31
|
+
]) {
|
|
32
|
+
const el = document.createElement(tag);
|
|
33
|
+
el.setAttribute('disabled', '');
|
|
34
|
+
if (tag === 'auro-hyperlink') {
|
|
35
|
+
el.setAttribute('href', '#');
|
|
36
|
+
}
|
|
37
|
+
document.body.appendChild(el);
|
|
38
|
+
expect(isFocusableComponent(el)).to.be.false;
|
|
39
|
+
el.remove();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('returns false for auro-hyperlink without href', async () => {
|
|
44
|
+
const el = document.createElement('auro-hyperlink');
|
|
45
|
+
document.body.appendChild(el);
|
|
46
|
+
expect(isFocusableComponent(el)).to.be.false;
|
|
47
|
+
el.remove();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns false for non-custom elements', async () => {
|
|
51
|
+
const el = document.createElement('div');
|
|
52
|
+
document.body.appendChild(el);
|
|
53
|
+
expect(isFocusableComponent(el)).to.be.false;
|
|
54
|
+
el.remove();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('getFocusableElements', () => {
|
|
59
|
+
it('finds standard focusable elements', async () => {
|
|
60
|
+
const el = await fixture(html`
|
|
61
|
+
<div>
|
|
62
|
+
<button id="btn"></button>
|
|
63
|
+
<input id="input">
|
|
64
|
+
<a id="link" href="#"></a>
|
|
65
|
+
<textarea id="ta"></textarea>
|
|
66
|
+
<select id="sel"></select>
|
|
67
|
+
</div>
|
|
68
|
+
`);
|
|
69
|
+
const focusables = getFocusableElements(el);
|
|
70
|
+
expect(focusables.map(e => e.id)).to.include.members(['btn', 'input', 'link', 'ta', 'sel']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('skips disabled elements', async () => {
|
|
74
|
+
const el = await fixture(html`
|
|
75
|
+
<div>
|
|
76
|
+
<button id="btn" disabled></button>
|
|
77
|
+
<input id="input" disabled>
|
|
78
|
+
<textarea id="ta" disabled></textarea>
|
|
79
|
+
<select id="sel" disabled></select>
|
|
80
|
+
</div>
|
|
81
|
+
`);
|
|
82
|
+
const focusables = getFocusableElements(el);
|
|
83
|
+
expect(focusables.length).to.equal(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('finds custom focusable components', async () => {
|
|
87
|
+
const el = await fixture(html`
|
|
88
|
+
<div>
|
|
89
|
+
<auro-checkbox id="cb"></auro-checkbox>
|
|
90
|
+
<auro-hyperlink id="hl" href="#"></auro-hyperlink>
|
|
91
|
+
<auro-button id="ab"></auro-button>
|
|
92
|
+
</div>
|
|
93
|
+
`);
|
|
94
|
+
const focusables = getFocusableElements(el);
|
|
95
|
+
expect(focusables.map(e => e.id)).to.include.members(['cb', 'hl', 'ab']);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('skips disabled custom components', async () => {
|
|
99
|
+
const el = await fixture(html`
|
|
100
|
+
<div>
|
|
101
|
+
<auro-checkbox id="cb" disabled></auro-checkbox>
|
|
102
|
+
<auro-hyperlink id="hl" disabled href="#"></auro-hyperlink>
|
|
103
|
+
</div>
|
|
104
|
+
`);
|
|
105
|
+
const focusables = getFocusableElements(el);
|
|
106
|
+
expect(focusables.length).to.equal(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('finds elements in shadow DOM', async () => {
|
|
110
|
+
class ShadowEl extends HTMLElement {
|
|
111
|
+
constructor() {
|
|
112
|
+
super();
|
|
113
|
+
this.attachShadow({ mode: 'open' });
|
|
114
|
+
}
|
|
115
|
+
connectedCallback() {
|
|
116
|
+
this.shadowRoot.innerHTML = `<button id="shadowBtn"></button>`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
customElements.define('shadow-el', ShadowEl);
|
|
120
|
+
const el = await fixture(html`
|
|
121
|
+
<div>
|
|
122
|
+
<shadow-el id="host"></shadow-el>
|
|
123
|
+
</div>
|
|
124
|
+
`);
|
|
125
|
+
await elementUpdated(el);
|
|
126
|
+
const focusables = getFocusableElements(el);
|
|
127
|
+
// Should find the button inside shadow DOM
|
|
128
|
+
const shadowBtn = el.querySelector('shadow-el').shadowRoot.getElementById('shadowBtn');
|
|
129
|
+
expect(focusables).to.include(shadowBtn);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('finds elements assigned to slots', async () => {
|
|
133
|
+
class SlotEl extends HTMLElement {
|
|
134
|
+
constructor() {
|
|
135
|
+
super();
|
|
136
|
+
this.attachShadow({ mode: 'open' });
|
|
137
|
+
}
|
|
138
|
+
connectedCallback() {
|
|
139
|
+
this.shadowRoot.innerHTML = `<slot></slot>`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
customElements.define('slot-el', SlotEl);
|
|
143
|
+
const el = await fixture(html`
|
|
144
|
+
<slot-el>
|
|
145
|
+
<button id="slottedBtn"></button>
|
|
146
|
+
</slot-el>
|
|
147
|
+
`);
|
|
148
|
+
await elementUpdated(el);
|
|
149
|
+
const focusables = getFocusableElements(el);
|
|
150
|
+
const slottedBtn = el.querySelector('#slottedBtn');
|
|
151
|
+
expect(focusables).to.include(slottedBtn);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('does not return duplicates', async () => {
|
|
155
|
+
// This is a contrived case, but let's check that duplicates are not returned
|
|
156
|
+
const el = await fixture(html`
|
|
157
|
+
<div>
|
|
158
|
+
<button id="btn"></button>
|
|
159
|
+
</div>
|
|
160
|
+
`);
|
|
161
|
+
const focusables = getFocusableElements(el);
|
|
162
|
+
// Should only have one instance of the button
|
|
163
|
+
expect(focusables.filter(e => e.id === 'btn').length).to.equal(1);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DATE_UTIL_CONSTRAINTS } from "./dateConstraints.mjs";
|
|
2
|
+
|
|
3
|
+
export class AuroDateUtilitiesBase {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description The maximum day value allowed by the various utilities in this class.
|
|
7
|
+
* @readonly
|
|
8
|
+
* @type {Number}
|
|
9
|
+
*/
|
|
10
|
+
get maxDay() {
|
|
11
|
+
return DATE_UTIL_CONSTRAINTS.maxDay;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @description The maximum month value allowed by the various utilities in this class.
|
|
16
|
+
* @readonly
|
|
17
|
+
* @type {Number}
|
|
18
|
+
*/
|
|
19
|
+
get maxMonth() {
|
|
20
|
+
return DATE_UTIL_CONSTRAINTS.maxMonth;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @description The maximum year value allowed by the various utilities in this class.
|
|
25
|
+
* @readonly
|
|
26
|
+
* @type {Number}
|
|
27
|
+
*/
|
|
28
|
+
get maxYear() {
|
|
29
|
+
return DATE_UTIL_CONSTRAINTS.maxYear;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @description The minimum day value allowed by the various utilities in this class.
|
|
34
|
+
* @readonly
|
|
35
|
+
* @type {Number}
|
|
36
|
+
*/
|
|
37
|
+
get minDay() {
|
|
38
|
+
return DATE_UTIL_CONSTRAINTS.minDay;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description The minimum month value allowed by the various utilities in this class.
|
|
43
|
+
* @readonly
|
|
44
|
+
* @type {Number}
|
|
45
|
+
*/
|
|
46
|
+
get minMonth() {
|
|
47
|
+
return DATE_UTIL_CONSTRAINTS.minMonth;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description The minimum year value allowed by the various utilities in this class.
|
|
52
|
+
* @readonly
|
|
53
|
+
* @type {Number}
|
|
54
|
+
*/
|
|
55
|
+
get minYear() {
|
|
56
|
+
return DATE_UTIL_CONSTRAINTS.minYear;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
class DateFormatter {
|
|
2
|
+
|
|
3
|
+
constructor() {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description Parses a date string into its components.
|
|
7
|
+
* @param {string} dateStr - Date string to parse.
|
|
8
|
+
* @param {string} format - Date format to parse.
|
|
9
|
+
* @returns {Object<key["month" | "day" | "year"]: number>|undefined}
|
|
10
|
+
*/
|
|
11
|
+
this.parseDate = (dateStr, format = 'mm/dd/yyyy') => {
|
|
12
|
+
|
|
13
|
+
// Guard Clause: Date string is defined
|
|
14
|
+
if (!dateStr) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Assume the separator is a "/" a defined in our code base
|
|
19
|
+
const separator = '/';
|
|
20
|
+
|
|
21
|
+
// Get the parts of the date and format
|
|
22
|
+
const valueParts = dateStr.split(separator);
|
|
23
|
+
const formatParts = format.split(separator);
|
|
24
|
+
|
|
25
|
+
// Check if the value and format have the correct number of parts
|
|
26
|
+
if (valueParts.length !== formatParts.length) {
|
|
27
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Date string and format length do not match');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Holds the result to be returned
|
|
31
|
+
const result = formatParts.reduce((acc, part, index) => {
|
|
32
|
+
const value = valueParts[index];
|
|
33
|
+
|
|
34
|
+
if ((/m/iu).test(part)) {
|
|
35
|
+
acc.month = value;
|
|
36
|
+
} else if ((/d/iu).test(part)) {
|
|
37
|
+
acc.day = value;
|
|
38
|
+
} else if ((/y/iu).test(part)) {
|
|
39
|
+
acc.year = value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
|
|
45
|
+
// If we found all the parts, return the result
|
|
46
|
+
if (result.month && result.year) {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Throw an error to let the dev know we were unable to parse the date string
|
|
51
|
+
throw new Error('AuroDatepickerUtilities | parseDate: Unable to parse date string');
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Convert a date object to string format.
|
|
56
|
+
* @param {Object} date - Date to convert to string.
|
|
57
|
+
* @param {String} locale - Optional locale to use for the date string. Defaults to user's locale.
|
|
58
|
+
* @returns {String} Returns the date as a string.
|
|
59
|
+
*/
|
|
60
|
+
this.getDateAsString = (date, locale = undefined) => date.toLocaleDateString(locale, {
|
|
61
|
+
year: "numeric",
|
|
62
|
+
month: "2-digit",
|
|
63
|
+
day: "2-digit",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Converts a date string to a North American date format.
|
|
68
|
+
* @param {String} dateStr - Date to validate.
|
|
69
|
+
* @param {String} format - Date format to validate against.
|
|
70
|
+
* @returns {Boolean}
|
|
71
|
+
*/
|
|
72
|
+
this.toNorthAmericanFormat = (dateStr, format) => {
|
|
73
|
+
|
|
74
|
+
if (format === 'mm/dd/yyyy') {
|
|
75
|
+
return dateStr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const parsedDate = this.parseDate(dateStr, format);
|
|
79
|
+
|
|
80
|
+
if (!parsedDate) {
|
|
81
|
+
throw new Error('AuroDatepickerUtilities | toNorthAmericanFormat: Unable to parse date string');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { month, day, year } = parsedDate;
|
|
85
|
+
|
|
86
|
+
const dateParts = [];
|
|
87
|
+
if (month) {
|
|
88
|
+
dateParts.push(month);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (day) {
|
|
92
|
+
dateParts.push(day);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (year) {
|
|
96
|
+
dateParts.push(year);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return dateParts.join('/');
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const dateFormatter = new DateFormatter();
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
import { AuroDateUtilitiesBase } from "./baseDateUtilities.mjs";
|
|
3
|
+
import { dateFormatter } from "./dateFormatter.mjs";
|
|
4
|
+
|
|
5
|
+
export class AuroDateUtilities extends AuroDateUtilitiesBase {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the current century.
|
|
9
|
+
* @returns {String} The current century.
|
|
10
|
+
*/
|
|
11
|
+
getCentury () {
|
|
12
|
+
return String(new Date().getFullYear()).slice(0, 2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns a four digit year.
|
|
17
|
+
* @param {String} year - The year to convert to four digits.
|
|
18
|
+
* @returns {String} The four digit year.
|
|
19
|
+
*/
|
|
20
|
+
getFourDigitYear (year) {
|
|
21
|
+
|
|
22
|
+
const strYear = String(year).trim();
|
|
23
|
+
return strYear.length <= 2 ? this.getCentury() + strYear : strYear;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
|
|
28
|
+
super();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compares two dates to see if they match.
|
|
32
|
+
* @param {Object} date1 - First date to compare.
|
|
33
|
+
* @param {Object} date2 - Second date to compare.
|
|
34
|
+
* @returns {Boolean} Returns true if the dates match.
|
|
35
|
+
*/
|
|
36
|
+
this.datesMatch = (date1, date2) => new Date(date1).getTime() === new Date(date2).getTime();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if value passed in is a valid date.
|
|
40
|
+
* @param {String} date - Date to validate.
|
|
41
|
+
* @param {String} format - Date format to validate against.
|
|
42
|
+
* @returns {Boolean}
|
|
43
|
+
*/
|
|
44
|
+
this.validDateStr = (date, format) => {
|
|
45
|
+
|
|
46
|
+
// The length we expect the date string to be
|
|
47
|
+
const dateStrLength = format.length;
|
|
48
|
+
|
|
49
|
+
// Guard Clause: Date and format are defined
|
|
50
|
+
if (typeof date === "undefined" || typeof format === "undefined") {
|
|
51
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date and format are required');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Guard Clause: Date should be of type string
|
|
55
|
+
if (typeof date !== "string") {
|
|
56
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Date must be a string');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Guard Clause: Format should be of type string
|
|
60
|
+
if (typeof format !== "string") {
|
|
61
|
+
throw new Error('AuroDatepickerUtilities | validateDateStr: Format must be a string');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Guard Clause: Length is what we expect it to be
|
|
65
|
+
if (date.length !== dateStrLength) {
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Get a formatted date string and parse it
|
|
70
|
+
const dateParts = dateFormatter.parseDate(date, format);
|
|
71
|
+
|
|
72
|
+
// Guard Clause: Date parse succeeded
|
|
73
|
+
if (!dateParts) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Create the expected date string based on the date parts
|
|
78
|
+
const expectedDateStr = `${dateParts.month}/${dateParts.day || "01"}/${this.getFourDigitYear(dateParts.year)}`;
|
|
79
|
+
|
|
80
|
+
// Generate a date object that we will extract a string date from to compare to the passed in date string
|
|
81
|
+
const dateObj = new Date(this.getFourDigitYear(dateParts.year), dateParts.month - 1, dateParts.day || 1);
|
|
82
|
+
|
|
83
|
+
// Get the date string of the date object we created from the string date
|
|
84
|
+
const actualDateStr = dateFormatter.getDateAsString(dateObj, "en-US");
|
|
85
|
+
|
|
86
|
+
// Guard Clause: Generated date matches date string input
|
|
87
|
+
if (expectedDateStr !== actualDateStr) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// If we passed all other checks, we can assume the date is valid
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Determines if a string date value matches the format provided.
|
|
97
|
+
* @param {string} value = The date string value.
|
|
98
|
+
* @param { string} format = The date format to match against.
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
this.dateAndFormatMatch = (value, format) => {
|
|
102
|
+
|
|
103
|
+
// Ensure we have both values we need to do the comparison
|
|
104
|
+
if (!value || !format) {
|
|
105
|
+
throw new Error('AuroFormValidation | dateFormatMatch: value and format are required');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// If the lengths are different, they cannot match
|
|
109
|
+
if (value.length !== format.length) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get the parts of the date
|
|
114
|
+
const dateParts = dateFormatter.parseDate(value, format);
|
|
115
|
+
|
|
116
|
+
// Validator for day
|
|
117
|
+
const dayValueIsValid = (day) => {
|
|
118
|
+
|
|
119
|
+
// Guard clause: if there is no day in the dateParts, we can ignore this check.
|
|
120
|
+
if (!dateParts.day) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Guard clause: ensure day exists.
|
|
125
|
+
if (!day) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Convert day to number
|
|
130
|
+
const numDay = Number.parseInt(day, 10);
|
|
131
|
+
|
|
132
|
+
// Guard clause: ensure day is a valid integer
|
|
133
|
+
if (Number.isNaN(numDay)) {
|
|
134
|
+
throw new Error('AuroDatepickerUtilities | dayValueIsValid: Unable to parse day value integer');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Guard clause: ensure day is within the valid range
|
|
138
|
+
if (numDay < this.minDay || numDay > this.maxDay) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Default return
|
|
143
|
+
return true;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Validator for month
|
|
147
|
+
const monthValueIsValid = (month) => {
|
|
148
|
+
|
|
149
|
+
// Guard clause: ensure month exists.
|
|
150
|
+
if (!month) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Convert month to number
|
|
155
|
+
const numMonth = Number.parseInt(month, 10);
|
|
156
|
+
|
|
157
|
+
// Guard clause: ensure month is a valid integer
|
|
158
|
+
if (Number.isNaN(numMonth)) {
|
|
159
|
+
throw new Error('AuroDatepickerUtilities | monthValueIsValid: Unable to parse month value integer');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Guard clause: ensure month is within the valid range
|
|
163
|
+
if (numMonth < this.minMonth || numMonth > this.maxMonth) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Default return
|
|
168
|
+
return true;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Validator for year
|
|
172
|
+
const yearIsValid = (_year) => {
|
|
173
|
+
|
|
174
|
+
// Guard clause: ensure year exists.
|
|
175
|
+
if (!_year) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Get the full year
|
|
180
|
+
const year = this.getFourDigitYear(_year);
|
|
181
|
+
|
|
182
|
+
// Convert year to number
|
|
183
|
+
const numYear = Number.parseInt(year, 10);
|
|
184
|
+
|
|
185
|
+
// Guard clause: ensure year is a valid integer
|
|
186
|
+
if (Number.isNaN(numYear)) {
|
|
187
|
+
throw new Error('AuroDatepickerUtilities | yearValueIsValid: Unable to parse year value integer');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Guard clause: ensure year is within the valid range
|
|
191
|
+
if (numYear < this.minYear || numYear > this.maxYear) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Default return
|
|
196
|
+
return true;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// Self-contained checks for month, day, and year
|
|
200
|
+
const checks = [
|
|
201
|
+
monthValueIsValid(dateParts.month),
|
|
202
|
+
dayValueIsValid(dateParts.day),
|
|
203
|
+
yearIsValid(dateParts.year)
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
// If any of the checks failed, the date format does not match and the result is invalid
|
|
207
|
+
const isValid = checks.every((check) => check === true);
|
|
208
|
+
|
|
209
|
+
// If the check is invalid, return false
|
|
210
|
+
if (!isValid) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Default case
|
|
215
|
+
return true;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { dateFormatter } from './dateFormatter.mjs';
|
|
2
|
+
import { AuroDateUtilities } from './dateUtilities.mjs';
|
|
3
|
+
|
|
4
|
+
export { AuroDateUtilities } from './dateUtilities.mjs';
|
|
5
|
+
|
|
6
|
+
// Export a class instance
|
|
7
|
+
export const dateUtilities = new AuroDateUtilities();
|
|
8
|
+
|
|
9
|
+
// Export the class instance methods individually
|
|
10
|
+
export const {
|
|
11
|
+
datesMatch,
|
|
12
|
+
validDateStr,
|
|
13
|
+
dateAndFormatMatch,
|
|
14
|
+
minDay,
|
|
15
|
+
minMonth,
|
|
16
|
+
minYear,
|
|
17
|
+
maxDay,
|
|
18
|
+
maxMonth,
|
|
19
|
+
maxYear
|
|
20
|
+
} = dateUtilities;
|
|
21
|
+
|
|
22
|
+
export const {
|
|
23
|
+
toNorthAmericanFormat,
|
|
24
|
+
parseDate,
|
|
25
|
+
getDateAsString
|
|
26
|
+
} = dateFormatter;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
|
|
4
|
+
// ---------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
import { literal, unsafeStatic } from 'lit/static-html.js';
|
|
7
|
+
|
|
8
|
+
export class AuroDependencyVersioning {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates a unique string to be used for child auro element naming.
|
|
12
|
+
* @private
|
|
13
|
+
* @param {string} baseName - Defines the first part of the unique element name.
|
|
14
|
+
* @param {string} version - Version of the component that will be appended to the baseName.
|
|
15
|
+
* @returns {string} - Unique string to be used for naming.
|
|
16
|
+
*/
|
|
17
|
+
generateElementName(baseName, version) {
|
|
18
|
+
let result = baseName;
|
|
19
|
+
|
|
20
|
+
result += '-';
|
|
21
|
+
result += version.replace(/[.]/g, '_');
|
|
22
|
+
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generates a unique string to be used for child auro element naming.
|
|
28
|
+
* @param {string} baseName - Defines the first part of the unique element name.
|
|
29
|
+
* @param {string} version - Version of the component that will be appended to the baseName.
|
|
30
|
+
* @returns {string} - Unique string to be used for naming.
|
|
31
|
+
*/
|
|
32
|
+
generateTag(baseName, version, tagClass) {
|
|
33
|
+
const elementName = this.generateElementName(baseName, version);
|
|
34
|
+
const tag = literal`${unsafeStatic(elementName)}`;
|
|
35
|
+
|
|
36
|
+
if (!customElements.get(elementName)) {
|
|
37
|
+
customElements.define(elementName, class extends tagClass {});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return tag;
|
|
41
|
+
}
|
|
42
|
+
}
|