import type * as types from './types.js' export { default as delay } from 'delay' export { default as assert } from 'tiny-invariant' /** * From `inputObj`, create a new object that does not include `keys`. * * @example * ```js * omit({ a: 1, b: 2, c: 3 }, 'a', 'c') // { b: 2 } * ``` */ export const omit = < T extends Record | object, K extends keyof T = keyof T >( inputObj: T, ...keys: K[] ): Omit => { const keysSet = new Set(keys) return Object.fromEntries( Object.entries(inputObj).filter(([k]) => !keysSet.has(k as any)) ) as any } /** * From `inputObj`, create a new object that only includes `keys`. * * @example * ```js * pick({ a: 1, b: 2, c: 3 }, 'a', 'c') // { a: 1, c: 3 } * ``` */ export const pick = < T extends Record | object, K extends keyof T = keyof T >( inputObj: T, ...keys: K[] ): Pick => { const keysSet = new Set(keys) return Object.fromEntries( Object.entries(inputObj).filter(([k]) => keysSet.has(k as any)) ) as any } export function pruneUndefined>( obj: T ): NonNullable<{ [K in keyof T]: Exclude }> { return Object.fromEntries( Object.entries(obj).filter(([, value]) => value !== undefined) ) as NonNullable } export function getEnv(name: string): string | undefined { try { return typeof process !== 'undefined' ? // eslint-disable-next-line no-process-env process.env?.[name] : undefined } catch { return undefined } } /** * Function that does nothing. */ export const noop = () => undefined /** * Throttles HTTP requests made by a ky instance. * * Very useful for enforcing rate limits. */ export function throttleKy( ky: types.KyInstance, throttleFn: ( function_: (...args_: Arguments) => ReturnValue ) => types.ThrottledFunction<(...args_: Arguments) => ReturnValue> ) { return ky.extend({ hooks: { beforeRequest: [throttleFn(noop)] } }) }