From 9268ccbd5112c9b1973d01a21cbb423472a42d60 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 22 Jul 2022 20:37:18 -0400 Subject: [PATCH] fix(striker-ui): create function based on condition(s) --- striker-ui/lib/createFunction.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 striker-ui/lib/createFunction.ts diff --git a/striker-ui/lib/createFunction.ts b/striker-ui/lib/createFunction.ts new file mode 100644 index 00000000..9515b498 --- /dev/null +++ b/striker-ui/lib/createFunction.ts @@ -0,0 +1,16 @@ +const createFunction = ( + { + conditionFn = () => true, + str = '', + condition = conditionFn() && str.length === 0, + }: { + condition?: boolean; + conditionFn?: (...args: unknown[]) => boolean; + str?: string; + }, + fn: () => unknown, + ...fnArgs: Parameters +): (() => unknown) | undefined => + condition ? fn.bind(null, ...fnArgs) : undefined; + +export default createFunction;