Skip to content

Commit

Permalink
safeOpts added
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzitelli committed Feb 24, 2023
1 parent 8f2cb4e commit f7c1e1e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/help.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {BaseOptions, BaseOptionsProps} from './types';

export const safeOpts =
(opts: BaseOptions<any> | BaseOptions<any>[]) => (props: BaseOptionsProps) => {
if (Array.isArray(opts)) {
let all_opts = {};
for (const opt of opts) {
all_opts = {
...all_opts,
...safeOpts(opt)(props),
};
}
return all_opts;
}

return typeof opts === 'function' ? opts(props) : opts;
};

0 comments on commit f7c1e1e

Please sign in to comment.