UNPKG

es-fetcher

Version:

Enhance your frontend application's API implementation and calls with es-fetcher. Simplify and accelerate the process like never before.

41 lines (40 loc) 1.62 kB
/** * Omit properties from an object. * * @param {object} item - The input object. * @param {string[]} keys - An array of keys to omit from the object. * @returns {{ [key: string]: any }} - A new object with the specified keys omitted. */ declare const omitProperties: <T extends Record<string, any>>(item: T, keys: (keyof T)[]) => Partial<T>; /** * Choose properties from an object. * * @param {object} item - The input object. * @param {string[]} keys - An array of keys to choose from the object. * @returns {{ [key: string]: any }} - A new object with only the specified keys. */ declare const chooseProperties: <T extends Record<string, any>>(item: T, keys: (keyof T)[]) => Partial<T>; /** * Check if a URL is absolute. * * @param {string} url - The URL to check. * @returns {boolean} - True if the URL is absolute, false otherwise. */ declare const isAbsoluteUrl: (url: string) => boolean; /** * Construct an absolute URL from a relative URL and an optional base. * * @param {string} url - The relative URL. * @param {string} [base] - The optional base URL. * @returns {string} - The absolute URL. */ declare const constructAbsoluteUrl: (url: string, base?: string) => string; /** * Try parsing the response body based on the content type. * * @param {Response} res - The response object. * @returns {Promise<any>} - A promise that resolves to the parsed response body. * @throws {Error} - Throws an error if parsing fails. */ declare const tryParsingBody: (res: Response) => Promise<any>; export { omitProperties, chooseProperties, isAbsoluteUrl, constructAbsoluteUrl, tryParsingBody };