and

Performs a logical AND operation on the given arguments.

1.
/**
2.
* Performs a logical AND operation on the given arguments.
3.
**/
4.
const and = (...args: unknown[]) => {
5.
if (args.length === 0) return false;
6.
return args.every((arg) => Boolean(arg));
7.
};
8.
9.
export default and;

1. Installtion

npx @jrtilak/lazykit add and

2. Parameters

  • ...args (unknown[])
    A variable number of arguments to evaluate in the logical AND operation.

3. Returns

  • boolean
    Returns true if all arguments are truthy; otherwise, returns false.

4. Usage

1.
import and from "@/helpers/and";
2.
3.
console.log(and(true, true));
4.
// Expected Output: true
5.
6.
console.log(and(true, false));
7.
// Expected Output: false
8.
9.
console.log(and());
10.
// Expected Output: false
11.
12.
console.log(and(1, "lazykit"));
13.
// Expected Output: true