From f56e70f1a9028c2d14c59f833b73f44f2c7c4dd1 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 7 Jun 2025 20:42:00 -0700 Subject: [PATCH] Clarify type to allow raw `ArrayBuffer`, not just `TypedArray` --- src/core.js | 2 +- test/core.test.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 6c59a1a..60132d6 100644 --- a/src/core.js +++ b/src/core.js @@ -8,7 +8,7 @@ import { ReadableStream, WritableStream, TransformStream } from 'node:stream/web /** * Parse and normalize a `PathLike` object into a string. * - * @param {PathLike|ArrayBufferView} path A `string`, `Buffer`, or `URL` representing a path to a local file. + * @param {PathLike|ArrayBufferView|ArrayBuffer} path A `string`, `Buffer`, or `URL` representing a path to a local file. * @returns {string} The normalized file path in string form. * @throws {TypeError} If `path` is not a `string`, `Buffer`, or `URL`, or it is a `URL` that is not using the `file` schema. */ diff --git a/test/core.test.js b/test/core.test.js index 366c0b1..c709a79 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -31,8 +31,10 @@ suite('parsePathLike', { concurrency: true }, () => { const vectors = [ { name: 'parses string relative path', input: './folder/example.txt', output: './folder/example.txt' }, { name: 'parses string absolute path', input: '/absolute/path/to/file.txt', output: '/absolute/path/to/file.txt' }, - { name: 'parses Buffer relative path', input: new TextEncoder().encode('./folder/example.txt'), output: './folder/example.txt' }, - { name: 'parses Buffer absolute path', input: new TextEncoder().encode('/absolute/path/to/file.txt'), output: '/absolute/path/to/file.txt' }, + { name: 'parses TypedArray relative path', input: new TextEncoder().encode('./folder/example.txt'), output: './folder/example.txt' }, + { name: 'parses TypedArray absolute path', input: new TextEncoder().encode('/absolute/path/to/file.txt'), output: '/absolute/path/to/file.txt' }, + { name: 'parses Buffer relative path', input: new TextEncoder().encode('./folder/example.txt').buffer, output: './folder/example.txt' }, + { name: 'parses Buffer absolute path', input: new TextEncoder().encode('/absolute/path/to/file.txt').buffer, output: '/absolute/path/to/file.txt' }, { name: 'parses URL relative path', input: pathToFileURL('./folder/example.txt'), output: resolve('./folder/example.txt') }, // Must use resolve because URLs automatically resolve to absolute path { name: 'parses URL absolute path', input: pathToFileURL('/absolute/path/to/file.txt'), output: resolve('/absolute/path/to/file.txt') }, { name: 'parses URL with percent-encoding', input: pathToFileURL('./folder/example%20chars.txt'), output: resolve('./folder/example%20chars.txt') }, -- 2.47.3