UNPKG

codetrix

Version:

A lightweight lodash-style utility library

67 lines (66 loc) 2.26 kB
/** * Converts an object into a query string. * * @param {Record<string, any>} obj - The object to convert. * @returns {string} Query string (e.g., a=1&b=2). * * @example * toQueryString({ a: 1, b: 2 }); // "a=1&b=2" */ export declare function toQueryString(obj: Record<string, any>): string; /** * Parses a query string into an object. * * @param {string} str - The query string (e.g., "a=1&b=2"). * @returns {Record<string, string>} Parsed object. * * @example * parseQueryString("a=1&b=2"); // { a: "1", b: "2" } */ export declare function parseQueryString(str: string): Record<string, string>; /** * Converts CSV string to JSON array. * * @param {string} csv - The CSV data (first row is header). * @param {string} [delimiter=','] - Delimiter used in CSV. * @returns {Record<string, string>[]} JSON array. * * @example * csvToJson("name,age\nAlice,25\nBob,30"); * // [{ name: "Alice", age: "25" }, { name: "Bob", age: "30" }] */ export declare function csvToJson(csv: string, delimiter?: string): Record<string, string>[]; /** * Converts JSON array into CSV string. * * @param {Record<string, any>[]} json - Array of objects. * @param {string} [delimiter=','] - Delimiter used in CSV. * @returns {string} CSV string. * * @example * jsonToCsv([{ name: "Alice", age: 25 }, { name: "Bob", age: 30 }]); * // "name,age\nAlice,25\nBob,30" */ export declare function jsonToCsv(json: Record<string, any>[], delimiter?: string): string; /** * Copies a given string to the user's clipboard. * * @param {string} str - The string content to copy into the clipboard. * @returns {Promise<void>} - Resolves when the text has been successfully copied. * * @example * await copyToClipboard("Hello World"); */ export declare function copyToClipboard(str: string): Promise<void>; /** * Triggers a download of a file in the browser. * * @param {Blob | string} data - The file data to download (Blob object or a string). * @param {string} filename - The name for the downloaded file (e.g., "file.txt"). * @returns {void} * * @example * const blob = new Blob(["Hello World"], { type: "text/plain" }); * downloadFile(blob, "hello.txt"); */ export declare function downloadFile(data: Blob | string, filename: string): void;