-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pluginutils): Use readonly arrays, add TSDoc (#187)
- Loading branch information
Showing
4 changed files
with
68 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
export default function ensureArray<T>(thing: Array<T> | T | undefined | null): Array<T> { | ||
if (Array.isArray(thing)) return thing; | ||
if (thing == undefined) return []; // eslint-disable-line no-undefined, eqeqeq | ||
// Helper since Typescript can't detect readonly arrays with Array.isArray | ||
function isArray(arg: unknown): arg is any[] | readonly any[] { | ||
return Array.isArray(arg); | ||
} | ||
|
||
export default function ensureArray<T>(thing: readonly T[] | T | undefined | null): readonly T[] { | ||
if (isArray(thing)) return thing; | ||
if (thing == null) return []; | ||
return [thing]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters