UNPKG

@cc-heart/utils

Version:

🔧 javascript common tools collection

46 lines (45 loc) • 1.99 kB
import type { QueryStringToObject } from '../typings/url'; export declare function parseKey(obj: Record<PropertyKey, any>, key: string, value: any): void; /** * Converts a query string to an object. * * @example `queryStringToObject('foo=1&bar=2&baz=3')` * @example `queryStringToObject('foo=&bar=2&baz=3')` * @example `queryStringToObject('foo[0]=1&foo[1]=2&baz=3')` * @template T - The type of the URL string. * @template U - The type of the object to return. * @param {T} url - The URL string to convert. * @returns {U} The object representation of the query string in `url`. */ export declare function queryStringToObject<T extends string, U extends Record<PropertyKey, any> = QueryStringToObject<T>>(url: T): U; /** * Converts an object to a query string. * * @param data - The object to convert. * @returns The query string representation of `data`. */ export declare function objectToQueryString<T extends Record<PropertyKey, any>>(data: T): string; /** * convert params routes to regular expressions * * @param path a params paths * @returns null or An array contains the RegExp that matches the params and the path for each params parameter */ export declare function convertParamsRouterToRegExp(path: string): (RegExp | string[])[] | null; /** * Returns the last portion of a path, similar to the Unix basename command. * Trims the query string if it exists. * Optionally, removes a suffix from the result. * * @param path - The path to get the basename from. * @param [suffix] - An optional suffix to remove from the basename. * @returns The basename of the path. */ export declare function basename(path: string, suffix?: string): string; /** * Convert a multi-dimensional array to a query string. * @param array The multi-dimensional array to convert. * @param field The field name to use in the query string. * @returns The generated query string. */ export declare function arrayToQueryString(array: Array<unknown>, field: string): string;