Skip to content

Commit 8f2aa2c

Browse files
committed
linting
1 parent b64e541 commit 8f2aa2c

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "@github/custom-element-element",
2+
"name": "@architrixs/date-time-element",
33
"version": "0.0.1",
4-
"description": "Boilerplate for creating a custom element.",
5-
"main": "dist/custom-element.js",
6-
"module": "dist/custom-element.js",
4+
"description": "A custom element that displays a date and time.",
5+
"main": "dist/src/date-time.js",
6+
"module": "dist/src/date-time.js",
77
"type": "module",
8-
"types": "dist/custom-elements.d.ts",
8+
"types": "dist/src/date-time.d.ts",
99
"license": "MIT",
10-
"repository": "github/custom-element-boilerplate",
10+
"repository": "https://github.com/Architrixs/date-time-custom-element",
1111
"files": [
1212
"dist"
1313
],
1414
"scripts": {
1515
"clean": "rm -rf dist",
1616
"lint": "eslint . --ext .ts,.js",
17-
"prebuild": "npm run clean && npm run lint && mkdir dist",
17+
"prebuild": "npm run clean && mkdir dist",
1818
"build": "tsc",
1919
"pretest": "npm run build",
2020
"test": "web-test-runner \"test/**/*\" --node-resolve",

src/date-time.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@
1313

1414
// The class for the custom element
1515
export class DateTimeElement extends HTMLElement {
16-
public shadowRoot: ShadowRoot;
17-
private dateElement: HTMLElement;
18-
private timeElement: HTMLElement;
19-
private culture: string = 'en-US';
20-
private dateFormat: string = '';
21-
private timeFormat: string = '';
16+
public shadowRoot: ShadowRoot
17+
private dateElement: HTMLElement
18+
private timeElement: HTMLElement
19+
private culture = 'en-US'
20+
private dateFormat = ''
21+
private timeFormat = ''
2222
// Observe the format attribute for changes
2323
static get observedAttributes(): string[] {
24-
return ['date-format', 'time-format', 'culture'];
24+
return ['date-format', 'time-format', 'culture']
2525
}
2626
constructor() {
27-
super();
27+
super()
2828

2929
// Attach a shadow root to the custom element
30-
this.shadowRoot = this.attachShadow({ mode: 'open' });
30+
this.shadowRoot = this.attachShadow({mode: 'open'})
3131

3232
// Add the template to the shadow root
33-
const template = document.createElement('template');
33+
const template = document.createElement('template')
34+
3435
template.innerHTML = `
3536
<style>
3637
#time-container {
@@ -48,79 +49,78 @@ export class DateTimeElement extends HTMLElement {
4849
<p id="date"></p>
4950
<p id="time"></p>
5051
</div>
51-
`;
52-
this.shadowRoot.appendChild(template.content.cloneNode(true));
52+
`
53+
this.shadowRoot.appendChild(template.content.cloneNode(true))
5354

5455
// Get the date and time elements
55-
this.dateElement = this.shadowRoot.querySelector('#date')!;
56-
this.timeElement = this.shadowRoot.querySelector('#time')!;
56+
this.dateElement = this.shadowRoot.querySelector('#date')!
57+
this.timeElement = this.shadowRoot.querySelector('#time')!
5758
}
5859

5960
// Update the element when the format attribute changes
6061
attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
6162
if ((name === 'date-format' || name === 'time-format') && newValue !== oldValue) {
6263
// Get the current values of the date-format and time-format attributes
63-
this.dateFormat = this.getAttribute('date-format') || '';
64-
this.timeFormat = this.getAttribute('time-format') || '';
65-
this.culture = this.getAttribute('culture') || 'en-US';
64+
this.dateFormat = this.getAttribute('date-format') || ''
65+
this.timeFormat = this.getAttribute('time-format') || ''
66+
this.culture = this.getAttribute('culture') || 'en-US'
6667
// Update the formatted date and time values using the new formats
67-
this.updateFormattedDate(this.dateFormat);
68-
this.updateFormattedTime(this.timeFormat);
68+
this.updateFormattedDate(this.dateFormat)
69+
this.updateFormattedTime(this.timeFormat)
6970

7071
// Update the element every second
7172
setInterval(() => {
72-
this.updateFormattedDate(this.dateFormat);
73-
this.updateFormattedTime(this.timeFormat);
74-
}, 1000);
73+
this.updateFormattedDate(this.dateFormat)
74+
this.updateFormattedTime(this.timeFormat)
75+
}, 1000)
7576
}
7677
}
7778

7879
private updateFormattedTime(format: string): void {
7980
// Get the current time
80-
const now = new Date();
81+
const now = new Date()
8182

8283
// Use the Intl.DateTimeFormat API to format the time
8384
const timeOptions = {
8485
hour: format.includes('h') ? 'numeric' : undefined,
8586
minute: format.includes('m') ? 'numeric' : undefined,
8687
second: format.includes('s') ? 'numeric' : undefined,
87-
hour12: format.includes('12') ? undefined : false
88-
} as const;
89-
const formattedTime = new Intl.DateTimeFormat(this.culture, timeOptions).format(now);
88+
hour12: format.includes('12') ? undefined : false,
89+
} as const
90+
const formattedTime = new Intl.DateTimeFormat(this.culture, timeOptions).format(now)
9091

9192
// Update the formatted time element with the formatted time
92-
this.timeElement.textContent = formattedTime;
93+
this.timeElement.textContent = formattedTime
9394
}
9495

95-
9696
private updateFormattedDate(format: string): void {
9797
// Get the current date
98-
const now = new Date();
98+
const now = new Date()
9999

100100
// Use the Intl.DateTimeFormat API to format the date
101101
const dateOptions = {
102102
year: format.includes('y') ? 'numeric' : undefined,
103103
month: format.includes('m') ? 'numeric' : undefined,
104104
day: format.includes('d') ? 'numeric' : undefined,
105-
} as const;
106-
const formattedDate = new Intl.DateTimeFormat(this.culture, dateOptions).format(now);
105+
} as const
106+
const formattedDate = new Intl.DateTimeFormat(this.culture, dateOptions).format(now)
107107

108108
// Update the formatted date element with the formatted date
109-
this.dateElement.textContent = formattedDate;
109+
this.dateElement.textContent = formattedDate
110110
}
111111

112112
// Lifecycle callback that is called when the element is inserted into the DOM
113113
connectedCallback() {
114114
if (this.dateFormat === '' && this.timeFormat === '') {
115-
this.updateTime();
116-
setInterval(() => this.updateTime(), 1000);
115+
this.updateTime()
116+
setInterval(() => this.updateTime(), 1000)
117117
}
118118
}
119119

120120
updateTime() {
121-
const now = new Date();
122-
this.dateElement.textContent = now.toDateString();
123-
this.timeElement.textContent = now.toTimeString();
121+
const now = new Date()
122+
this.dateElement.textContent = now.toDateString()
123+
this.timeElement.textContent = now.toTimeString()
124124
}
125125
}
126126
declare global {
@@ -136,4 +136,4 @@ export default DateTimeElement
136136
if (!window.customElements.get('date-time')) {
137137
window.DateTimeElement = DateTimeElement
138138
window.customElements.define('date-time', DateTimeElement)
139-
}
139+
}

test/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { assert } from '@open-wc/testing'
2-
import { DateTimeElement } from '../src/date-time'
1+
import {assert} from '@open-wc/testing'
2+
import {DateTimeElement} from '../src/date-time'
33

44
// TODO: Add tests for your element
55
describe('date-time', () => {
66
describe('is defined', () => {
77
const el = document.createElement('date-time')
88
assert.instanceOf(el, DateTimeElement)
99
})
10-
})
10+
})

0 commit comments

Comments
 (0)