UNPKG

xuxi

Version:

Dynamically utility for combining different types of values ​​into a single value.

45 lines (44 loc) 2.05 kB
/** Represents a mapping of string or symbol keys to any value. */ export type keyMap = Record<string | symbol, any>; /** Defines the accepted value types for the utility functions. */ export type cnxValues = keyMap | keyMap[] | cnxValues[] | string | number | boolean | null | undefined | BigInt | Date | Map<any, any> | Set<any> | ((v?: any) => cnxValues); /** * Converts input values into a space-separated string. * @param args - Input values. * @returns The formatted string. */ declare function cnx(...args: cnxValues[]): string; type StringValues = cnxValues; interface ExtendsOpt { separator?: string; } /** * Represents a string utility object returned by the `string()` function. * * Provides multiple methods for converting the original values * into different string formats. */ interface StringFunction { /** Converts input values into a space-separated string. Similar to how class names are joined in CSS-in-JS libraries. */ toString(): string; /** Recursively serializes objects, arrays, and nested structures into a flattened `key=value` pair string. */ recursive(opts?: ExtendsOpt): string; /** Detects specific object types like Date, Map, and Set, and converts them into human-readable strings. */ instanceof(opts?: ExtendsOpt): string; /** Implicitly converts the object to a string when used in a primitive context (e.g., template literals). */ [Symbol.toPrimitive](): string; } /** * Creates a string utility object from the given input values. * * Accepts a list of values (strings, objects, arrays, or primitives) and provides * multiple methods to serialize or convert them into string representations * based on different strategies. * * This is especially useful for conditionally building class names, query strings, * or logging structured data. * @param args - One or more values to be stringified or serialized. * @returns An object with string conversion utilities. */ declare function string(...args: StringValues[]): StringFunction; export { cnx, string };