From 7a416ad8eece56cf67ef403fec7845ef4142494a Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 19 Jan 2025 23:40:42 -0800 Subject: [PATCH] Simplify with early returns --- src/core.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index b3a4c40..94c47d8 100644 --- a/src/core.js +++ b/src/core.js @@ -13,20 +13,18 @@ import { fileURLToPath } from 'node:url'; * @throws {TypeError} If `path` is not a `string`, `Buffer`, or `URL`, or it is a `URL` that is not using the `file` schema. */ export function parsePathLike(path) { - let parsedPath; if (typeof path === 'string') { - parsedPath = normalize(path); + return normalize(path); } else if (ArrayBuffer.isView(path) || path instanceof ArrayBuffer) { - parsedPath = normalize(new TextDecoder().decode(path)); + return normalize(new TextDecoder().decode(path)); } else if (path instanceof URL) { - parsedPath = fileURLToPath(path); + return fileURLToPath(path); } else { throw new TypeError(`Expected a string, Buffer, or URL, but received ${typeof path}.`); } - return parsedPath; } /** -- 2.47.3