From 61f9dba3f5536063b3c737c26ff0c01eaa2f1999 Mon Sep 17 00:00:00 2001 From: Ryuu Mitsuki Date: Sat, 20 Apr 2024 10:06:05 +0700 Subject: [PATCH] fix: Fix the `options` parameter non-nullable Previously, the `options` parameter of all `ls*` functions cannot passed as `null`, instead it should use `undefined` or an empty object (`{}`). This change is here to address the issue, and the `options` parameter can now be passed either with `null` or `undefined` as the value. --- src/lsfnd.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lsfnd.ts b/src/lsfnd.ts index 260c69d..9824bfa 100644 --- a/src/lsfnd.ts +++ b/src/lsfnd.ts @@ -173,18 +173,19 @@ export async function ls( match = options; exclude = undefined; options = { encoding: 'utf8', recursive: false }; - } else if (typeof options === 'object') { + } else if (typeof options === 'undefined' || options === null) { + options = { encoding: 'utf8', recursive: false }; + match = /.+/; + } else if (options && typeof options === 'object' && !Array.isArray(options)) { match = (typeof options!.match === 'string') ? new RegExp(options!.match) : (isRegExp(options!.match) ? options!.match : /.+/); exclude = (typeof options!.exclude === 'string') ? new RegExp(options!.exclude) : (isRegExp(options!.exclude) ? options!.exclude : undefined); - } else if (typeof options === 'undefined' || options === null) { - options = { encoding: 'utf8', recursive: false }; - match = /.+/; } else { - throw new TypeError('Unknown type of "options": ' + typeof options); + throw new TypeError('Unknown type of "options": ' + + (Array.isArray(options) ? 'array' : typeof options)); } let result: LsResult = null;