From f4a9e82f4b57858ccb8a830ab6c59edd8b20c90c Mon Sep 17 00:00:00 2001 From: cswimr Date: Sat, 8 Feb 2025 08:51:23 -0600 Subject: [PATCH] improve typing in resource class --- src/resource.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/resource.ts b/src/resource.ts index 4d7637d..681ea0d 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -5,11 +5,11 @@ import * as path from "path"; export default class Resource { constructor(public readonly path: string) {} - toString() { + toString(): string { return this.path; } - get isUrl() { + get isUrl(): boolean { try { new URL(this.path); return true; @@ -18,13 +18,13 @@ export default class Resource { } } - get name() { + get name(): string { return this.isUrl ? new URL(this.path).pathname.split("/").pop() || "" : path.basename(this.path); } - get parent() { + get parent(): Resource { if (this.isUrl) { const url = new URL(this.path); url.pathname = path.dirname(url.pathname); @@ -33,7 +33,7 @@ export default class Resource { return new Resource(path.dirname(this.path)); } - get ext() { + get ext(): string { return this.isUrl ? path.extname(new URL(this.path).pathname) : path.extname(this.path);