From 03d4edbb085adc805fb3081649816e24a1833ea9 Mon Sep 17 00:00:00 2001 From: Marcello Date: Thu, 9 Jul 2026 15:01:57 -0400 Subject: [PATCH 1/2] Implement includesOnly function for collection comparison Added a function to check if a collection contains exactly the specified values. --- src/core.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/core.ts b/src/core.ts index 7b773ca..bbde9f7 100644 --- a/src/core.ts +++ b/src/core.ts @@ -755,3 +755,42 @@ export function move(list: T[], from: number, to: number): T[] { copy.splice(to, 0, item); return copy; } + +/** + * Checks whether a collection contains **exactly** the specified values. + * + * The order of values does not matter, but the set of values must match + * exactly. Duplicate values are ignored, since both the collection and the + * expected values are compared as sets. + * + * @template T The type of values in the collection. + * @param collection The collection to compare. + * @param values The expected values. + * @returns `true` if the collection contains exactly the specified values; + * otherwise, `false`. + * + * @example + * includesOnly([1], 1); // true + * includesOnly([1], 1, 2); // false + * includesOnly([2, 1], 1, 2); // true + * includesOnly(new Set(["a", "b"]), "b", "a"); // true + */ +export function includesOnly( + collection: Iterable, + ...values: T[] +): boolean { + const actual = new Set(collection); + const expected = new Set(values); + + if (actual.size !== expected.size) { + return false; + } + + for (const value of actual) { + if (!expected.has(value)) { + return false; + } + } + + return true; +} From 4e8b3651b0062312442aa106d78bb8b284e9d132 Mon Sep 17 00:00:00 2001 From: Marcello Date: Thu, 9 Jul 2026 15:02:14 -0400 Subject: [PATCH 2/2] Bump version from 2.1.0 to 2.2.0 --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 10d2603..a63001e 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@bytebury/toolkit", - "version": "2.1.0", + "version": "2.2.0", "exports": { ".": "./mod.ts", "./core": "./src/core.ts",