// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Creates a new object by including the specified keys from the provided
 * object.
 *
 * @template T The type of the object.
 * @template K The type of the keys.
 *
 * @param obj The object to pick keys from.
 * @param keys The keys to include in the new object.
 *
 * @returns A new object with the specified keys from the provided object.
 *
 * @example Basic usage
 * ```ts
 * import { pick } from "@std/collections/pick";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const obj = { a: 5, b: 6, c: 7, d: 8 };
 * const picked = pick(obj, ["a", "c"]);
 *
 * assertEquals(picked, { a: 5, c: 7 });
 * ```
 */
export function pick<T extends object, K extends keyof T>(
  obj: Readonly<T>,
  keys: readonly K[],
): Pick<T, K> {
  return Object.fromEntries(keys.map((k) => [k, obj[k]])) as Pick<T, K>;
}

// denoCacheMetadata={"headers":{"access-control-allow-origin":"*","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","etag":"\"862d1d3fe91b3d9bcd8f9d2f1276b4de\"","x-robots-tag":"noindex","content-type":"text/typescript","cache-control":"public, max-age=31536000, immutable","x-jsr-backend":"modules","content-length":"941","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","alt-svc":"h3=\":443\"; ma=86400","set-cookie":"__cf_bm=CCYbcjkyl62m0JahO4_1GJa5Ck1Q_mn_OeBhj4JgO34-1785241874.9632263-1.0.1.1-_RcyEMFzGXvc5FyOTtzXz_YelYZYO5EA0BUoYmbR10r92eqTaUzWEeUA8azgkPUdGcC9Zqwsspoa9M7M8OrCL1Cx2XvR_u0b54aynQD7rTQckNbO2DIBO79Cm.qxjuN4; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","server":"cloudflare","access-control-expose-headers":"*","vary":"Origin","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=RPQH0iXGQrarr%2FcL%2BfR8G9L3sG0TOpnTuS8KylstqoenNnj2zHeTBLSs7WJXyROfiMcqnhqQax0%2FFAfwuzPn2xsHATJcQNCHvZW2n%2BG6wxFBaQo7rPzJbRY%3D\"}]}","cross-origin-resource-policy":"cross-origin","cf-ray":"a223e6564f2e7db6-LAX","x-content-type-options":"nosniff"},"url":"https://jsr.io/@std/collections/0.224.2/pick.ts","time":1785241875}