From: Ardis Lu Date: Mon, 20 Jan 2025 07:40:42 +0000 (-0800) Subject: Simplify with early returns X-Git-Tag: v0.1.0~104 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=7a416ad8eece56cf67ef403fec7845ef4142494a;p=csvio Simplify with early returns --- 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; } /**