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