next-era
Version:
Welcome to **Next Era**! A comprehensive library designed to supercharge your **Next.js** applications with powerful utilities and significant performance optimizations. Build faster, more efficient, and feature-rich Next.js projects with ease.
80 lines (79 loc) • 3.98 kB
TypeScript
/**
* Convert object keys from snakeCase to camelCase.
* @param obj - The object to process.
* @returns A new object with camelCase keys.
*/
export declare function toCamelKey(obj: string | number | null): string | number | null;
export declare function toCamelKey<T>(obj: Record<string, string | number | null>): T;
export declare function toCamelKey<T>(obj: (string | number | Record<string, string | number | null>)[]): (string | number | T)[];
export declare function toCamelKey<T>(obj: (string | number | Record<string, string | number | null>)[]): (string | number | T)[];
export declare function toCamelKey<T>(obj: Record<string, string | number | null> | (string | number | Record<string, string | number | null>)[]): T | (string | number | T)[];
export declare function toCamelKey<T>(obj: string | Record<string, string | number | null> | (string | number | Record<string, string | number | null>)[]): string | T | (string | number | T)[];
export declare function toCamelKey<T>(obj: string | number | Record<string, string | number | null> | (string | number | Record<string, string | number | null>)[]): string | number | T | (string | number | T)[];
export declare function toCamelKey<T>(obj: string | number | Record<string, string | number | null> | (string | number | Record<string, string | number | null>)[]): string | number | T | (string | number | T)[];
/**
* Insert a separator between each element of an array such as ReactNode.
* @param array The array to process.
* @param separator The separator to insert between each element.
* @returns A new array with the separator inserted between each element.
*/
export declare function between(array: unknown[], separator: unknown | ((index: number) => unknown)): any[];
/**
* Left merge objects deeply without mutating original object.
* @param params The objects to merge.
* @returns A new object merged deeply.
*/
export declare function defaultsDeep<T>(...params: T[]): T;
/**
* Flatten object deeply. Useful for routing to another path with searchParams like: `https://example.com/route?ancestor.parent.child=1&ancestor.parent.child=2`
* Example:
* ```ts
* flattenDeep({ancestor: {parent: {child: 1, child: 2}}}) // {'ancestor.parent.child': 1, 'ancestor.parent.child': 2}
* ```
* @param object The object to flatten.
*/
export declare function flattenDeep(object?: Record<string, unknown>): Record<string, unknown>;
export declare function flattenDeep(object?: unknown[]): unknown[];
/**
* Unflatten object deeply. Useful for extracting searchParams after routing by flattenDeep function.
* Example:
* ```ts
* unflattenDeep<ToType>(
* await props.searchParams,
* ); // {ancestor: {parent: {child: 1, child: 2}}}
* ```
* @param object The object to unflatten.
* @returns A new object unflattened deeply.
*/
export declare function unflattenDeep<T = Record<string, string | number>>(object?: Record<string, string | number>): Partial<T>;
export declare function clsx(...args: unknown[]): string;
export declare function interpolate(regex: RegExp, flag?: string): {
template: (content: string) => {
compiled: (value: Record<string, unknown>) => string;
};
};
/**
* Normalize path by replacing backslashes with slashes.
* @param path The path to normalize.
* @returns A new path normalized.
*/
export declare function normalizePath(path: string): string;
/**
* Create a wildcard pattern matcher. Example: `wildcardize("*.js").test("index.js")`
* @param pattern The wildcard pattern to match.
* @returns A wildcard pattern matcher.
*/
export declare function wildcardize(pattern: string): {
test: (text: string) => boolean;
};
declare const utils: {
between: typeof between;
defaultsDeep: typeof defaultsDeep;
flattenDeep: typeof flattenDeep;
unflattenDeep: typeof unflattenDeep;
clsx: typeof clsx;
interpolate: typeof interpolate;
normalizePath: typeof normalizePath;
wildcardize: typeof wildcardize;
};
export default utils;