UNPKG

safers

Version:

Safely convert to the desired data and error-free refine values.

25 lines (24 loc) 859 B
/** * Checks if a value is included in an array or a single value. * * @param val - The value to be checked. * @param keywords - An array or a single value for validation. * @returns `true` if the value is included, otherwise `false`. * * @example * includes([1, 2, 3], 2); // true * includes([1, 2, 3], 4); // false * * includes([1, 2, 3], 2); // true * includes([1, 2, 3], 4); // false * * includes({ name: "John", age: 23 }, { name: "John", age: 23 }); // true * includes({ name: "John", age: 23 }, { name: "John", age: 24 }); // false * * includes([1, 2, 3], [1, 2, 3]); // true * includes([1, 2, 3], [1, 2, 3, [4]]); // false * includes([1, 2, 3, [4]], [1, 2, 3, [4]]); // true * */ export declare function includes<T>(keywords: T, val: unknown): val is T; export declare function includes<T>(keywords: T[], val: unknown): val is T;