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;