thena
Version:
A simple, lightweight, and fast utility library for Node and the browser.
74 lines (67 loc) • 2.02 kB
TypeScript
/**
* loop
* @description loop `n` times
* @param n number of iterations
* @param fn callback function to be run on each iteration
* @returns promise that resolves when loop is complete
*/
export function loop(n: number, fn: (i: number) => void): Promise<void>;
/**
* each
* @description loop through an array
* @param arr array-like object to loop through
* @param fn callback function to be run on each iteration
* @returns promise that resolves when loop is complete
*/
export function each(arr: any[], fn: (item: any, i: number) => void): Promise<void>;
/**
* num
* @description convert a value to a number
* @param n number to be converted
* @returns converted number
* @throws error if value cannot be converted to a number
*/
export function num(n: number | string | object | any[]): number;
/**
* fetch
* @description fetch data from a URL with a reconsumable body
* @param url URL to fetch data from
* @param options fetch options
* @returns response object
* @throws error if `fetch` is not supported in the current environment
* @example
* const response = await fetch('https://example.com/someData');
*
* const body = response.body.json();
* const rawBody = response.body.text();
* const htmlBody = response.body.html();
*/
export function fetch(
url: string,
options: {
method?: string;
headers?: any;
body?: any;
}
): Promise<any>;
/**
* h
* @description create an HTML element
* @param tag HTML tag name
* @param props HTML element properties
* @param children HTML element children
* @returns HTMLElement
* @example
* const div = h('div', { id: 'myDiv' }, 'Hello World');
*
* document.body.appendChild(div); // <div id="myDiv">Hello World</div>
*/
export function h(tag: keyof HTMLElementTagNameMap, props: Record<string, any>, ...children: any[]): HTMLElement;
declare const _default: {
loop: typeof loop;
each: typeof each;
num: typeof num;
fetch: typeof fetch;
h: typeof h;
};
export default _default;