Skip to content

Commit 5a4b84d

Browse files
committed
Modern syntax to import built-in node modules
1 parent c67dd8c commit 5a4b84d

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
"replacer-util": "~1.6",
110110
"rimraf": "~6.1",
111111
"run-scripts-util": "~1.3",
112-
"typescript": "~5.9",
113-
"typescript-eslint": "~8.57",
112+
"typescript": "~6.0",
113+
"typescript-eslint": "~8.58",
114114
"uglify-js": "~3.19",
115115
"w3c-html-validator": "~2.2"
116116
}

spec/package.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Imports
44
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
5-
import fs from 'fs';
5+
import fs from 'node:fs';
66

77
////////////////////////////////////////////////////////////////////////////////
88
describe('The "dist" folder', () => {

src/js/lib-x.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const libXDom = {
142142
hasClass(elems: LibXElems, className: string): boolean {
143143
// Returns true if any of the elements in the given list have the specified class.
144144
const elemHas = (elem: Element) => elem.classList.contains(className);
145-
return !!Array.prototype.some.call(elems, elemHas);
145+
return Array.prototype.some.call(elems, elemHas);
146146
},
147147
toggleClass(elem: Element, className: string, state?: boolean): Element {
148148
// Adds or removes an element class.
@@ -211,12 +211,12 @@ const libXDom = {
211211
},
212212
indexOf(elems: LibXElems, elem: Element): number {
213213
// Returns the location an element within an array of elements.
214-
return Number(Array.prototype.indexOf.call(elems, elem));
214+
return Array.prototype.indexOf.call(elems, elem);
215215
},
216216
findIndex(elems: LibXElems, selector: string): number {
217217
// Returns the location of the first matching element within an array of elements.
218218
const elemMatches = (elem: Element) => elem.matches(selector);
219-
return Number(Array.prototype.findIndex.call(elems, elemMatches));
219+
return Array.prototype.findIndex.call(elems, elemMatches);
220220
},
221221
isElem(elem: unknown): boolean {
222222
return !!elem && typeof elem === 'object' && !!(<Element>elem).nodeName;
@@ -656,24 +656,25 @@ const libXUi = {
656656
style.opacity = '0';
657657
if (globalThis.getComputedStyle(elem).display === 'none')
658658
style.display = 'block';
659-
const load = (done: (elem: Element) => void) => {
659+
const load = (done: (returnElem: Element) => void) => {
660+
console.log()
660661
const cleanup = () => {
661662
style.removeProperty('transition');
662663
style.removeProperty('opacity');
663664
done(elem);
664665
};
665666
const handleImgage = () => {
666667
if (elem.matches('img'))
667-
(<HTMLImageElement>elem).src = url;
668+
(<HTMLImageElement>elem).src = url; //eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion
668669
else
669670
style.backgroundImage = 'url("' + url + '")';
670671
style.transition = `all ${fadeTransition}ms`;
671672
style.opacity = '1';
672673
globalThis.setTimeout(cleanup, fadeTransition + 100);
673674
};
674-
const img = new Image();
675-
img.onload = handleImgage;
676-
img.src = url;
675+
const imgCache = new Image();
676+
imgCache.onload = handleImgage;
677+
imgCache.src = url;
677678
};
678679
return new Promise(resolve => load(resolve));
679680
},
@@ -838,7 +839,7 @@ const libXBrowser = {
838839
const polyfill = (): NavigatorUAData => {
839840
const brandEntry = globalThis.navigator.userAgent.split(' ').pop()?.split('/') ?? [];
840841
const hasTouch = !!navigator.maxTouchPoints;
841-
const platform = globalThis.navigator.platform; //eslint-disable-line @typescript-eslint/no-deprecated
842+
const platform = globalThis.navigator.platform;
842843
const mac = hasTouch ? 'iOS' : 'macOS';
843844
const platforms: { [platform: string]: string} =
844845
{ 'MacIntel': mac, 'Win32': 'Windows', 'iPhone': 'iOS', 'iPad': 'iOS' };

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"target": "ES2022",
1111
"module": "nodenext",
1212
"moduleResolution": "nodenext",
13+
"types": ["node"],
1314
"exactOptionalPropertyTypes": true,
1415
"forceConsistentCasingInFileNames": true,
1516
"noFallthroughCasesInSwitch": true,

0 commit comments

Comments
 (0)