Skip to content

Commit

Permalink
fix(ls): Allow null value for options parameter
Browse files Browse the repository at this point in the history
This change addresses a type safety issue related to the `options` parameter in all `ls*` functions.

Signed-off-by: Ryuu Mitsuki <[email protected]>
  • Loading branch information
mitsuki31 committed Apr 20, 2024
2 parents 61748da + 61f9dba commit 6c8a65e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lsfnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6c8a65e

Please sign in to comment.