All files / src/commands commandHooks.tsx

80% Statements 8/10
60% Branches 3/5
50% Functions 1/2
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18    8015x 8015x       8015x       8015x   8552x        
import { CommandBindpoint, useCommands } from "just-search-it";
 
function useHasCommand() {
  const commands = useCommands();
 
  return function commandExists<Args extends any[], ReturnType>(
    command: CommandBindpoint<Args, ReturnType>,
    ...args: Args
  ) {
    // TODO: replace this line with getCommandKey from just-search-it
    const commandKey =
      command.key + "." + args.map((arg) => arg?.toString() || "").join(".");
    return commands[commandKey] !== undefined;
  };
}
 
export { useHasCommand };