UNPKG

@busymango/fetch-driver

Version:

fetch with middlewares for the browser

108 lines (107 loc) 4.76 kB
/** * @author mango * @description fetch type define */ import type { DriveMiddleware } from "./model"; /** Type narrow func define */ export interface NarrowFunc<T> { (source: unknown): boolean; (source: unknown): source is T; } /** * Removes falsy values (false, null, 0, "", undefined, and NaN) from an array. * @param source - The input array to compact. * @returns An array with falsy values removed. */ export declare function compact<T = unknown>(source: (T | undefined | null | false | '' | 0)[]): T[]; /** * Narrow source type to `String` && Check is not empty string. */ export declare function isNonEmptyString(source: unknown): source is Exclude<string, "">; export declare const isEmptyValue: (data: unknown) => data is "" | undefined | null | [] | Record<string, never>; export declare const isNonEmptyArray: (source: unknown) => source is unknown[]; /** * Narrow source type to `Array` && Check is not empty. */ export declare function isStringArray(source: unknown): source is string[]; /** * Narrow source type to `Number` &amp;&amp; Check is not `Infinity`, `-Infinity`, `NaN`. */ export declare function isFinite(source: unknown): source is number; /** * Narrow source key type. * @example ```typescript * const obj: unknown; * isValidKey('key', obj, isString); * // obj is Recrode<'key', string>; * ``` */ export declare function isValidKey<K extends string, T>(key: K, source: object, is: NarrowFunc<T>): source is Record<K, T>; /** * Checks if the provided source is an instance of FormData. * * @param source The value to check. * @returns Returns true if source is an instance of FormData, false otherwise. */ export declare function isFormData(source: unknown): source is FormData; /** * Checks if the provided source is an instance of ReadableStream. * * @param source The value to check. * @returns Returns true if source is an instance of ReadableStream, false otherwise. */ export declare function isReadableStream(source: unknown): source is ReadableStream; /** * Checks if the given source is an instance of ArrayBuffer. * If is ArrayBuffer, narrow to type ArrayBuffer. * @param {unknown} source - The value to be checked. * @returns {boolean} Returns true if the source is an instance of ArrayBuffer, false otherwise. */ export declare function isArrayBuffer(source: unknown): source is ArrayBuffer; /** * Checks if the given source is an instance of Uint8Array. * If is Uint8Array, narrow to type Uint8Array. * @param {unknown} source - The value to be checked. * @returns {boolean} Returns true if the source is an instance of Uint8Array, false otherwise. */ export declare function isUint8Array(source: unknown): source is Uint8Array; /** * Narrow source type to `isArrayBufferLike`. */ export declare function isArrayBufferLike(source: unknown): source is ArrayBufferLike; /** * Narrow source type to `ArrayBufferView`. */ export declare function isArrayBufferView(source: unknown): source is ArrayBufferView; /** * Narrow source type to `BufferSource`. */ export declare function isBufferSource(source: unknown): source is BufferSource; /** * Checks if the given source is an instance of URLSearchParams. * If is URLSearchParams, narrow to type URLSearchParams. * @param {unknown} source - The value to be checked. * @returns {boolean} Returns true if the source is an instance of URLSearchParams, false otherwise. */ export declare function isURLSearchParams(source: unknown): source is URLSearchParams; /** * Checks if the given source is an instance of Blob. * If is Promise, narrow to type Promise. * @param {unknown} source - The value to be checked. * @returns {boolean} Returns true if the source is an instance of Blob, false otherwise. */ export declare function isBlob(source: unknown): source is Blob; export declare function isNonRawBodyInit(source: unknown): source is Exclude<BodyInit, string | URLSearchParams>; export declare function isRawTextBody(type?: string): boolean; export declare function downloader(href: string, download: string): void; export declare function src2name(src: string): string; export declare function createMiddleware<T = unknown>(middleware: DriveMiddleware<T>): DriveMiddleware<T>; /** * Constructs and returns a URLSearchParams object based on the provided initialization data. * Supports initializing with various types: URLSearchParams, string, string arrays, and plain objects. * Returns undefined if the initialization data does not match any supported type. * * @param init The initialization data for URLSearchParams. * @returns A URLSearchParams object constructed from the provided data, or undefined if invalid. */ export declare function iSearchParams(init: unknown): URLSearchParams | undefined;