UNPKG

@visulima/string

Version:

Functions for manipulating strings.

89 lines (88 loc) 2.9 kB
declare const outdent: Outdent; /** * Represents the outdent function, which can be called as a template tag * or as a function to create a new instance with specific options. * It also includes a `.string()` method for processing regular strings. */ interface Outdent { /** * Remove indentation from a template literal. * Tag function for template literals. * @param strings The static string parts of the template literal. * @param values The interpolated values. * @returns The processed string with indentation removed. */ (strings: TemplateStringsArray, ...values: any[]): string; /** * Create and return a new Outdent instance with the given options. * @param options Configuration options for the new instance. * @returns A new Outdent function instance. */ (options: Options): Outdent; /** * Remove indentation from a string * @param string_ The raw string to process. * @returns The processed string with indentation removed. */ string: (string_: string) => string; } /** * Configuration options for the outdent function. */ interface Options { /** * Whether to cache processed template literals for better performance when * using the same template multiple times. * * Enabling caching can significantly improve performance when the same template * is used repeatedly, such as in loops or frequently called functions. * @example * // Create an outdent function with caching enabled (default) * const dedent = outdent(); * * // Create an outdent function with caching disabled * const noCacheDedent = outdent({ cache: false }); * @default true */ cache?: boolean; /** * Custom cache store to use instead of the default WeakMap. * Must be a WeakMap instance. * * This allows you to provide your own WeakMap instance for caching, * which can be useful for advanced use cases or for sharing cache * between multiple outdent instances. * @example * // Create a custom cache * const customCache = new WeakMap(); * * // Create an outdent function with a custom cache * const customCacheDedent = outdent({ cacheStore: customCache }); */ cacheStore?: WeakMap<TemplateStringsArray, string[]>; /** * Normalize all newlines in the template literal to this value. * * If `null`, newlines are left untouched. * * Newlines that get normalized are '\r\n', '\r', and '\n'. * * Newlines within interpolated values are *never* normalized. * * Although intended for normalizing to '\n' or '\r\n', * you can also set to any string; for example ' '. * @default null */ newline?: string | null; /** * Whether to trim the leading newline in the template literal. * @default true */ trimLeadingNewline?: boolean; /** * Whether to trim the trailing newline in the template literal. * @default true */ trimTrailingNewline?: boolean; } export { Options, Outdent, outdent };