@monstermann/fn
Version:
A utility library for TypeScript.
51 lines (49 loc) • 825 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/map/hasAny.ts
/**
* `hasAny(map, keys)`
*
* Checks if `map` contains any of the specified `keys`. This function supports iterables.
*
* ```ts
* hasAny(
* new Map([
* ["a", 1],
* ["b", 2],
* ]),
* ["a", "c"],
* ); // true
*
* hasAny(
* new Map([
* ["a", 1],
* ["b", 2],
* ]),
* ["c", "d"],
* ); // false
* ```
*
* ```ts
* pipe(
* new Map([
* ["a", 1],
* ["b", 2],
* ]),
* hasAny(["a", "c"]),
* ); // true
*
* pipe(
* new Map([
* ["a", 1],
* ["b", 2],
* ]),
* hasAny(["c", "d"]),
* ); // false
* ```
*/
const hasAny = dfdlT((target, keys) => {
for (const key of keys) if (target.has(key)) return true;
return false;
}, 2);
//#endregion
export { hasAny };