Skip to content

Commit

Permalink
fix: Fix the options parameter non-nullable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mitsuki31 committed Apr 20, 2024
1 parent 61748da commit 61f9dba
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 61f9dba

Please sign in to comment.